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

The following examples show how to use org.hl7.fhir.dstu3.model.Bundle#setType() . 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: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private static void buildVitalSignsSet() throws FileNotFoundException, IOException, FHIRFormatError {
  Calendar base = Calendar.getInstance();
  base.add(Calendar.DAY_OF_MONTH, -1);
  Bundle b = new Bundle();
  b.setType(BundleType.COLLECTION);
  b.setId(UUID.randomUUID().toString().toLowerCase());
  
  vitals(b, base, 0, 80, 120, 95, 37.1);
  vitals(b, base, 35, 85, 140, 98, 36.9);
  vitals(b, base, 53, 75, 110, 96, 36.2);
  vitals(b, base, 59, 65, 100, 94, 35.5);
  vitals(b, base, 104, 60, 90, 90, 35.9);
  vitals(b, base, 109, 65, 100, 92, 36.5);
  vitals(b, base, 114, 70, 130, 94, 37.5);
  vitals(b, base, 120, 90, 150, 97, 37.3);
  vitals(b, base, 130, 95, 133, 97, 37.2);
  vitals(b, base, 150, 85, 125, 98, 37.1);
  
  new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\vitals.xml"), b);
}
 
Example 2
Source File: LoincToDEConvertor.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public Bundle process(String sourceFile) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
  this.definitions = sourceFile;
  log("Begin. Produce Loinc CDEs in "+dest+" from "+definitions);
  loadLoinc();
  log("LOINC loaded");

  now = DateTimeType.now();

  bundle = new Bundle();
  bundle.setType(BundleType.COLLECTION);
  bundle.setId("http://hl7.org/fhir/commondataelement/loinc");
  bundle.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));

  processLoincCodes();
  return bundle;
}
 
Example 3
Source File: HospitalExporterStu3.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Export the hospital in FHIR STU3 format.
 */
public static void export(long stop) {
  if (Boolean.parseBoolean(Config.get("exporter.hospital.fhir_stu3.export"))) {

    Bundle bundle = new Bundle();
    if (Boolean.parseBoolean(Config.get("exporter.fhir.transaction_bundle"))) {
      bundle.setType(BundleType.TRANSACTION);
    } else {
      bundle.setType(BundleType.COLLECTION);
    }
    for (Provider h : Provider.getProviderList()) {
      // filter - exports only those hospitals in use
      Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
      int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream()
          .mapToInt(ai -> ai.get()).sum();
      if (totalEncounters > 0) {
        BundleEntryComponent entry = FhirStu3.provider(bundle, h);
        addHospitalExtensions(h, (Organization) entry.getResource());
      }
    }

    String bundleJson = FHIR_CTX.newJsonParser().setPrettyPrint(true)
        .encodeResourceToString(bundle);

    // get output folder
    List<String> folders = new ArrayList<>();
    folders.add("fhir_stu3");
    String baseDirectory = Config.get("exporter.baseDirectory");
    File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
    f.mkdirs();
    Path outFilePath = f.toPath().resolve("hospitalInformation" + stop + ".json");

    try {
      Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
 
Example 4
Source File: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
/**
*     

* @throws FHIRException
* @throws IOException
* @throws FileNotFoundException
*/
 public static void buildStatsSeries() throws FHIRException, IOException, FileNotFoundException {
   Bundle b = new Bundle();
   b.setType(BundleType.COLLECTION);
   b.setId(UUID.randomUUID().toString().toLowerCase());

   addAge(b, 5, 1, "18.3");
   addAge(b, 5, 2, "18.4");
   addAge(b, 5, 3, "18.6");
   addAge(b, 5, 4, "18.8");
   addAge(b, 5, 5, "19.0");
   addAge(b, 5, 6, "19.1");
   addAge(b, 5, 7, "19.3");
   addAge(b, 5, 8, "19.5");
   addAge(b, 5, 9, "19.6");
   addAge(b, 5,10, "19.8");
   addAge(b, 5,11, "20.0");
   addAge(b, 6, 0, "20.2");
   addAge(b, 6, 1, "20.3");
   addAge(b, 6, 2, "20.5");
   addAge(b, 6, 3, "20.7");
   addAge(b, 6, 4, "20.9");
   addAge(b, 6, 5, "21.0");
   addAge(b, 6, 6, "21.2");
   addAge(b, 6, 7, "21.4");
   addAge(b, 6, 8, "21.6");
   addAge(b, 6, 9, "21.8");
   addAge(b, 6,10, "22.0");
   addAge(b, 6,11, "22.2");
   addAge(b, 7, 0, "22.4");
   addAge(b, 7, 1, "22.6");
   addAge(b, 7, 2, "22.8");
   addAge(b, 7, 3, "23.0");
   addAge(b, 7, 4, "23.2");
   addAge(b, 7, 5, "23.4");
   addAge(b, 7, 6, "23.6");
   addAge(b, 7, 7, "23.9");
   addAge(b, 7, 8, "24.1");
   addAge(b, 7, 9, "24.3");
   addAge(b, 7,10, "24.5");
   addAge(b, 7,11, "24.8");
   addAge(b, 8, 0, "25.0");
   addAge(b, 8, 1, "25.3");
   addAge(b, 8, 2, "25.5");
   addAge(b, 8, 3, "25.8");
   addAge(b, 8, 4, "26.0");
   addAge(b, 8, 5, "26.3");
   addAge(b, 8, 6, "26.6");
   addAge(b, 8, 7, "26.8");
   addAge(b, 8, 8, "27.1");
   addAge(b, 8, 9, "27.4");
   addAge(b, 8,10, "27.6");
   addAge(b, 8,11, "27.9");
   addAge(b, 9, 0, "28.2");
   addAge(b, 9, 1, "28.5");
   addAge(b, 9, 2, "28.8");
   addAge(b, 9, 3, "29.1");
   addAge(b, 9, 4, "29.4");
   addAge(b, 9, 5, "29.7");
   addAge(b, 9, 6, "30.0");
   addAge(b, 9, 7, "30.3");
   addAge(b, 9, 8, "30.6");
   addAge(b, 9, 9, "30.9");
   addAge(b, 9, 10, "31.2");
   addAge(b, 9, 11, "31.5");
   addAge(b, 10, 0, "31.9");

 
   new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\obs.xml"), b);
 }
 
Example 5
Source File: BatchLoader.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException {
  long ms = System.currentTimeMillis();
  System.out.print("Loading "+f.getName()+".. ");
  IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser();
  Resource res = parser.parse(new FileInputStream(f));
  System.out.println("  done: ("+Long.toString(System.currentTimeMillis()-ms)+" ms)");
  
  if (res instanceof Bundle) {
    Bundle bnd = (Bundle) res;
    int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0;
    while (cursor < bnd.getEntry().size()) {
      Bundle bt = new Bundle();
      bt.setType(BundleType.BATCH);     
      bt.setId(UUID.randomUUID().toString().toLowerCase());
      for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor+size); i++) {
        if (i >=0 && i < bnd.getEntry().size()) {
          BundleEntryComponent be = bt.addEntry();
          be.setResource(bnd.getEntry().get(i).getResource());
          be.getRequest().setMethod(HTTPVerb.PUT);
          be.getRequest().setUrl(be.getResource().getResourceType().toString()+"/"+be.getResource().getId());
        }
      }
      System.out.print(f.getName()+" ("+cursor+"/"+bnd.getEntry().size()+"): ");
      ms = System.currentTimeMillis();
      Bundle resp = client.transaction(bt);

      int ncursor = cursor+size;
      for (int i = 0; i < resp.getEntry().size(); i++) {
        BundleEntryComponent t = resp.getEntry().get(i);
        if (!t.getResponse().getStatus().startsWith("2")) { 
          System.out.println("failed status at "+Integer.toString(i)+": "+t.getResponse().getStatus());
          ncursor = cursor+i-1;
          break;
        }
      }
      cursor = ncursor;
      System.out.println("  .. done: ("+Long.toString(System.currentTimeMillis()-ms)+" ms) "+SimpleDateFormat.getInstance().format(new Date()));
      ini.setIntegerProperty("progress", f.getName(), cursor, null);
      ini.save();
    }
    ini.setBooleanProperty("finished", f.getName(), true, null);
    ini.save();
  } else {
    client.update(res);
    ini.setBooleanProperty("finished", f.getName(), true, null);
    ini.save();
  }    
}
 
Example 6
Source File: FhirStu3.java    From synthea with Apache License 2.0 4 votes vote down vote up
/**
 * Convert the given Person into a FHIR Bundle, containing the Patient and the
 * associated entries from their health record.
 *
 * @param person Person to generate the FHIR from
 * @param stopTime Time the simulation ended
 * @return FHIR Bundle containing the Person's health record.
 */
public static Bundle convertToFHIR(Person person, long stopTime) {
  Bundle bundle = new Bundle();
  if (TRANSACTION_BUNDLE) {
    bundle.setType(BundleType.TRANSACTION);
  } else {
    bundle.setType(BundleType.COLLECTION);
  }

  BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);

  for (Encounter encounter : person.record.encounters) {
    BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);

    for (HealthRecord.Entry condition : encounter.conditions) {
      condition(personEntry, bundle, encounterEntry, condition);
    }

    for (HealthRecord.Entry allergy : encounter.allergies) {
      allergy(personEntry, bundle, encounterEntry, allergy);
    }

    for (Observation observation : encounter.observations) {
      // If the Observation contains an attachment, use a Media resource, since
      // Observation resources in stu3 don't support Attachments
      if (observation.value instanceof Attachment) {
        media(personEntry, bundle, encounterEntry, observation);
      } else {
        observation(personEntry, bundle, encounterEntry, observation);
      }
    }

    for (Procedure procedure : encounter.procedures) {
      procedure(personEntry, bundle, encounterEntry, procedure);
    }

    for (Medication medication : encounter.medications) {
      medication(personEntry, bundle, encounterEntry, medication);
    }

    for (HealthRecord.Entry immunization : encounter.immunizations) {
      immunization(personEntry, bundle, encounterEntry, immunization);
    }

    for (Report report : encounter.reports) {
      report(personEntry, bundle, encounterEntry, report);
    }

    for (CarePlan careplan : encounter.careplans) {
      careplan(personEntry, bundle, encounterEntry, careplan);
    }

    for (ImagingStudy imagingStudy : encounter.imagingStudies) {
      imagingStudy(personEntry, bundle, encounterEntry, imagingStudy);
    }

    for (HealthRecord.Device device : encounter.devices) {
      device(personEntry, bundle, device);
    }
    
    for (HealthRecord.Supply supply : encounter.supplies) {
      supplyDelivery(personEntry, bundle, supply, encounter);
    }
    
    // one claim per encounter
    BundleEntryComponent encounterClaim = encounterClaim(personEntry, bundle,
        encounterEntry, encounter.claim);

    explanationOfBenefit(personEntry,bundle,encounterEntry,person,
        encounterClaim, encounter);
  }
  return bundle;
}