\"\n" +
- " },\n" +
- " \"date\":\"2013-02-01T12:30:02Z\",\n" +
- " \"type\":{\n" +
- " \"coding\":[\n" +
- " {\n" +
- " \"system\":\"http://loinc.org\",\n" +
- " \"code\":\"28655-9\"\n" +
- " }\n" +
- " ],\n" +
- " \"text\":\"Discharge Summary from Responsible Clinician\"\n" +
- " },\n" +
- " \"status\":\"final\",\n" +
- " \"confidentiality\":\"N\",\n" +
- " \"subject\":{\n" +
- " \"reference\":\"http://fhir.healthintersections.com.au/open/Patient/d1\",\n" +
- " \"display\":\"Eve Everywoman\"\n" +
- " },\n" +
- " \"author\":[\n" +
- " {\n" +
- " \"reference\":\"Practitioner/example\",\n" +
- " \"display\":\"Doctor Dave\"\n" +
- " }\n" +
- " ],\n" +
- " \"encounter\":{\n" +
- " \"reference\":\"http://fhir.healthintersections.com.au/open/Encounter/doc-example\"\n" +
- " },\n" +
- " \"section\":[\n" +
- " {\n" +
- " \"title\":\"Reason for admission\",\n" +
- " \"content\":{\n" +
- " \"reference\":\"urn:uuid:d0dd51d3-3ab2-4c84-b697-a630c3e40e7a\"\n" +
- " }\n" +
- " },\n" +
- " {\n" +
- " \"title\":\"Medications on Discharge\",\n" +
- " \"content\":{\n" +
- " \"reference\":\"urn:uuid:673f8db5-0ffd-4395-9657-6da00420bbc1\"\n" +
- " }\n" +
- " },\n" +
- " {\n" +
- " \"title\":\"Known allergies\",\n" +
- " \"content\":{\n" +
- " \"reference\":\"urn:uuid:68f86194-e6e1-4f65-b64a-5314256f8d7b\"\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " }" +
- " ]" +
- "}";
- //@formatter:on
-
- ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
-
- String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
- ourLog.info(encoded);
-
- assertEquals("urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getId().getValue());
- assertEquals("urn:uuid:", parsed.getEntry().get(0).getResource().getId().getBaseUrl());
- assertEquals("180f219f-97a8-486d-99d9-ed631fe4fc57", parsed.getEntry().get(0).getResource().getId().getIdPart());
- assertThat(encoded, containsString("\"id\":\"180f219f-97a8-486d-99d9-ed631fe4fc57\""));
- }
-
-
- @Test
- public void testParseBundleWithBinary() {
- Binary patient = new Binary();
- patient.setId(new IdDt("http://base/Binary/11/_history/22"));
- patient.setContentType("foo");
- patient.setContent(new byte[] { 1, 2, 3, 4 });
-
- String val = ourCtx.newJsonParser().encodeResourceToString(patient);
- assertEquals("{\"resourceType\":\"Binary\",\"id\":\"11\",\"meta\":{\"versionId\":\"22\"},\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}", val);
- }
-
-
- @Test
- public void testEncodingNullExtension() {
- Patient p = new Patient();
- ExtensionDt extension = new ExtensionDt(false, "http://foo#bar");
- p.addUndeclaredExtension(extension);
- String str = ourCtx.newJsonParser().encodeResourceToString(p);
-
- assertEquals("{\"resourceType\":\"Patient\"}", str);
-
- extension.setValue(new StringDt());
-
- str = ourCtx.newJsonParser().encodeResourceToString(p);
- assertEquals("{\"resourceType\":\"Patient\"}", str);
-
- extension.setValue(new StringDt(""));
-
- str = ourCtx.newJsonParser().encodeResourceToString(p);
- assertEquals("{\"resourceType\":\"Patient\"}", str);
-
- }
-
- /**
- * See #163
- */
- @Test
- public void testParseResourceType() {
- IParser jsonParser = ourCtx.newJsonParser().setPrettyPrint(true);
-
- // Patient
- Patient patient = new Patient();
- String 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
- ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
- bundle.setType(BundleTypeEnum.COLLECTION);
- bundle.addEntry().setResource(patient);
-
- String bundleText = jsonParser.encodeResourceToString(bundle);
- ourLog.info(bundleText);
-
- ca.uhn.fhir.model.dstu2.resource.Bundle reincarnatedBundle = jsonParser.parseResource (ca.uhn.fhir.model.dstu2.resource.Bundle.class, bundleText);
- Patient reincarnatedPatient = (Patient) reincarnatedBundle.getEntry().get(0).getResource();
-
- assertEquals("Patient", patient.getId().getResourceType());
- assertEquals("Patient", reincarnatedPatient.getId().getResourceType());
- }
-
- /**
- * See #144 and #146
- */
- @Test
- public void testReportSerialize() {
-
- ReportObservation obsv = new ReportObservation();
- obsv.getCode().addCoding().setCode("name");
- obsv.setValue(new StringDt("value test"));
- obsv.setStatus(ObservationStatusEnum.FINAL);
- obsv.setReliability(ObservationReliabilityEnum.OK);
- obsv.addIdentifier().setSystem("System").setValue("id value");
-
- DiagnosticReport report = new DiagnosticReport();
- report.getContained().getContainedResources().add(obsv);
- report.addResult().setResource(obsv);
-
- IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
- String message = parser.encodeResourceToString(report);
- ourLog.info(message);
- Assert.assertThat(message, containsString("contained"));
- }
-
- @Test
- public void testEncodeBundleOldBundleNoText() {
-
- Bundle b = new Bundle();
-
- BundleEntry e = b.addEntry();
- e.setResource(new Patient());
- b.addCategory("scheme", "term", "label");
-
- String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
- ourLog.info(val);
-
- assertThat(val, not(containsString("text")));
-
- b = ourCtx.newJsonParser().parseBundle(val);
- assertEquals(1, b.getEntries().size());
-
- }
-
- @Test
- public void testEncodeBundleNewBundleNoText() {
-
- ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
- b.getText().setDiv("");
- b.getText().getStatus().setValueAsString("");
- ;
-
- Entry e = b.addEntry();
- e.setResource(new Patient());
-
- String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(b);
- ourLog.info(val);
- assertThat(val, not(containsString("text")));
-
- val = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(b);
- ourLog.info(val);
- assertThat(val, not(containsString("text")));
-
- }
-
- /**
- * See #144 and #146
- */
- @Test
- public void testReportSerializeWithMatchingId() {
-
- ReportObservation obsv = new ReportObservation();
- obsv.getCode().addCoding().setCode("name");
- obsv.setValue(new StringDt("value test"));
- obsv.setStatus(ObservationStatusEnum.FINAL);
- obsv.setReliability(ObservationReliabilityEnum.OK);
- obsv.addIdentifier().setSystem("System").setValue("id value");
-
- DiagnosticReport report = new DiagnosticReport();
- report.getContained().getContainedResources().add(obsv);
-
- obsv.setId("#123");
- report.addResult().setReference("#123");
-
- IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
- String message = parser.encodeResourceToString(report);
- ourLog.info(message);
- Assert.assertThat(message, containsString("contained"));
- }
-
- /**
- * see #144 and #146
- */
- @Test
- public void testParseContained() {
-
- FhirContext c = FhirContext.forDstu2();
- IParser parser = c.newJsonParser().setPrettyPrint(true);
-
- Observation o = new Observation();
- o.getCode().setText("obs text");
-
- Patient p = new Patient();
- p.addName().addFamily("patient family");
- o.getSubject().setResource(p);
-
- String enc = parser.encodeResourceToString(o);
- ourLog.info(enc);
-
- //@formatter:off
- assertThat(enc, stringContainsInOrder(
- "\"resourceType\":\"Observation\"",
- "\"contained\":[",
- "\"resourceType\":\"Patient\",",
- "\"id\":\"1\"",
- "\"reference\":\"#1\""
- ));
- //@formatter:on
-
- o = parser.parseResource(Observation.class, enc);
- assertEquals("obs text", o.getCode().getText());
-
- assertNotNull(o.getSubject().getResource());
- p = (Patient) o.getSubject().getResource();
- assertEquals("patient family", p.getNameFirstRep().getFamilyAsSingleString());
- }
-
- @Test
- public void testEncodeAndParseMetaProfileAndTags() {
- Patient p = new Patient();
- p.addName().addFamily("FAMILY");
-
- List