google / android-fhir

The Android FHIR SDK is a set of Kotlin libraries for building offline-capable, mobile-first healthcare applications using the HL7® FHIR® standard on Android.
https://google.github.io/android-fhir/
Apache License 2.0
465 stars 246 forks source link

Repeated Group: Anomalous behaviour of enableWhen expressions in a repeated group #2590

Open allan-on opened 1 week ago

allan-on commented 1 week ago

Describe the bug The enableWhen expression condition cascades to other group items below or above the trigger group item.

Component SDC library

To Reproduce Steps to reproduce the behaviour:

  1. Define a repeated group with several items e.g. choice and date fields.
  2. Add an enableWhen expression for showing/hiding a field based on a choice selection (condition).
  3. When the app runs, add items in the UI and click the option(s) tied to the enableWhen expression.
  4. See that multiple fields are affected by the choice selection.

Expected behaviour For an enableWhen expression condition that affects a single field should not cascade to other fields.

Screenshots

https://github.com/google/android-fhir/assets/16164649/cef11fa5-2769-4207-b875-53e62e129fe8

Smartphone (please complete the following information):

Additional context In the video shared above, there are two fields, a choice option, and a date field. The date field only shows if the choice is option A. Selecting option A shows all date fields and selecting any other option hides it.

Would you like to work on the issue? Please state if this issue should be assigned to you or who you think could help to solve this issue.

jingtang10 commented 1 week ago

thanks @allan-on can you share your questionnaire?

allan-on commented 5 days ago

thanks @allan-on can you share your questionnaire?

Hi @jingtang10 This is the Questionnaire I used in the demo above:

{
  "resourceType": "Questionnaire",
  "item": [
    {
      "linkId": "1",
      "type": "group",
      "text": "Repeated Group",
      "repeats": true,
      "item": [
        {
          "linkId": "1-2",
          "type": "choice",
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/questionnaire-item-control",
                    "code": "drop-down",
                    "display": "Drop down"
                  }
                ],
                "text": "Drop down"
              }
            }
          ],
          "text": "Sample dropdown question",
          "answerOption": [
            {
              "valueCoding": {
                "code": "answer-a",
                "display": "A"
              }
            },
            {
              "valueCoding": {
                "code": "answer-b",
                "display": "B"
              }
            },
            {
              "valueCoding": {
                "code": "answer-c",
                "display": "C"
              }
            },
            {
              "valueCoding": {
                "code": "answer-other",
                "display": "Other"
              }
            }
          ],
          "item": [
            {
              "linkId": "1-3-1",
              "text": "Dropdown question helper text",
              "type": "display",
              "extension": [
                {
                  "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
                  "valueCodeableConcept": {
                    "coding": [
                      {
                        "system": "http://hl7.org/fhir/questionnaire-item-control",
                        "code": "flyover",
                        "display": "Fly-over"
                      }
                    ],
                    "text": "Flyover"
                  }
                }
              ]
            }
          ]
        },
        {
          "linkId": "1-1",
          "text": "Sample date question",
          "type": "date",
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
              "valueString": "yyyy-mm-dd"
            },
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
              "valueExpression": {
                "language": "text/fhirpath",
                "expression": "%resource.descendants().where(linkId='1-2').answer.value.code = 'answer-a'"
              }
            }
          ]
        }
      ]
    }
  ]
}
santosh-pingle commented 1 day ago

thanks @allan-on can you share your questionnaire?

Hi @jingtang10 This is the Questionnaire I used in the demo above:

{
  "resourceType": "Questionnaire",
  "item": [
    {
      "linkId": "1",
      "type": "group",
      "text": "Repeated Group",
      "repeats": true,
      "item": [
        {
          "linkId": "1-1",
          "text": "Sample date question",
          "type": "date",
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
              "valueString": "yyyy-mm-dd"
            }
          ]
        },
        {
          "linkId": "1-2",
          "type": "choice",
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/questionnaire-item-control",
                    "code": "drop-down",
                    "display": "Drop down"
                  }
                ],
                "text": "Drop down"
              }
            }
          ],
          "text": "Sample dropdown question",
          "answerOption": [
            {
              "valueCoding": {
                "code": "answer-a",
                "display": "A"
              }
            },
            {
              "valueCoding": {
                "code": "answer-b",
                "display": "B"
              }
            },
            {
              "valueCoding": {
                "code": "answer-c",
                "display": "C"
              }
            },
            {
              "valueCoding": {
                "code": "answer-other",
                "display": "Other"
              }
            }
          ],
          "item": [
            {
              "linkId": "1-3-1",
              "text": "Dropdown question helper text",
              "type": "display",
              "extension": [
                {
                  "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
                  "valueCodeableConcept": {
                    "coding": [
                      {
                        "system": "http://hl7.org/fhir/questionnaire-item-control",
                        "code": "flyover",
                        "display": "Fly-over"
                      }
                    ],
                    "text": "Flyover"
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

@allan-on Can you please check whether posted questionnaire has the enable-when expression?

allan-on commented 1 day ago

Hi @santosh-pingle. I'm sorry about that. I've updated the sample I shared earlier.

jingtang10 commented 8 hours ago

Hey @allan-on i'm not sure i agree with the use of %resource in the enable when expression I think you end up losing the context of your answer inside the repeated group.

I think the best way to handle this is actually use enable when element defined in the questionnaire base spec.

Take a look at the comemnts section of this element: https://build.fhir.org/questionnaire-definitions.html#Questionnaire.item.enableWhen.question it very clearly defines the order or traversal so I think the behaviour is more predictable.