Stream: hapi
Topic: contained resources
Sufyan Patel (Jul 28 2017 at 12:05):
Hi, Has anyone got an example of how they used the HAPI API to create contained resources?
I have tied the following ways:
Location loc = new Location();
loc.setAddress(new Address().setCity("Some City").setCountry("UK").setPostalCode("PO57 CDE"));
List<Resource> res = new ArrayList<Resource>();
res.add(loc);
hcs.setContained(res);
and also this way:
Location loc = new Location();
loc.setAddress(new Address().setCity("Some City").setCountry("UK").setPostalCode("PO57 CDE"));
hcs.addContained(loc);
But when I parse out the object, it does not have the contained resource.
Any help is much appreciated.
Kevin Mayfield (Jul 28 2017 at 12:28):
What you appear to be doing is adding an address to a location. Your're not adding a contained resource.
Kevin Mayfield (Jul 28 2017 at 12:29):
You could add a contained resource where a reference is required. Either the reference points to an external resource or the contained resource.
Kevin Mayfield (Jul 28 2017 at 12:35):
So your last example using Organisation as the contained resource :
See lines 100-118 in the link below
Kevin Mayfield (Jul 28 2017 at 12:52):
Or a more worked example
Kevin Mayfield (Jul 28 2017 at 12:52):
Sufyan Patel (Jul 28 2017 at 13:29):
Thanks Kevin, I didn't give a complete example earlier.
I am trying to add a contained resource (Location) to the HealthcareService resource. The hcs in the above code was the HealthcareService object.
P.S. I'm doing this in STU3 therefore for setLocation(...), it is expecting List <Resource>.
Kevin Mayfield (Jul 28 2017 at 13:33):
try adding an id to the loc Location e.g. loc.setId("#loc");
Kevin Mayfield (Jul 28 2017 at 13:35):
I think hapi doesn't know how to link the resources together.
Kevin Mayfield (Jul 28 2017 at 13:36):
On your second example... That looks like how I would have done on the STU3 version.
Kevin Mayfield (Jul 28 2017 at 13:43):
HealthcareService hcs = new HealthcareService(); loc.setId("#loc"); hcs.setLocation(new Reference(loc.getId())); // this bit will be different on STU3 hcs.addContained(loc);
Sufyan Patel (Jul 28 2017 at 14:27):
Got it to work with something like this
Location loc = new Location();
loc.setAddress(new Address().setCity("Some City").setCountry("UK").setPostalCode("PO57 CDE"));
loc.setId(new IdType().setValue("#9"));
List<Reference> res = new ArrayList<Reference>();
res.add(new Reference(loc.getId()));
hcs.addContained(loc);
hcs.setLocation(res);
return hcs;
Thanks for your help
Ruwen Böhm (Jul 09 2020 at 13:41):
Dear all, I'm trying to feed HAPI with a MedicationStatement containing a Medication resource. However, the contained resource is discarded, e.g.
<MedicationStatement xmlns="http://hl7.org/fhir">
<contained>
<Medication>
<code>
<coding>
<system value="http://fhir.de/CodeSystem/dimdi/atc"/>
<code value="j01ma02"/>
<display value="Ciprofloxacin"/>
</coding>
</code>
</Medication>
</contained>
<status value="active"/>
<subject>
<reference value....
Help is highly appreciated.
Rik Smithies (Jul 09 2020 at 14:37):
Can't see your reference properly, but contained resources need to be referenced by the containing resource (or possibly the other way around). Could that be it?
Jose Costa Teixeira (Jul 09 2020 at 20:07):
indeed - your contained resource does not have an ID, i would start there.
Ruwen Böhm (Jul 10 2020 at 19:40):
Thank you for pointing this out! I'll try. Additional question: HAPI FHIR can be run without storage: https://hapifhir.io/hapi-fhir/docs/server_plain/introduction.html and resources can be created by calling Constructors in Java using the class IResourceProvider, probably thus avoiding all the errors in otherwise created FHIR resources. Is there a tool to construct FHIR without the HAPI server (i.e., write it directly to a file)?
Lisa Nelson (May 18 2021 at 17:14):
Here is what we are seeing:
We are doing a conditional create of the Patient Resource inside a transaction bundle that also subsequently posts a Communication Resource which references that Patient as the subject and sender. The Transaction completes successfully but when I retrieve the Communication that was created, it has a "contained" Patient resource and the subject and sender are referencing the local contained Patient resource. This is not the behavior I was expecting to see. Do you know why this transaction is causing the Patient to be carried as a Contained Resource?
Cheng Liu (May 18 2021 at 17:17):
Here is the follow up for Lisa's question. Please check the attachment for the transaction bundle we post to the hapi FHIR server.
TransactionBundle.json
James Agnew (May 18 2021 at 18:04):
Just confirmed I see the same behaviour... Just trying to figure out why
Lisa Nelson (May 18 2021 at 18:35):
@James Agnew Glad you can reproduce it.
James Agnew (May 19 2021 at 13:53):
FYI this has been fixed. Thanks for supplying the test case, that was helpful.
Christian Gulden (May 21 2021 at 21:33):
I'm still seeing this issue with Device
and possibly other resource types as well on HAPI FHIR 5.4.0. But it occurs only after sending the same transaction twice, here's an example test case:
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "urn:uuid:4ec7879f-13da-4a24-a77a-6ea35d4d5a5a",
"resource": {
"resourceType": "Patient",
"identifier": [
{
"type": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "MR"
}
]
},
"system": "https://fhir.example.org/identifiers/patient-id",
"value": "123"
}
],
"gender": "female",
"birthDate": "1900-01-01"
},
"request": {
"method": "PUT",
"url": "Patient?identifier=https://fhir.example.org/identifiers/patient-id|123"
}
},
{
"fullUrl": "urn:uuid:b01d2e99-ec2b-475e-a69e-6e303e24edbc",
"resource": {
"resourceType": "Device",
"identifier": [
{
"system": "https://fhir.example.org/identifiers/device-id",
"value": "device-1"
}
],
"status": "active",
"deviceName": [
{
"name": "test",
"type": "manufacturer-name"
}
],
"version": [
{
"value": "1.0.0"
}
]
},
"request": {
"method": "POST",
"url": "Device",
"ifNoneExist": "identifier=https://fhir.example.org/identifiers/device-id|device-1"
}
},
{
"fullUrl": "urn:uuid:e08c6c9e-ca18-4524-bdfc-d5f8827e1acd",
"resource": {
"resourceType": "List",
"identifier": [
{
"system": "https://fhir.example.org/identifiers/list-id",
"value": "list-1"
}
],
"status": "current",
"mode": "working",
"source": {
"reference": "urn:uuid:b01d2e99-ec2b-475e-a69e-6e303e24edbc"
},
"entry": [
{
"item": {
"reference": "urn:uuid:4ec7879f-13da-4a24-a77a-6ea35d4d5a5a"
}
}
]
},
"request": {
"method": "PUT",
"url": "List?identifier=https://fhir.example.org/identifiers/list-id|list-1"
}
}
]
}
Turns into:
{
"resourceType": "List",
"id": "3",
"meta": {
"versionId": "2",
"lastUpdated": "2021-05-21T21:23:15.142+00:00",
"source": "#9NZJXYPb8Fz8jCBo"
},
"contained": [ {
"resourceType": "Device",
"id": "1",
"identifier": [ {
"system": "https://fhir.example.org/identifiers/device-id",
"value": "device-1"
} ],
"status": "active",
"deviceName": [ {
"name": "test",
"type": "manufacturer-name"
} ],
"version": [ {
"value": "1.0.0"
} ]
} ],
"identifier": [ {
"system": "https://fhir.example.org/identifiers/list-id",
"value": "list-1"
} ],
"status": "current",
"mode": "working",
"source": {
"reference": "#1"
},
"entry": [ {
"item": {
"reference": "Patient/2"
}
} ]
}
While version 1 looks like the expected outcome:
{
"resourceType": "List",
"id": "3",
"meta": {
"versionId": "1",
"lastUpdated": "2021-05-21T21:22:33.048+00:00",
"source": "#bfQutYlHbeMLoJaG"
},
"identifier": [
{
"system": "https://fhir.example.org/identifiers/list-id",
"value": "list-1"
}
],
"status": "current",
"mode": "working",
"source": {
"reference": "Device/1"
},
"entry": [
{
"item": {
"reference": "Patient/2"
}
}
]
}
James Agnew (May 23 2021 at 21:05):
@Christian Gulden Unfortunately the fix for this issue didn't make the code freeze date for 5.4.0. It is fixed in the current 5.5.0 snapshot builds, if you're able to test with that?
We're going to do a mid-cycle release this time around in about a month, so it'll be included in that.
Christian Gulden (May 25 2021 at 13:10):
Works perfectly using 5.5.0-PRE1-SNAPSHOT
. Thank you for your work!
Last updated: Apr 12 2022 at 19:14 UTC