Skip to content
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

Issue with parsing contained resource from JSON #146

Closed
mojitoholic opened this Issue Apr 1, 2015 · 8 comments

Comments

Projects
None yet
3 participants
@mojitoholic
Copy link
Contributor

mojitoholic commented Apr 1, 2015

(I did not delve into this in detail but I thought I'd report it here FWIW)
Using the latest snapshot and querying for MedicationPrescription, the contained Medication resources are not parsed correctly -- the link is there but the actual resource content is null. When I change the rest client to force using XML instead of JSON it works well.

@jamesagnew

This comment has been minimized.

Copy link
Owner

jamesagnew commented Apr 1, 2015

Hi @mochaholic, thanks for reporting!
Is this against a public server by any chance? If so, can you share the URL you're using so we can put together a unit test?

@mojitoholic

This comment has been minimized.

Copy link
Contributor Author

mojitoholic commented Apr 1, 2015

No. But here is an example (I have redacted the urls). containedResources.size() is 0.

    String resourceString = "{\n" +
            "    \"resourceType\":\"Bundle\",\n" +
            "    \"id\":\"ea00edca-7ede-42c5-a64c-04225740e5f9\",\n" +
            "    \"text\":{\n" +
            "    },\n" +
            "    \"type\":\"searchset\",\n" +
            "    \"base\":\"...\",\n" +
            "    \"total\":1,\n" +
            "    \"link\":[\n" +
            "        {\n" +
            "            \"relation\":\"self\",\n" +
            "            \"url\":\"...\"\n" +
            "        }\n" +
            "    ],\n" +
            "    \"entry\":[\n" +
            "        {\n" +
            "            \"resource\":{\n" +
            "                \"resourceType\":\"MedicationPrescription\",\n" +
            "                \"id\":\"medicationprescription-179\",\n" +
            "                \"meta\":{\n" +
            "                    \"versionId\":\"1\",\n" +
            "                    \"lastUpdated\":\"2015-01-14T16:08:20.000-05:00\"\n" +
            "                },\n" +
            "                \"status\":\"active\",\n" +
            "                \"patient\":{\n" +
            "                    \"reference\":\"Patient/patient-1642068\"\n" +
            "                },\n" +
            "                \"medication\":{\n" +
            "                    \"reference\":\"#med\"\n" +
            "                }\n" +
            "            },\n" +
            "            \"search\":{\n" +
            "                \"mode\":\"match\"\n" +
            "            }\n" +
            "        }\n" +
            "    ]\n" +
            "}";

    FhirContext context = FhirContext.forDstu2();
    Bundle bundle =context.newJsonParser().parseBundle(resourceString);
    List<? extends IResource> containedResources = bundle.getEntries().get(0).getResource().getContained().getContainedResources();
@baopingle

This comment has been minimized.

Copy link

baopingle commented Apr 2, 2015

If using the new FhirContext().newXmlParser().parseResource(resource), the contained resources of this resource can not be parsed correctly. I also report this issue #144.

@jamesagnew

This comment has been minimized.

Copy link
Owner

jamesagnew commented Apr 2, 2015

The snippet above doesn't actually have any contained resources in it. I.e. I don't see any "#med" anywhere except in the reference so I would expect getContainedResources() to not return anything.

I've added a unit test for this in checkin 0ca1b9f but so far I haven't been able to reproduce. The unit test passes so presumably there is something I'm missing.

@mojitoholic

This comment has been minimized.

Copy link
Contributor Author

mojitoholic commented Apr 2, 2015

That's right sorry I rushed a bit. The problem seems to be in the JSON encoder. When I get the XML bundle the contained resource is there but when I switched to JSON and copied seems like the contained resource didn't appear. Let me work on this a bit more to come up with an example.

@jamesagnew

This comment has been minimized.

Copy link
Owner

jamesagnew commented Apr 2, 2015

Fantastic, that would be great. I'm hoping to release HAPI FHIR 1.0 within
the next 24 hours so it would be awesome to have this bug fixed in that
release.

Cheers,
James

On Thu, Apr 2, 2015 at 12:09 PM, Mohammad Jafari notifications@github.com
wrote:

That's right sorry I rushed a bit. The problem seems to be in the JSON
encoder. When I got the XML bundle the contained resource is there but when
I switched to JSON and copied seems like the contained resource didn't
appear. Let me work on this a bit more to come up with an example.


Reply to this email directly or view it on GitHub
#146 (comment)
.

@mojitoholic

This comment has been minimized.

Copy link
Contributor Author

mojitoholic commented Apr 3, 2015

OK so I can reproduce this issue now with a resource I created on the uhn test server:

        FhirContext context = FhirContext.forDstu2();
        IGenericClient restClient = context.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
        restClient.setEncoding(EncodingEnum.XML);
        Bundle bundle = restClient.search(new UriDt("http://fhirtest.uhn.ca/baseDstu2/MedicationPrescription?patient=13123"));
        int containedResourcesWithXML = bundle.getEntries().get(0).getResource().getContained().getContainedResources().size();
        System.out.println(containedResourcesWithXML);

        restClient.setEncoding(EncodingEnum.JSON);
        bundle = restClient.search(new UriDt("http://fhirtest.uhn.ca/baseDstu2/MedicationPrescription?patient=13123"));
        int containedResourcesWithJSON = bundle.getEntries().get(0).getResource().getContained().getContainedResources().size();
        System.out.println(containedResourcesWithJSON);

        assert containedResourcesWithXML == containedResourcesWithJSON;
@jamesagnew

This comment has been minimized.

Copy link
Owner

jamesagnew commented Apr 3, 2015

Ahh fantastic. Thanks for all the effort in tracking this down, we now have a working unit test! Solution should be coming up shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.