hapi-fhir icon indicating copy to clipboard operation
hapi-fhir copied to clipboard

Issue converting XML to JSON with a contained resource referencing the container

Open shamilnn opened this issue 1 year ago • 1 comments

NOTE: Before filing a ticket, please see the following URL: https://github.com/hapifhir/hapi-fhir/wiki/Getting-Help

Describe the bug It seems there is still an issue when parsing/converting XML to JSON. For example, when an XML resource instance, such as Practitioner, contains a 'contained' PractitionerRole that references back to the Practitioner, the resulting JSON is missing the 'contained' PractitionerRole.

I have just tested this with HAPI FHIR version 4.2.0.

To Reproduce Steps to reproduce the behavior:

  1. Practitioner instance sample:
<Practitioner>
  <contained>
    <PractitionerRole>
      <id value="role"/>
      <practitioner>
        <reference value="#"/>
      </practitioner>
      <specialty>
        <coding>
          <system value="http://nucc.org/provider-taxonomy"/>
          <code value="207Q00000X"/>
        </coding>
      </specialty>
    </PractitionerRole>
  </contained>
  <identifier>
    <system value="http://hl7.org/fhir/sid/us-npi"/>
    <value value="99999999"/>
  </identifier>
</Practitioner>

when converted using this code:

IParser source = context.newXmlParser();
IBaseResource resource = source.parseResource( practitioner );
IParser target = context.newJsonParser();
return target.setPrettyPrint( true ).encodeResourceToString(resource);

the result is this:

{
  "resourceType": "Practitioner",
  "identifier": [
    {
      "system": "http://hl7.org/fhir/sid/us-npi",
      "value": "99999999"
    }
  ]
}

Expected behavior To comply with both statements in the FHIR spec: Resources can only be contained in other resources if there is a reference from the resource to the contained resource, or if the contained resource references the container resource.

Environment (please complete the following information):

  • HAPI FHIR Version 4.2.0

shamilnn avatar Nov 20 '23 20:11 shamilnn

4.2 is very old. Have you tried an updated version? I think 6.10.0 is the latest as of now.

XcrigX avatar Nov 20 '23 20:11 XcrigX