Stream: implementers
Topic: Contained Resources
Paul Barry (May 24 2016 at 22:36):
We are using transaction bundles to persist medicationDispense resources and all associated resources - organization, patient, dispenser. We'd like to link the MedicationDispense to the AuthorisingPrescription (MedicationOrder) if it exists. However if it doesn't exist we'd need to store the prescribing data somewhere but we wouldn't have enough information to create independent resources so I was thinking of using 'contained' resources. How would I put this logic in the transaction e.g. if AuthorisingPrescription exist then link else use contained resources
Paul Barry (May 25 2016 at 03:17):
We have since found in the spec the following statement on contained resources:
*Contained resources SHALL NOT contain additional contained resources*
This means we wouldn't be able to 'contain' the Prescriber within the MedicationOrder that is contained within the MedicationDispense. So we have a problem. How will we store the following data against our MedicationDispense resource?
Prescriber number
prescriber first name
prescriber last name
practice name
practice address
practice phone number
Creating a profile doesn't feel right?
Gaute Brakstad (May 25 2016 at 07:02):
Next you have a rule that says:
Gaute Brakstad (May 25 2016 at 07:02):
A contained resource SHALL only be included in a resource if something in that resource (potentially another contained resource) has a reference to it
Gaute Brakstad (May 25 2016 at 07:13):
we had some discussion internally in our company around this in a similar case. What we ended up with was following is not allowed:
<Composition xmlns="http://hl7.org/fhir">
<extension>...</extension>
<text>...</text>
<contained>
<Organization>
<contained>
<Organization>
<id value="org2"/>
</Organization>
</contained>
<id value="org1"/>
<partOf>
<reference value="#org2" />
</partOf>
</Organization>
</contained>
<information>
<custodian>
<reference value="#org1" />
</custodian>
<information>
</Composition>
While following is correct:
<Composition xmlns="http://hl7.org/fhir">
<extension>...</extension>
<text>...</text>
<contained>
<Organization>
<id value="org1"/>
<partOf>
<reference value="#org2" />
</partOf>
</Organization>¨
</contained>
<contained>
<Organization>
<id value="org2"/>
</Organization>
</contained>
<information>
<custodian>
<reference value="#org1" />
</custodian>
<information>
</Composition>
This is to make sure you only have to look one place for your contained resources. Basicly its the "master" resource that have all the contain
Paul Barry (May 25 2016 at 10:33):
@Gaute Brakstad Thanks for your response. I am not sure your solution works for my scenario. The organisation is only referenced by the prescriber and the prescriber can only be referenced by medicationOrder so how can I not go two deep?
Gaute Brakstad (May 25 2016 at 12:03):
<MedicationDispense xmlns="http://hl7.org/fhir">
<contained>
<MedicationOrder>
<id>order1</id>
<prescriber>
<reference value="#practitioner1" />
</prescriber>
</MedicationOrder>
</contained>
<contained>
<Practitioner>
<id>practitioner1</id>
</Practitioner>
</contained>
<authorizingPrescription>
<reference value="#order1" />
</authorizingPrescription>
</MedicationDispense>
Gaute Brakstad (May 25 2016 at 12:04):
Is it something like this you want to achive?
Yunwei Wang (May 25 2016 at 14:23):
@Paul Barry Just for curiosity, in which situation you have a MedicalDispense instance w/o MedicationOrder (so you have to create contained resource)?
Igor Sirkovich (May 25 2016 at 15:53):
We used the same solution as Gaute did: have all the contained resources under the MedicationDispense. Then each of these contained resources can reference any other contained resource
Grahame Grieve (May 25 2016 at 21:34):
yes that's the intent
Paul Barry (May 25 2016 at 22:19):
@Yunwei Wang Sometimes Pharmacies are connected to the system but the Prescribing systems are not. If the patient presents at the pharmacy they will submit details about the prescriber as well as their own dispensing information
Paul Barry (May 25 2016 at 22:26):
@Gaute Brakstad yes this is what we are trying to achieve. I see you have put the contained Practitioner inline with the contained MedicationOrder even though it is reference by the MedicationOrder (as opposed to the MedicationDispense). I wasn't sure if this was correct. Thanks for clarifying
Andrew Ross (Jun 03 2016 at 14:45):
A Bundle
is not allowed to have contained resources, right?
Andrew Ross (Jun 03 2016 at 14:45):
because it inherits from Resource
as opposed to DomainResource
Andrew Ross (Jun 03 2016 at 14:46):
but the resources referenced in Bundle.entry
each *can* have their own contained resources, right?
Andrew Ross (Jun 03 2016 at 14:46):
(but it wouldn't be possible for a resource in one entry
to reference something contained in another)
Andrew Ross (Jun 03 2016 at 14:47):
we're building a FHIR client library that might encapsulate looking up contained resources and we just want to make sure we're looking in the right place
Mirjam Baltus (Jun 03 2016 at 15:05):
Correct.
For which language/platform are you building the library?
Andrew Ross (Jun 03 2016 at 15:12):
Ruby
Andrew Ross (Jun 03 2016 at 15:12):
we're working with MITRE / FHIR crucible
Andrew Ross (Jun 03 2016 at 15:13):
they already have them published open source, we're just working on extending it to handle more use-cases
Igor Sirkovich (Jun 03 2016 at 20:43):
I've just found that if I try to validate a bundle with resources, which have contained resources on Grahame's server at fhir3.healthintersections.com.au/open/, I get an error that local references have to start with "#", but actually, all my local references start with "#". If I extract any resources from this bundle and try to validate on the same server , it passes the validation. @Grahame Grieve, could you please look at this issue when you have time?
Grahame Grieve (Jun 05 2016 at 12:01):
Igor, can you send me the bundle please
Igor Sirkovich (Jun 06 2016 at 14:32):
Igor Sirkovich (Jun 06 2016 at 14:35):
@Grahame Grieve , the bundle is attached above. I've simplified it, so it has only one MedicationDispense resource in it with a few data elements and a few references to contained resources.
Igor Sirkovich (Jun 06 2016 at 14:38):
The errors I get are of type: "SHALL have a local reference if the resource is provided inline (url: Medication561127; ids: ) () reference.startsWith('#').not() or (reference.substring(1).trace('url') in %resource.contained.id.trace('ids'))"
If I run the same resource with all its contained resources spearately (not part of a bundle), I get "All OK".
Grahame Grieve (Jun 07 2016 at 00:42):
ok I'll look
Igor Sirkovich (Jun 09 2016 at 19:06):
Thank you @Grahame Grieve
David Hay (Jun 25 2018 at 22:24):
Can a contained resource claim conformance to a profile? I don't see why not...
Grahame Grieve (Jun 26 2018 at 03:22):
yes
Raheel Sayeed (Jul 19 2018 at 15:44):
I have a similar question about contained resources, related to QuestionnaireResponse
and Questionnaire
.
1. Questionnaire is unique enough to exist as a contained resource in QuestionnaireResponse
.
2. Questionnaire has a contained resource ValueSet
, that Quesionnaire.item.options
references.
So: QuestionnaireResponse contains Questionnaire contains ValueSet
However, when the resource is created: all contained resources are within the parent resource
QuestionnaireResponse
.contained: [
1. Questionnaire
2. ValueSet
]
Is this an expected behavior? The Questionnaire.item.options have to be redirected to the contained
of parent resource and not its own contained
set?
Pascal Pfiffner (Jul 19 2018 at 15:58):
Contained resources cannot themselves contain resources, see http://build.fhir.org/references.html#contained
You simply stick them all in the parent resource and reference them with "#id", as you're already doing.
Raheel Sayeed (Jul 19 2018 at 16:07):
Contained resources cannot themselves contain resources, see http://build.fhir.org/references.html#contained
You simply stick them all in the parent resource and reference them with "#id", as you're already doing.
Yep, thats what I figured, this is corrected at the server! Nice.
Lloyd McKenzie (Jul 19 2018 at 17:35):
Corrected at the server? If you found a server that accepts a contained resource within a contained resource and fixes it for you, you're very lucky - as your inbound instance wasn't conformant and (in most environments) would have been rejected.
Last updated: Apr 12 2022 at 19:14 UTC