Using FHIRPath to determine type of Reference in MedicationRequest

34 views
Skip to first unread message

Akkaash Goel

unread,
Jan 13, 2022, 8:28:31 PM1/13/22
to HAPI FHIR
I am trying to use FHIRPath in a MedicationRequest resource such that I would like to check if the reference in MedicationRequest.subject is of type Patient. Specifically, the FHIRPath is 
"MedicationRequest.subject.where(resolve() is Patient)"
and my code is "fhirContext.newFhirPath().evaluate(medicationRequestObj, expression, Patient.class)"

I looked into the code for FHIRPathEngine (FPE) and from what I can understand (which can be entirely incorrect), FPE is trying to resolve the resource reference itself. Is my understanding correct?

My requirement however is just to simply return whether or not the reference is of type Patient. Open to all ideas from the group here. Thank you. 

Oliver Egger

unread,
Jan 14, 2022, 2:31:40 AM1/14/22
to Akkaash Goel, HAPI FHIR
Hi Akkash


I am trying to use FHIRPath in a MedicationRequest resource such that I would like to check if the reference in MedicationRequest.subject is of type Patient. Specifically, the FHIRPath is 
"MedicationRequest.subject.where(resolve() is Patient)"
and my code is "fhirContext.newFhirPath().evaluate(medicationRequestObj, expression, Patient.class)"

I looked into the code for FHIRPathEngine (FPE) and from what I can understand (which can be entirely incorrect), FPE is trying to resolve the resource reference itself. Is my understanding correct?
Yes that what is resolve should do according to the spec, see https://www.hl7.org/fhir/fhirpath.html.

My requirement however is just to simply return whether or not the reference is of type Patient. Open to all ideas from the group here. Thank you. 
You could only for certain use cases derive the type from the reference without resolving it. 
- If the type of the reference is specified (https://hl7.org/fhir/references-definitions.html#Reference.type), but this is optional. 
- if it is a reference which has an url with the resource type in it, however you don't have that in all usecases (could also be a reference to a contained resource without type information or a reference by uuid in a bundle).

Hope that helps
Oliver

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/1fad42b2-d39b-4bec-bcf0-a8f03ff35dedn%40googlegroups.com.

Akkaash Goel

unread,
Jan 14, 2022, 4:03:52 AM1/14/22
to HAPI FHIR
Thanks for your response Oliver. The behavior makes sense now. 

It would be interesting to see if there's a way I can then possibly update the behavior on FPE to see if I can alter the resolve logic so that it uses a different data store instead of HAPI FHIR trying to resolve the reference. Do you have any ideas on how I plug in to that framework? 

Oliver Egger

unread,
Jan 14, 2022, 5:27:20 AM1/14/22
to Akkaash Goel, HAPI FHIR
Hi Akkash

FHIRPathEngine can be set with an EvaluationContext which defines a resolveReference function:

  /**

     * Implementation of resolve() function. Passed a string, return matching resource, if one is known - else null

     * @appContext - passed in by the host to the FHIRPathEngine

     * @param url the reference (Reference.reference or the value of the canonical

     * @return

     * @throws FHIRException 

     */

    public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException;


maybe you can try that?

Best regards,
Oliver

Reply all
Reply to author
Forward
0 new messages