android-fhir icon indicating copy to clipboard operation
android-fhir copied to clipboard

Incorporate `%context` into variable expression evaluation

Open jingtang10 opened this issue 7 months ago • 0 comments

Is your feature request related to a problem? Please describe. In trying to resolve #2590, I started a discussion on fhir chat https://chat.fhir.org/#narrow/stream/179266-fhirpath/topic/parent.28.29.20or.20siblings.28.29.3F and was pointed to a solution where %context is used in variable expressions which are then used by enable when expressions to evaluate the enabled status of nested questions.

I authored a questionnaire that follows this approach:

{
  "resourceType": "Questionnaire",
  "item": [
    {
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/variable",
          "valueExpression": {
            "name": "answer",
            "language": "text/fhirpath",
            "expression": "%context.descendants().where(linkId='1-2').answer.value.code = 'answer-a'"
          }
        }
      ],
      "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": "%answer"
              }
            }
          ]
        }
      ]
    }
  ]
}

However, in our variable expression calculation, we don't incorporate the questionnaire response item.... this means we cannot pass the questionnarie response item to the fhir path engine as the %context fhir path supplement.

Describe the solution you'd like questionnaire response item needs to be added as a parameter in the evaluateVariable function.

Describe alternatives you've considered There's no alternative really

Additional context The issue #2590 is resolved using a different approach using just enable when elements instead of expressions. Please refer to the issue itself.

Would you like to work on the issue? Sure but happen to guide someone else to do this too. @f-odhiambo @f-odhiambo @allan-on if you guys are interested lmk ☺️

jingtang10 avatar Jul 09 '24 09:07 jingtang10