Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use initial expressions to select the initial value from a dropdown list populated using answer expressions #1830

Closed
KhumboLihonga opened this issue Jan 26, 2023 · 13 comments · Fixed by #2065
Assignees
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue

Comments

@KhumboLihonga
Copy link

Is your feature request related to a problem? Please describe.
When I populate a dropdown using the answer expression extension as per this example, I cannot set the initial value using the initial expression extension. This is due to the item being of a reference type and the type I'm trying to populate is a string type.

Describe the solution you'd like
I should be able to use initial expressions to set the initial value

Describe alternatives you've considered
Instead of using answer expressions, I can populate the dropdown with answer options instead but this is challenging where there are a large number of options.

Additional context
Here is the questionnaire I tried and this is the logcat. If there is another way to do this, please point me in the right direction.

@omarismail94
Copy link
Contributor

omarismail94 commented Jan 27, 2023

@KhumboLihonga I can replicate your issue using the questionnaire I defined below, which works with resources fetched from the public https://hapi.fhir.org/baseR4/ site.

Will continue to debug

{
  "resourceType": "Questionnaire",
  "id": "test-questionnaire",
  "language": "en",
  "title": "Test Questionnaire",
  "status": "active",
  "publisher": "mcore",
  "contact": [
    {
      "name": "http:https://www.d-tree.org"
    }
  ],
  "item": [
    {
      "extension": [
        {
          "url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http:https://hl7.org/fhir/questionnaire-item-control",
                "code": "drop-down",
                "display": "Drop down"
              }
            ],
            "text": "Drop down"
          }
        },
        {
          "url": "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
          "valueExpression": {
            "language": "text/fhirpath",
            "expression": "Patient.id"
          }
        },
        {
          "url": "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression",
          "valueExpression": {
            "expression": "Patient?address-city=NAIROBI",
            "language": "application/x-fhir-query"
          }
        },
        {
          "url": "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn",
          "extension": [
            {
              "url": "path",
              "valueString": "display"
            },
            {
              "url": "label",
              "valueString": "name"
            },
            {
              "url": "forDisplay",
              "valueBoolean": true
            }
          ]
        }
      ],
      "linkId": "district",
      "text": "District",
      "type": "reference",
      "required": true
    }
  ]
}

@PallaviGanorkar PallaviGanorkar added P2 Medium priority issue effort:medium Medium effort - 3 to 5 days P1 High priority issue and removed P2 Medium priority issue labels Jan 30, 2023
@omarismail94
Copy link
Contributor

@KhumboLihonga I created PR #1831 to propose fixing. Please check out and lmk if you have any thoughts

@omarismail94 omarismail94 self-assigned this Jan 30, 2023
@KhumboLihonga
Copy link
Author

Hey @omarismail94, my colleague tested your PR and was unable to verify that the issue was fixed. This is the comment he left. Is there any update on this?

@omarismail94
Copy link
Contributor

Hey @KhumboLihonga and @sevenreup , please see the attached video of the fix working:

Where is the app crashing for you, and what are the logs that you are getting?

I also had to implement the DataCaptureConfig.Provider interface in the FhirApplication class to provide an xFhirQueryResolver:

https://github.com/google/android-fhir/pull/1831/files#diff-dc8902f9b4a0cb8dab12c5cdb57cfefbcf29b4482c5d2e28e60c6e51ac932389

device-2023-02-16-111350.mp4

@sevenreup
Copy link

@omarismail94 the initial expression is working when I use the example questionnaire you gave here, it only shows the resource reference as a label.
But when I try to change the label to something else for example the Patients name, it does not work.
The questionnaire I am using is the one below.

{
  "resourceType": "Questionnaire",
  "id": "test-questionnaire",
  "language": "en",
  "title": "Test Questionnaire",
  "status": "active",
  "publisher": "mcore",
  "contact": [
    {
      "name": "http:https://www.d-tree.org"
    }
  ],
  "item": [
    {
      "extension": [
        {
          "url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http:https://hl7.org/fhir/questionnaire-item-control",
                "code": "drop-down",
                "display": "Drop down"
              }
            ],
            "text": "Drop down"
          }
        },
        {
          "url": "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
          "valueExpression": {
            "language": "text/fhirpath",
            "expression": "Patient.id"
          }
        },
        {
          "url": "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression",
          "valueExpression": {
            "expression": "Patient?address-city=NAIROBI",
            "language": "application/x-fhir-query"
          }
        },
        {
          "url": "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn",
          "extension": [
            {
              "url": "path",
              "valueString": "name.given"
            },
            {
              "url": "label",
              "valueString": "text"
            },
            {
              "url": "forDisplay",
              "valueBoolean": true
            }
          ]
        }
      ],
      "linkId": "district",
      "text": "District",
      "type": "reference",
      "required": true
    }
  ]
}

@omarismail94
Copy link
Contributor

omarismail94 commented Feb 17, 2023

@sevenreup hmm, is name.given a valid fhir path? can you try name.first().given? That should give you a list of all given names in the choices. We add first() because the name field is repeated

@sevenreup
Copy link

It is a valid path. Even when I use first() I am still getting the same problem

@omarismail94
Copy link
Contributor

When I do name.first().given, this is what I get:
image

Is what you want that the Patient Id appears initially (not the given name), and then when the dropdown is selected, the given names are shown?

@sevenreup
Copy link

We want what we have defined as the label to appear initially and in the selection ( in this case, the patient's name). Because what is happening now is the initial selection is not working when you change the path.

@omarismail94
Copy link
Contributor

If I understand correctly, you want what is defined in the label field to appear in the selection, just like in the example here:
https://build.fhir.org/ig/HL7/sdc/examples.html#using-choicecolumn

I think that is a different issue than what this Issue was opened for. Would you agree? My understanding of this opened issue is to set the initial value using the initial expression extension

@KhumboLihonga
Copy link
Author

@omarismail94 I feel there are two issues here:

  1. If the path attribute is changed to name.first().given, the dropdown options are indeed updated to display as intended BUT the initial expression does not set the initial value (regardless of how it is meant to be presented)
  2. We should be able to define how the selected item should be presented using the label attribute

I believe point 1 is still a part of this PR while point 2 would be a separate PR. What do you think?

@KhumboLihonga
Copy link
Author

@omarismail94 Just following up on this issue. What do you think about my comment above?

@KhumboLihonga
Copy link
Author

@omarismail94 following up on this once again. Let me know your thoughts on the comment above so we can decide how to best proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue
Projects
Status: Complete
4 participants