Stream: fhirpath
Topic: inspecting contained resource
Jens Villadsen (Mar 25 2020 at 23:14):
How do I correctly get a hold of a certain (set of) contained resource(s) in an invariant. Lets say I have a Communication resource and the sender is a contained device. In my Invariant, I would like to get access to that particular contained resource. The following does not work (and it aint elegant either): contained.where(id = sender.reference.replace('#',''))
Jens Villadsen (Mar 25 2020 at 23:15):
the question is how is that correctly stated using FHIR Path?
Lloyd McKenzie (Mar 26 2020 at 04:53):
You should ideally be resolving the references (using .resolve()
) rather than relying on foreknowledge that the content will be contained.
Jens Villadsen (Mar 26 2020 at 08:40):
How do I inspect the identifier of the device when the example looks like the following?
{ "sender": { "reference": "#1" }, "meta": { "profile": [ "http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-message" ] }, "status": "completed", "medium": [ { "text": "WRITTEN", "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v3-ParticipationMode", "code": "WRITTEN" } ] } ], "recipient": [ { "reference": "http://inttest.ehealth.sundhed.dk/trifork-fhir-server/Patient/XXX" } ], "resourceType": "Communication", "category": [ { "text": "Besked", "coding": [ { "system": "http://ehealth.sundhed.dk/cs/message-category", "code": "message" } ] } ], "contained": [ { "id": "1", "resourceType": "Device", "identifier": [ { "value": "hello.system" } ] } ], "payload": [ { "contentString": "Hello world" } ], "sent": "2019-04-03T18:01:10-08:00" }
sender.resolve() returns the empty set
Jens Villadsen (Mar 26 2020 at 08:41):
at least using https://marketplace.visualstudio.com/items?itemName=Yannick-Lagger.vscode-fhir-tools
Jose Costa Teixeira (Oct 28 2021 at 20:54):
I have the same need, I guess
Jose Costa Teixeira (Oct 28 2021 at 20:55):
I am looking into a contained resource.
This evaluates to true:
contained.first().id=implementation.custodian.reference.substring(1,999)
Jose Costa Teixeira (Oct 28 2021 at 20:56):
(as it should) - this means that the first contained resource matches what I want to look for
Jose Costa Teixeira (Oct 28 2021 at 20:57):
so why doesn't contained.where(id=implementation.custodian.reference.substring(1,999))
return the first contained resource?
Lloyd McKenzie (Oct 28 2021 at 22:21):
contained.where(id=%resource.implementation.custodian.reference.substring(1,999))
will probably work
Lloyd McKenzie (Oct 28 2021 at 22:22):
When you're inside the where clause, the names of the properties you're referencing have to be 'visible' from the node you're on. In this case, the root node of all the contained resources
Lloyd McKenzie (Oct 28 2021 at 22:36):
%resource allows you to start at the root of the resource that is the 'base' for the current node
Jose Costa Teixeira (Oct 29 2021 at 06:21):
It seems that %resource is not implemented in the javascript library that I want to use.
Lloyd McKenzie (Oct 29 2021 at 13:05):
@Paul Lynch
Brian Postlethwaite (Oct 29 2021 at 23:41):
It is, but you have to set it when calling it.
Jose Costa Teixeira (Oct 30 2021 at 08:38):
What does that mean?
Brian Postlethwaite (Oct 30 2021 at 09:07):
The code that calls it needs to pass in an array of variables, including this one.
Brian Postlethwaite (Oct 30 2021 at 09:12):
Not the part on here that talks about environment variables, use that and add in resource to that array like it has for %a
https://github.com/HL7/fhirpath.js/
Jose Costa Teixeira (Oct 31 2021 at 22:20):
thanks. That works
Last updated: Apr 12 2022 at 19:14 UTC