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

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

Closed
allan-on opened this issue Jun 25, 2024 · 7 comments · Fixed by #2597 or #2600
Closed

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

allan-on opened this issue Jun 25, 2024 · 7 comments · Fixed by #2597 or #2600
Assignees
Labels
P1 High priority issue type:bug Something isn't working

Comments

@allan-on
Copy link
Contributor

allan-on commented Jun 25, 2024

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

repeated_group_enable_when_anomaly.mp4

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
Copy link
Collaborator

thanks @allan-on can you share your questionnaire?

@jingtang10 jingtang10 self-assigned this Jun 25, 2024
@allan-on
Copy link
Contributor Author

allan-on commented Jun 27, 2024

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 santosh-pingle added type:bug Something isn't working P1 High priority issue labels Jul 1, 2024
@santosh-pingle
Copy link
Collaborator

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
Copy link
Contributor Author

allan-on commented Jul 1, 2024

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

@jingtang10
Copy link
Collaborator

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.

@jingtang10
Copy link
Collaborator

Hey @allan-on,

I posted a question on fhir chat https://chat.fhir.org/#narrow/stream/179266-fhirpath/topic/parent.28.29.20or.20siblings.28.29.3F and I've yet to try this method.

But I've I tried to use enable when statement instead of enablewhen expression, and I tried the following questionnaire:

{
  "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",
          "enableWhen": [
            {
              "question": "1-2",
              "operator": "=",
              "answerCoding": {
                "code": "answer-a",
                "display": "A"
              }
            }
          ],
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
              "valueString": "yyyy-mm-dd"
            }
          ]
        }
      ]
    }
  ]
}

which worked with #2597 which I've just sent out.

@github-project-automation github-project-automation bot moved this from New to Complete in Android FHIR SDK Jul 4, 2024
@allan-on
Copy link
Contributor Author

allan-on commented Jul 8, 2024

Thanks @jingtang10 and @santosh-pingle for working on this!
I've tested this on my end and it works with the enableWhen statement 👍🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High priority issue type:bug Something isn't working
Projects
Status: Complete
3 participants