Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
contained resource in MedicationPrescription resource not included #113
I am now updating our FHIR server implementation from DSTU to DSTU2 (or DEV) to use some new resources. While doing that, I found that "contained" reference resource is not included in our MedicationPrescription resource. We haven't created Medication resource yet. So, we are using inline medication reference for medication parameter in MedicationPrescription. In DSTU structure, the contained referenced resource is printed in the response. However, when I use DSTU2, the contained resource does not present.
The spec says that domain resource (which extends resource) has contained element there. The base reference does have setContained method in HAPI API document for DEV.
Does anyone know what went wrong and how to fix this?
The follow is the code snippet. We are adding medication information in the contained section as we don't have Medication resource implemented yet. We are implementing MedicationPrescription first. The following codes successfully put in the response with the information we put when we used DSTU version of HAPI FHIR. However, when we switch to DEV version of HAPI FHIR, the element is gone and does not shown on the response. Am I explaining OK? Please let me know if you need more explanation.
// Adding medication to Contained.
// Medication reference. This should point to the contained resource.
Hello, thanks for providing that detail!
So, there are actually a few options you can use. What you have done should work, so I'm going to commit a fix shortly that will make it work as is in the next build of HAPI FHIR.
There are two workarounds though- HAPI currently expects your contained resource to have a local ID (an ID starting with '#'), so your code will work if you change
The easier way entirely is to just not assign any IDs to the contained resource, and not manually create the contained list. In that case, HAPI will automatically populate the contained list for you. The following should work:
// Adding medication to Contained. Medication medResource = new Medication(); // No ID set medResource.setCode(codeDt); // Medication reference. This should point to the contained resource. ResourceReferenceDt medRefDt = new ResourceReferenceDt(); medRefDt.setDisplay(nameDisp); // Resource reference set, but no ID medRefDt.setResource(medResource); medicationPrescript.setMedication(medRefDt);