New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contained resource in MedicationPrescription resource not included #113

Closed
myungchoi opened this Issue Feb 20, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@myungchoi

myungchoi commented Feb 20, 2015

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?

@jamesagnew

This comment has been minimized.

Owner

jamesagnew commented Mar 12, 2015

Hello, would you be able to provide a code sample that illustrates what you mean? I'm not sure I'm following this bug unfortunately.

@myungchoi

This comment has been minimized.

myungchoi commented Mar 13, 2015

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 medResource = new Medication();
medResource.setCode(codeDt);
medResource.setId(String.valueOf(medId));
ArrayList medResList = new ArrayList();
medResList.add(medResource);
ContainedDt medContainedDt = new ContainedDt();
medContainedDt.setContainedResources(medResList);
medicationPrescript.setContained(medContainedDt);

// Medication reference. This should point to the contained resource.
ResourceReferenceDt medRefDt = new ResourceReferenceDt("#" + medId);
medRefDt.setDisplay(nameDisp);
medicationPrescript.setMedication(medRefDt);

@jamesagnew

This comment has been minimized.

Owner

jamesagnew commented Mar 19, 2015

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
medResource.setId(String.valueOf(medId));
to
medResource.setId('#' + String.valueOf(medId));

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment