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

JsonParser in 1.0-SNAPSHOT does not populate resourceType in IdDt #163

Closed
nrpeterson opened this Issue Apr 16, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@nrpeterson
Contributor

nrpeterson commented Apr 16, 2015

When decoding a DSTU2 bundle using the jsonParser, the IDs attached to resources lose the resourceType portion.

This means that parsing a bundle (with jsonParser.parseResource(classOf[Bundle], resopnseText)), pulling a resource (say, resource) out of it, then making a reference to that resource loses that information. So, further encodeToString/parseResource iterations lose the ability to link resources properly.

@nrpeterson

This comment has been minimized.

Contributor

nrpeterson commented Apr 16, 2015

E.g.:

Say that we make a bundle, consisting only of a patient resource:

  val ctx = FhirContext.forDstu2()
  val jsonParser = ctx.newJsonParser() setPrettyPrint true

  // Patient
  val patient = new Patient()
  val patientId = UUID.randomUUID.toString
  patient setId {new IdDt("Patient", patientId)}
  patient.addName addGiven "John" addFamily "Smith"
  patient setGender AdministrativeGenderEnum.MALE
  patient setBirthDate {new DateDt("1987-04-16")}

  // Bundle
  val bundle = new Bundle()
  bundle setType BundleTypeEnum.COLLECTION
  bundle.addEntry setResource patient

Now, we encode the bundle to a string:

val bundleText = jsonParser encodeResourceToString bundle

and then parse it back out and retrieve the patient:

  val reincarnatedBundle = jsonParser parseResource (classOf[Bundle], bundleText)
  val reincarnatedPatient = reincarnatedBundle getAllPopulatedChildElementsOfType classOf[Patient] get 0

We can now see that information is lost:

println(patient.getId.getResourceType)     // Patient
println(reincarnatedPatient.getId.getResourceType)    // null

Now, making a new reference to reincarnatedPatient, we don't get the full reference:

  val reincarnatedBundle = jsonParser parseResource (classOf[Bundle], bundleText)
  val reincarnatedPatient = reincarnatedBundle getAllPopulatedChildElementsOfType classOf[Patient] get 0
  println(jsonParser encodeResourceToString height)

yields

{
    "resourceType":"Observation",
    "id":"2dc0064f-a83d-496b-9eb7-2daf71c52178",
    "code":{
        "coding":[
            {
                "system":"http://loinc.org",
                "code":"8302-2",
                "display":"Height"
            }
        ]
    },
    "valueQuantity":{
        "value":175.26,
        "units":"cm",
        "system":"http://unitsofmeasure.org"
    },
    "status":"final",
    "subject":{
        "reference":"4bf478f1-70ea-451f-b99a-18cbc9d27455"
    }
}
@jamesagnew

This comment has been minimized.

Owner

jamesagnew commented Apr 24, 2015

Out of curiosity, what language is this example? :)

Either way, thanks for reporting! I was able to reproduce and I have a fix. I'm going to commit it now, and push a new snapshot build in the morning.

@nrpeterson

This comment has been minimized.

Contributor

nrpeterson commented Apr 24, 2015

Scala. :-)

Thank you, sir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment