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 245 forks source link

Enhance x-fhir-query to handle fhirpath expression #1658

Closed maimoonak closed 1 year ago

maimoonak commented 1 year ago

Is your feature request related to a problem? Please describe. Enhance x-fhir-query to handle fhirpath expression in query as defined in spec https://build.fhir.org/ig/HL7/sdc/expressions.html#x-fhir-query-enhancements

jingtang10 commented 1 year ago

@maimoonak and @f-odhiambo can you share some use cases and give us an indication of the urgency/priority of this issue?

fredhersch commented 1 year ago

@maimoonak If this is an important issue (see Jing's comment), is this one you are interested/able to pick up?

cc: @f-odhiambo @pld

sevenreup commented 1 year ago

As of current, we are not able to access the context that the x-fhir-query is in. In our use case, we need to be able to access the patient id in the query to only get tasks that the patient owns. For example

Task?code=http://snomed.info/sct|12345678&subject={{Patient.id}}

cc: @KhumboLihonga @Gental-Giant

Gental-Giant commented 1 year ago

@f-odhiambo We have the above use case

jingtang10 commented 1 year ago

discussed with Khumbo - this is high priority.

KhumboLihonga commented 1 year ago

@jingtang10 thanks again for taking a look at this. One use case for this is where we want to get a list of active patients with the same organization id as the patient being observed. As per the documentation, I believe the questionnaire would look like this.

gosso22 commented 1 year ago

Hi @jingtang10 - another use case is for a scenario where you would want to use the information collected by a previous question in the questionnaire. For example we want to be able to select catchment areas based on selected district in the select district question in the questionnaire. When you select a certain district you would populate the drop down list of catchments areas that are part of that district. Below is the expression:

{ "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression", "valueExpression": { "expression": "Location?status=active&partof={{%resource.repeat(item).where(linkId='district' and answer.exists()).answer.value.reference}}", "language": "application/x-fhir-query" } }

omarismail94 commented 1 year ago

@KhumboLihonga can you see if you can use enhanced x-fhir-queries now? The PRs merged should allow you to. When setting up the questionnaire fragment, use the setQuestionnaireLaunchContext builder function to pass in the resource you want to evaluate your expressions against

KhumboLihonga commented 1 year ago

@sevenreup could you please take a look and confirm

sevenreup commented 1 year ago

@omarismail94 Tested the PR, and it works as intended. The only thing that I think is missing is the ability to add more than one Resource to the launch context. So currently you can only add one Resource to be accessed in the enhanced x-fhir-queries but we have some use cases that will need access to multiple resources, for example, accessing both the Patient and the Location resource.

omarismail94 commented 1 year ago

@sevenreup I was away for the last two weeks. Great to see this works! I can work on a follow-up PR to allow adding multiple resources as part of the context

sevenreup commented 1 year ago

Okay, thanks @omarismail94 that will be appreciated

omarismail94 commented 1 year ago

@sevenreup can you work off the changes I made in PR#2000 to see if that resolves your issue? When setting up the fragment, I changed the API to be setQuestionnaireLaunchContexts (pluralised). It expects an encoded list of all the resources you want to pass

sevenreup commented 1 year ago

@omarismail94 I managed to test out the PR, It works as intended. Used a Patient and Encounter as launch contexts and managed to access them in the x-fhir-query.

omarismail94 commented 1 year ago

@sevenreup PR is merged and will be part of the next release of the SDC library. Until that happens, you can fork/cherrypick