Java Code Examples for org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent#getResource()

The following examples show how to use org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent#getResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SNOMEDUKMockValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
private void loadStructureDefinitions(FhirContext theContext, Map<String, StructureDefinition> theCodeSystems, String theClasspath) {
  logD("SNOMEDMOCK Loading structure definitions from classpath: "+ theClasspath);
  InputStream valuesetText = SNOMEDUKMockValidationSupport.class.getResourceAsStream(theClasspath);
  if (valuesetText != null) {
    InputStreamReader reader = new InputStreamReader(valuesetText, Charsets.UTF_8);

    Bundle bundle = theContext.newXmlParser().parseResource(Bundle.class, reader);
    for (BundleEntryComponent next : bundle.getEntry()) {
      if (next.getResource() instanceof StructureDefinition) {
        StructureDefinition nextSd = (StructureDefinition) next.getResource();
        nextSd.getText().setDivAsString("");
        String system = nextSd.getUrl();
        if (isNotBlank(system)) {
          theCodeSystems.put(system, nextSd);
        }
      }
    }
  } else {
    log.warn("Unable to load resource: {}", theClasspath);
  }
}
 
Example 2
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public Resource resolve(String value) {
  if (value.startsWith("#")) {
    for (Resource r : resourceResource.getContained()) {
      if (r.getId().equals(value.substring(1)))
        return r;
    }
    return null;
  }
  if (bundleResource != null) {
    for (BundleEntryComponent be : bundleResource.getEntry()) {
      if (be.getFullUrl().equals(value))
        return be.getResource();
      if (value.equals(be.getResource().fhirType()+"/"+be.getResource().getId()))
        return be.getResource();
    }
  }
  return null;
}
 
Example 3
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static String representDataElementCollection(IWorkerContext context, Bundle bundle, boolean profileLink, String linkBase) {
  StringBuilder b = new StringBuilder();
  DataElement common = showDECHeader(b, bundle);
  b.append("<table class=\"grid\">\r\n"); 
  List<String> cols = chooseColumns(bundle, common, b, profileLink);
  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    renderDE(de, cols, b, profileLink, linkBase);
  }
  b.append("</table>\r\n");
  return b.toString();
}
 
Example 4
Source File: FhirStu3.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Create an entry for the given Claim, which references a Medication.
 *
 * @param personEntry Entry for the person
 * @param bundle The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claim the Claim object
 * @param medicationEntry The Entry for the Medication object, previously created
 * @return the added Entry
 */
private static BundleEntryComponent medicationClaim(BundleEntryComponent personEntry,
    Bundle bundle, BundleEntryComponent encounterEntry, Claim claim,
    BundleEntryComponent medicationEntry) {
  org.hl7.fhir.dstu3.model.Claim claimResource = new org.hl7.fhir.dstu3.model.Claim();
  org.hl7.fhir.dstu3.model.Encounter encounterResource =
      (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();

  claimResource.setStatus(ClaimStatus.ACTIVE);
  claimResource.setUse(org.hl7.fhir.dstu3.model.Claim.Use.COMPLETE);

  // duration of encounter
  claimResource.setBillablePeriod(encounterResource.getPeriod());

  claimResource.setPatient(new Reference(personEntry.getFullUrl()));
  claimResource.setOrganization(encounterResource.getServiceProvider());

  // add item for encounter
  claimResource.addItem(new org.hl7.fhir.dstu3.model.Claim.ItemComponent(new PositiveIntType(1))
      .addEncounter(new Reference(encounterEntry.getFullUrl())));

  // add prescription.
  claimResource.setPrescription(new Reference(medicationEntry.getFullUrl()));

  Money moneyResource = new Money();
  moneyResource.setValue(claim.getTotalClaimCost());
  moneyResource.setCode("USD");
  moneyResource.setSystem("urn:iso:std:iso:4217");
  claimResource.setTotal(moneyResource);

  return newEntry(bundle, claimResource);
}
 
Example 5
Source File: FhirStu3.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Find the Practitioner entry in this bundle, and return the associated "fullUrl"
 * attribute.
 * @param clinician A given clinician.
 * @param bundle The current bundle being generated.
 * @return Practitioner.fullUrl if found, otherwise null.
 */
private static String findPractitioner(Clinician clinician, Bundle bundle) {
  for (BundleEntryComponent entry : bundle.getEntry()) {
    if (entry.getResource().fhirType().equals("Practitioner")) {
      Practitioner doc = (Practitioner) entry.getResource();
      if (doc.getIdentifierFirstRep().getValue().equals("" + clinician.identifier)) {
        return entry.getFullUrl();
      }
    }
  }
  return null;
}
 
Example 6
Source File: FhirStu3.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Find the provider entry in this bundle, and return the associated "fullUrl" attribute.
 * @param provider A given provider.
 * @param bundle The current bundle being generated.
 * @return Provider.fullUrl if found, otherwise null.
 */
private static String findProviderUrl(Provider provider, Bundle bundle) {
  for (BundleEntryComponent entry : bundle.getEntry()) {
    if (entry.getResource().fhirType().equals("Organization")) {
      Organization org = (Organization) entry.getResource();
      if (org.getIdentifierFirstRep().getValue().equals(provider.getResourceID())) {
        return entry.getFullUrl();
      }
    }
  }
  return null;
}
 
Example 7
Source File: Unbundler.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static void unbundle(String src) throws FHIRFormatError, FileNotFoundException, IOException {
  String folder = Utilities.getDirectoryForFile(src);
  Bundle bnd = (Bundle) new JsonParser().parse(new FileInputStream(src));
  for (BundleEntryComponent be : bnd.getEntry()) {
    Resource r = be.getResource();
    if (r != null) {
      String tgt = Utilities.path(folder, r.fhirType()+"-"+r.getId()+".json");
      new JsonParser().compose(new FileOutputStream(tgt), r);
    }
  }
}
 
Example 8
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(Bundle b, boolean evenIfAlreadyHasNarrative) throws EOperationOutcome, FHIRException, IOException {
  boolean res = false;
  this.bundle = b;
  for (BundleEntryComponent be : b.getEntry()) {
    if (be.hasResource() && be.getResource() instanceof DomainResource) {
      DomainResource dr = (DomainResource) be.getResource();
      if (evenIfAlreadyHasNarrative || !dr.getText().hasDiv())
        res = generate(new ResourceContext(b, dr), dr) || res;
    }
  }
  return res;
}
 
Example 9
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static boolean hasUnits(Bundle bundle) {
  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    if (ToolingExtensions.getAllowedUnits(de.getElement().get(0)) != null)
      return true;
  }
  return false;
}
 
Example 10
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static boolean hasType(Bundle bundle) {
  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    if (de.getElement().get(0).hasType())
      return true;
  }
  return false;
}
 
Example 11
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static boolean hasCode(Bundle bundle) {
  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    if (de.getElement().get(0).hasCode())
      return true;
  }
  return false;
}
 
Example 12
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static boolean hasBinding(Bundle bundle) {
  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    if (de.getElement().get(0).hasBinding())
      return true;
  }
  return false;
}
 
Example 13
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static boolean hasExtension(Bundle bundle, String url) {
  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    if (ToolingExtensions.hasExtension(de, url))
      return true;
  }
  return false;
}
 
Example 14
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Resource getById(Bundle feed, ResourceType type, String reference) {
  for (BundleEntryComponent item : feed.getEntry()) {
    if (item.getResource().getId().equals(reference) && item.getResource().getResourceType() == type)
      return item.getResource();
  }
  return null;
}
 
Example 15
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private static DataElement showDECHeader(StringBuilder b, Bundle bundle) {
  DataElement meta = new DataElement();
  DataElement prototype = (DataElement) bundle.getEntry().get(0).getResource();
  meta.setPublisher(prototype.getPublisher());
  meta.getContact().addAll(prototype.getContact());
  meta.setStatus(prototype.getStatus());
  meta.setDate(prototype.getDate());
  meta.addElement().getType().addAll(prototype.getElement().get(0).getType());

  for (BundleEntryComponent e : bundle.getEntry()) {
    DataElement de = (DataElement) e.getResource();
    if (!Base.compareDeep(de.getPublisherElement(), meta.getPublisherElement(), false))
      meta.setPublisherElement(null);
    if (!Base.compareDeep(de.getContact(), meta.getContact(), false))
      meta.getContact().clear();
    if (!Base.compareDeep(de.getStatusElement(), meta.getStatusElement(), false))
      meta.setStatusElement(null);
    if (!Base.compareDeep(de.getDateElement(), meta.getDateElement(), false))
      meta.setDateElement(null);
    if (!Base.compareDeep(de.getElement().get(0).getType(), meta.getElement().get(0).getType(), false))
      meta.getElement().get(0).getType().clear();
  }
  if (meta.hasPublisher() || meta.hasContact() || meta.hasStatus() || meta.hasDate() /* || meta.hasType() */) {
    b.append("<table class=\"grid\">\r\n"); 
    if (meta.hasPublisher())
      b.append("<tr><td>Publisher:</td><td>"+meta.getPublisher()+"</td></tr>\r\n");
    if (meta.hasContact()) {
      b.append("<tr><td>Contacts:</td><td>");
      boolean firsti = true;
      for (ContactDetail c : meta.getContact()) {
        if (firsti)
          firsti = false;
        else
          b.append("<br/>");
        if (c.hasName())
          b.append(Utilities.escapeXml(c.getName())+": ");
        boolean first = true;
        for (ContactPoint cp : c.getTelecom()) {
          if (first)
            first = false;
          else
            b.append(", ");
          renderContactPoint(b, cp);
        }
      }
      b.append("</td></tr>\r\n");
    }
    if (meta.hasStatus())
      b.append("<tr><td>Status:</td><td>"+meta.getStatus().toString()+"</td></tr>\r\n");
    if (meta.hasDate())
      b.append("<tr><td>Date:</td><td>"+meta.getDateElement().asStringValue()+"</td></tr>\r\n");
    if (meta.getElement().get(0).hasType())
      b.append("<tr><td>Type:</td><td>"+renderType(meta.getElement().get(0).getType())+"</td></tr>\r\n");
    b.append("</table>\r\n"); 
  }  
  return meta;
}
 
Example 16
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsSystem(String system) throws TerminologyServiceException {
  if (codeSystems.containsKey(system)) {
    return true;
  } else if (nonSupportedCodeSystems.contains(system)) {
    return false;
  } else if (system.startsWith("http://example.org") || system.startsWith("http://acme.com")
    || system.startsWith("http://hl7.org/fhir/valueset-") || system.startsWith("urn:oid:")) {
    return false;
  } else {
    if (noTerminologyServer) {
      return false;
    }
    if (bndCodeSystems == null) {
      try {
        tlog("Terminology server: Check for supported code systems for " + system);
        bndCodeSystems = txServer.fetchFeed(txServer.getAddress()
          + "/CodeSystem?content-mode=not-present&_summary=true&_count=1000");
      } catch (Exception e) {
        if (canRunWithoutTerminology) {
          noTerminologyServer = true;
          log("==============!! Running without terminology server !!============== (" + e
            .getMessage() + ")");
          return false;
        } else {
          throw new TerminologyServiceException(e);
        }
      }
    }
    if (bndCodeSystems != null) {
      for (BundleEntryComponent be : bndCodeSystems.getEntry()) {
        CodeSystem cs = (CodeSystem) be.getResource();
        if (!codeSystems.containsKey(cs.getUrl())) {
          codeSystems.put(cs.getUrl(), null);
        }
      }
    }
    if (codeSystems.containsKey(system)) {
      return true;
    }
  }
  nonSupportedCodeSystems.add(system);
  return false;
}
 
Example 17
Source File: FhirStu3.java    From synthea with Apache License 2.0 4 votes vote down vote up
/**
 * Add a MedicationAdministration if needed for the given medication.
 * 
 * @param personEntry       The Entry for the Person
 * @param bundle            Bundle to add the MedicationAdministration to
 * @param encounterEntry    Current Encounter entry
 * @param medication        The Medication
 * @param medicationRequest The related medicationRequest
 * @return The added Entry
 */
private static BundleEntryComponent medicationAdministration(
    BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry,
    Medication medication, MedicationRequest medicationRequest) {

  MedicationAdministration medicationResource = new MedicationAdministration();

  medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
  medicationResource.setContext(new Reference(encounterEntry.getFullUrl()));

  Code code = medication.codes.get(0);
  String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;

  medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
  medicationResource.setEffective(new DateTimeType(new Date(medication.start)));

  medicationResource.setStatus(MedicationAdministrationStatus.fromCode("completed"));

  if (medication.prescriptionDetails != null) {
    JsonObject rxInfo = medication.prescriptionDetails;
    MedicationAdministrationDosageComponent dosage =
        new MedicationAdministrationDosageComponent();

    // as_needed is true if present
    if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
      Quantity dose = new SimpleQuantity().setValue(
          rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
      dosage.setDose((SimpleQuantity) dose);

      if (rxInfo.has("instructions")) {
        for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
          JsonObject instruction = instructionElement.getAsJsonObject();

          dosage.setText(instruction.get("display").getAsString());
        }
      }
    }
    medicationResource.setDosage(dosage);
  }

  if (!medication.reasons.isEmpty()) {
    // Only one element in list
    Code reason = medication.reasons.get(0);
    for (BundleEntryComponent entry : bundle.getEntry()) {
      if (entry.getResource().fhirType().equals("Condition")) {
        Condition condition = (Condition) entry.getResource();
        // Only one element in list
        Coding coding = condition.getCode().getCoding().get(0);
        if (reason.code.equals(coding.getCode())) {
          medicationResource.addReasonReference().setReference(entry.getFullUrl());
        }
      }
    }
  }

  BundleEntryComponent medicationAdminEntry = newEntry(bundle, medicationResource);
  return medicationAdminEntry;
}
 
Example 18
Source File: FhirStu3.java    From synthea with Apache License 2.0 4 votes vote down vote up
/**
 * Map the given CarePlan to a FHIR CarePlan resource, and add it to the given Bundle.
 *
 * @param personEntry The Entry for the Person
 * @param bundle Bundle to add the CarePlan to
 * @param encounterEntry Current Encounter entry
 * @param carePlan The CarePlan to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static BundleEntryComponent careplan(BundleEntryComponent personEntry, Bundle bundle,
    BundleEntryComponent encounterEntry, CarePlan carePlan) {
  org.hl7.fhir.dstu3.model.CarePlan careplanResource = new org.hl7.fhir.dstu3.model.CarePlan();
  careplanResource.setIntent(CarePlanIntent.ORDER);
  careplanResource.setSubject(new Reference(personEntry.getFullUrl()));
  careplanResource.setContext(new Reference(encounterEntry.getFullUrl()));

  Code code = carePlan.codes.get(0);
  careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));

  CarePlanActivityStatus activityStatus;
  GoalStatus goalStatus;

  Period period = new Period().setStart(new Date(carePlan.start));
  careplanResource.setPeriod(period);
  if (carePlan.stop != 0L) {
    period.setEnd(new Date(carePlan.stop));
    careplanResource.setStatus(CarePlanStatus.COMPLETED);
    activityStatus = CarePlanActivityStatus.COMPLETED;
    goalStatus = GoalStatus.ACHIEVED;
  } else {
    careplanResource.setStatus(CarePlanStatus.ACTIVE);
    activityStatus = CarePlanActivityStatus.INPROGRESS;
    goalStatus = GoalStatus.INPROGRESS;
  }

  if (!carePlan.activities.isEmpty()) {
    for (Code activity : carePlan.activities) {
      CarePlanActivityComponent activityComponent = new CarePlanActivityComponent();
      CarePlanActivityDetailComponent activityDetailComponent =
          new CarePlanActivityDetailComponent();

      activityDetailComponent.setStatus(activityStatus);

      activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
      activityComponent.setDetail(activityDetailComponent);

      careplanResource.addActivity(activityComponent);
    }
  }

  if (!carePlan.reasons.isEmpty()) {
    // Only one element in list
    Code reason = carePlan.reasons.get(0);
    for (BundleEntryComponent entry : bundle.getEntry()) {
      if (entry.getResource().fhirType().equals("Condition")) {
        Condition condition = (Condition) entry.getResource();
        // Only one element in list
        Coding coding = condition.getCode().getCoding().get(0);
        if (reason.code.equals(coding.getCode())) {
          careplanResource.addAddresses().setReference(entry.getFullUrl());
        }
      }
    }
  }

  for (JsonObject goal : carePlan.goals) {
    BundleEntryComponent goalEntry = caregoal(bundle, goalStatus, goal);
    careplanResource.addGoal().setReference(goalEntry.getFullUrl());
  }

  return newEntry(bundle, careplanResource);
}
 
Example 19
Source File: FHIRSTU3ExporterTest.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Test
public void testSampledDataExport() throws Exception {

  Person person = new Person(0L);
  person.attributes.put(Person.GENDER, "F");
  person.attributes.put(Person.FIRST_LANGUAGE, "spanish");
  person.attributes.put(Person.RACE, "other");
  person.attributes.put(Person.ETHNICITY, "hispanic");
  person.attributes.put(Person.INCOME, Integer.parseInt(Config
      .get("generate.demographics.socioeconomic.income.poverty")) * 2);
  person.attributes.put(Person.OCCUPATION_LEVEL, 1.0);

  person.history = new LinkedList<>();
  Provider mock = Mockito.mock(Provider.class);
  mock.uuid = "Mock-UUID";
  person.setProvider(EncounterType.AMBULATORY, mock);
  person.setProvider(EncounterType.WELLNESS, mock);
  person.setProvider(EncounterType.EMERGENCY, mock);
  person.setProvider(EncounterType.INPATIENT, mock);

  Long time = System.currentTimeMillis();
  long birthTime = time - Utilities.convertTime("years", 35);
  person.attributes.put(Person.BIRTHDATE, birthTime);

  Payer.loadNoInsurance();
  for (int i = 0; i < person.payerHistory.length; i++) {
    person.setPayerAtAge(i, Payer.noInsurance);
  }
  
  Module module = TestHelper.getFixture("observation.json");
  
  State encounter = module.getState("SomeEncounter");
  assertTrue(encounter.process(person, time));
  person.history.add(encounter);
  
  State physiology = module.getState("Simulate_CVS");
  assertTrue(physiology.process(person, time));
  person.history.add(physiology);
  
  State sampleObs = module.getState("SampledDataObservation");
  assertTrue(sampleObs.process(person, time));
  person.history.add(sampleObs);
  
  FhirContext ctx = FhirContext.forDstu3();
  IParser parser = ctx.newJsonParser().setPrettyPrint(true);
  String fhirJson = FhirStu3.convertToFHIRJson(person, System.currentTimeMillis());
  Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
  
  for (BundleEntryComponent entry : bundle.getEntry()) {
    if (entry.getResource() instanceof Observation) {
      Observation obs = (Observation) entry.getResource();
      assertTrue(obs.getValue() instanceof SampledData);
      SampledData data = (SampledData) obs.getValue();
      assertEquals(10, data.getPeriod().doubleValue(), 0.001); // 0.01s == 10ms
      assertEquals(3, (int) data.getDimensions());
    }
  }
}
 
Example 20
Source File: FHIRSTU3ExporterTest.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Test
public void testObservationAttachment() throws Exception {

  Person person = new Person(0L);
  person.attributes.put(Person.GENDER, "F");
  person.attributes.put(Person.FIRST_LANGUAGE, "spanish");
  person.attributes.put(Person.RACE, "other");
  person.attributes.put(Person.ETHNICITY, "hispanic");
  person.attributes.put(Person.INCOME, Integer.parseInt(Config
      .get("generate.demographics.socioeconomic.income.poverty")) * 2);
  person.attributes.put(Person.OCCUPATION_LEVEL, 1.0);
  person.attributes.put("Pulmonary Resistance", 0.1552);
  person.attributes.put("BMI Multiplier", 0.055);
  person.setVitalSign(VitalSign.BMI, 21.0);

  person.history = new LinkedList<>();
  Provider mock = Mockito.mock(Provider.class);
  mock.uuid = "Mock-UUID";
  person.setProvider(EncounterType.AMBULATORY, mock);
  person.setProvider(EncounterType.WELLNESS, mock);
  person.setProvider(EncounterType.EMERGENCY, mock);
  person.setProvider(EncounterType.INPATIENT, mock);

  Long time = System.currentTimeMillis();
  long birthTime = time - Utilities.convertTime("years", 35);
  person.attributes.put(Person.BIRTHDATE, birthTime);

  Payer.loadNoInsurance();
  for (int i = 0; i < person.payerHistory.length; i++) {
    person.setPayerAtAge(i, Payer.noInsurance);
  }
  
  Module module = TestHelper.getFixture("observation.json");
  
  State physiology = module.getState("Simulate_CVS");
  assertTrue(physiology.process(person, time));
  person.history.add(physiology);
  
  State encounter = module.getState("SomeEncounter");
  assertTrue(encounter.process(person, time));
  person.history.add(encounter);
  
  State chartState = module.getState("ChartObservation");
  assertTrue(chartState.process(person, time));
  person.history.add(chartState);
  
  State urlState = module.getState("UrlObservation");
  assertTrue(urlState.process(person, time));
  person.history.add(urlState);
  
  FhirContext ctx = FhirContext.forDstu3();
  IParser parser = ctx.newJsonParser().setPrettyPrint(true);
  String fhirJson = FhirStu3.convertToFHIRJson(person, System.currentTimeMillis());
  Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
  
  for (BundleEntryComponent entry : bundle.getEntry()) {
    if (entry.getResource() instanceof Media) {
      Media media = (Media) entry.getResource();
      if (media.getContent().getData() != null) {
        assertEquals(400, media.getWidth());
        assertEquals(200, media.getHeight());
        assertEquals("Invasive arterial pressure", media.getReasonCode().get(0).getText());
        assertTrue(Base64.isBase64(media.getContent().getDataElement().getValueAsString()));
      } else if (media.getContent().getUrl() != null) {
        assertEquals("https://example.com/image/12498596132", media.getContent().getUrl());
        assertEquals("en-US", media.getContent().getLanguage());
        assertTrue(media.getContent().getSize() > 0);
      } else {
        fail("Invalid Media element in output JSON");
      }
    }
  }
}