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
463 stars 241 forks source link

bug creating XFhirQuery from expression #2451

Open FikriMilano opened 3 months ago

FikriMilano commented 3 months ago

Describe the bug there is a bug in createXFhirQueryFromExpression method.

in the case of having a launchContext in a questionnaire, where if we try to combine both fhirPathsEvaluatedPairs and variablesEvaluatedPairs, then fold the expression to replace the string template into the right evaluated value, the resulting xFhirQuery string gives the wrong result.

that happens because of the same variable name from both fhirPathsEvaluatedPairs and variablesEvaluatedPairs, and the variable from fhirPathsEvaluatedPairs are given first priority over the one from variablesEvaluatedPairs.

the one value from fhirPathsEvaluatedPairs are empty, while what we need was from variablesEvaluatedPairs.

the resulting xFhirQuery has a search parameter, but that search parameter value is empty because of this. This will cause the fhirEngine resolver to search all resources of that type mentioned in the xFhirQuery. This can be prevented by using the _count param.

Example: fhirPathsEvaluatedPairs contains: [{a}, “”] variablesEvaluatedPairs contains: [{a}, “47626”]

Resulting xFhirQuery: Patient?_id= The expected and correct xFhirQuery: Patient?_id=47626

Prevention 1: xFhirQuery: Patient?_count =1&_id=

Prevention 2: xFhirQuery: Patient?name=NOTHING

*assume NOTHING as a variable

Component SDC library

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior when launchContext exists in a questionnaire but not used in the X-FHIR-Query, fhirPathsEvaluatedPairs should return an empty sequence instead of a non empty sequence with a key and an empty value.

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

Additional context original ticket

Would you like to work on the issue? Yes

MJ1998 commented 1 month ago

What if we validate if keys present in fhirPathsEvaluatedPairs are valid fhir paths ?