-
Notifications
You must be signed in to change notification settings - Fork 293
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
EnableWhenExpression context literal fhirpath supplement implementation #1957
Conversation
datacapture/src/main/java/com/google/android/fhir/datacapture/fhirpath/FhirPathUtil.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @maimoonak for this PR.
I'm having some trouble understanding what this PR is doing beyond wrapping fhir path engine functions in wrappers.
To support fhirpath supplements, we need to use FHIRPathEngineHostServices
so that it can resolve %resource
, %context
etc. It is the service FHIRPathEngine
uses when it sees a variable with %
that it cannot resolve.
@omarismail94 fyi - we discussed this before. |
There is a bug where we are not passing focusResource (which is recognized as %resource in expression) and baseResource (which is recognized as %context or $this in expression) separately into evaluate function when evaluating enableWhen-expression. This leads to a missing feature i.e. use of %context to get current questionnaireResponseItem in expression as defined here https://build.fhir.org/ig/HL7/sdc/expressions.html#fhirpath-supplements and a bug where user can use %resource, %context, $this all constants for questionnaireResponse which is wrong.
As per implementation here org.hl7.fhir.r4.utils.FHIRPathEngine#resolveConstant(ExecutionContext, String, boolean, ExpressionNode), the constants which are part of default fhir spec (https://hl7.org/fhir/fhirpath.html#variables and https://hl7.org/fhir/fhirpath.html#vars) i.e. %constant_name are resolved automatically by engine. We can not provide implementation for those. If any variable is not reserved one and is provided by specific IG, then we need to provide it via HostServices. Some of the examples of such cases are StructureMap extraction and SDC variable resolution. See attached image to see the code flow. |
datacapture/src/main/java/com/google/android/fhir/datacapture/fhirpath/FhirPathUtil.kt
Show resolved
Hide resolved
Co-authored-by: Jing Tang <[email protected]>
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Fixes #1958
Description
To make question fhirpath dynamic and have current questionnaire item we need to support fhirpath supplement context literal. This allow to get current questionnaire item as %context into fhirpath expressions on questionnaire items. Details for spec defined here https://build.fhir.org/ig/HL7/sdc/expressions.html#fhirpath-supplements .
This is a bug fix and the changes MAY affect existing use of enableWhenExpression where anyone tried to write expression for questionnaireResponse as $this. $this refers to current item under consideration aka %context as well. Old implementation might have entertained $this as questionnaireResponse. Hence anyone using expression wrongfully can have erratic behavior for their current enableWhenExpressions
Alternative(s) considered
Bug fix
Type
Choose one: Bug fix
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project../gradlew check
and./gradlew connectedCheck
to test my changes locally.