Java Code Examples for org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent

The following examples show how to use org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent. These examples are extracted from open source projects. 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 Project: org.hl7.fhir.core   Author: hapifhir   File: NarrativeGenerator.java    License: 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 #2
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 #3
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper function to create an Entry for the given Resource within the given Bundle.
 * Sets the entry's fullURL to resourceID, and adds the entry to the bundle.
 *
 * @param bundle The Bundle to add the Entry to
 * @param resource Resource the new Entry should contain
 * @param resourceID The Resource ID to assign
 * @return the created Entry
 */
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource,
    String resourceID) {
  BundleEntryComponent entry = bundle.addEntry();

  resource.setId(resourceID);
  if (Boolean.parseBoolean(Config.get("exporter.fhir.bulk_data"))) {
    entry.setFullUrl(resource.fhirType() + "/" + resourceID);
  } else {
    entry.setFullUrl("urn:uuid:" + resourceID);
  }
  entry.setResource(resource);

  if (TRANSACTION_BUNDLE) {
    BundleEntryRequestComponent request = entry.getRequest();
    request.setMethod(HTTPVerb.POST);
    request.setUrl(resource.getResourceType().name());
    entry.setRequest(request);
  }

  return entry;
}
 
Example #4
Source Project: org.hl7.fhir.core   Author: hapifhir   File: CCDAConverter.java    License: Apache License 2.0 5 votes vote down vote up
protected String addReference(DomainResource r, String title, String id) throws Exception {
	if (r.getText() == null)
		r.setText(new Narrative());
	if (r.getText().getDiv() == null) {
		r.getText().setStatus(NarrativeStatus.GENERATED);
		new NarrativeGenerator("", "", context).generate(r);
	}
	r.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
	r.setId(id);
	feed.getEntry().add(new BundleEntryComponent().setResource(r));
	return id;
}
 
Example #5
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #6
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public static BundleEntryComponent getEntryById(Bundle feed, ResourceType type, String reference) {
  for (BundleEntryComponent item : feed.getEntry()) {
    if (item.getResource().getId().equals(reference) && item.getResource().getResourceType() == type)
      return item;
  }
  return null;
}
 
Example #7
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #8
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #9
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #10
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #11
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #12
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #13
Source Project: org.hl7.fhir.core   Author: hapifhir   File: NarrativeGenerator.java    License: 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 #14
Source Project: org.hl7.fhir.core   Author: hapifhir   File: Unbundler.java    License: 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 #15
Source Project: bunsen   Author: cerner   File: Stu3FhirConversionSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<IBaseResource> extractEntryFromBundle(IBaseBundle bundle, String resourceName) {

  Bundle stu3Bundle = (Bundle) bundle;

  List<IBaseResource> items = stu3Bundle.getEntry().stream()
          .map(BundleEntryComponent::getResource)
          .filter(resource ->
              resource != null
                  && resourceName.equalsIgnoreCase(resource.getResourceType().name()))
          .collect(Collectors.toList());

  return items;
}
 
Example #16
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: 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 #17
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: 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 #18
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: 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 #19
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Map the given Media element to a FHIR Media resource, and add it to the given Bundle.
 *
 * @param personEntry    The Entry for the Person
 * @param bundle         Bundle to add the Media to
 * @param encounterEntry Current Encounter entry
 * @param obs   The Observation to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static BundleEntryComponent media(BundleEntryComponent personEntry, Bundle bundle,
    BundleEntryComponent encounterEntry, Observation obs) {
  org.hl7.fhir.dstu3.model.Media mediaResource =
      new org.hl7.fhir.dstu3.model.Media();

  if (obs.codes != null && obs.codes.size() > 0) {
    List<CodeableConcept> reasonList = obs.codes.stream()
        .map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
    mediaResource.setReasonCode(reasonList);
  }
  
  // Hard code as an image
  mediaResource.setType(DigitalMediaType.PHOTO);
  mediaResource.setSubject(new Reference(personEntry.getFullUrl()));

  Attachment content = (Attachment) obs.value;
  org.hl7.fhir.dstu3.model.Attachment contentResource = new org.hl7.fhir.dstu3.model.Attachment();
  
  contentResource.setContentType(content.contentType);
  contentResource.setLanguage(content.language);
  if (content.data != null) {
    contentResource.setDataElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.data));
  }
  contentResource.setUrl(content.url);
  contentResource.setSize(content.size);
  contentResource.setTitle(content.title);
  if (content.hash != null) {
    contentResource.setHashElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.hash));
  }
  
  mediaResource.setWidth(content.width);
  mediaResource.setHeight(content.height);
  
  mediaResource.setContent(contentResource);

  return newEntry(bundle, mediaResource);
}
 
Example #20
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle.
 *
 * @param personEntry    The Person entry.
 * @param bundle         Bundle to add to.
 * @param supply         The supplied object to add.
 * @param encounter      The encounter during which the supplies were delivered
 * @return The added Entry.
 */
private static BundleEntryComponent supplyDelivery(BundleEntryComponent personEntry, 
        Bundle bundle, HealthRecord.Supply supply, Encounter encounter) {
 
  SupplyDelivery supplyResource = new SupplyDelivery();
  supplyResource.setStatus(SupplyDeliveryStatus.COMPLETED);
  supplyResource.setPatient(new Reference(personEntry.getFullUrl()));
  
  CodeableConcept type = new CodeableConcept();
  type.addCoding()
    .setCode("device")
    .setDisplay("Device")
    .setSystem("http://hl7.org/fhir/supply-item-type");
  supplyResource.setType(type);
  
  SupplyDeliverySuppliedItemComponent suppliedItem = new SupplyDeliverySuppliedItemComponent();
  suppliedItem.setItem(mapCodeToCodeableConcept(supply.codes.get(0), SNOMED_URI));
  
  SimpleQuantity quantity = new SimpleQuantity();
  quantity.setValue(supply.quantity);
  suppliedItem.setQuantity(quantity);
  
  supplyResource.setSuppliedItem(suppliedItem);
  
  supplyResource.setOccurrence(convertFhirDateTime(supply.start, true));
  
  return newEntry(bundle, supplyResource);
}
 
Example #21
Source Project: synthea   Author: synthetichealth   File: FhirStu3.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Map the clinician into a FHIR Practitioner resource, and add it to the given Bundle.
 * @param bundle The Bundle to add to
 * @param clinician The clinician
 * @return The added Entry
 */
protected static BundleEntryComponent practitioner(Bundle bundle, Clinician clinician) {
  Practitioner practitionerResource = new Practitioner();

  practitionerResource.addIdentifier().setSystem("http://hl7.org/fhir/sid/us-npi")
  .setValue("" + clinician.identifier);
  practitionerResource.setActive(true);
  practitionerResource.addName().setFamily(
      (String) clinician.attributes.get(Clinician.LAST_NAME))
    .addGiven((String) clinician.attributes.get(Clinician.FIRST_NAME))
    .addPrefix((String) clinician.attributes.get(Clinician.NAME_PREFIX));

  Address address = new Address()
      .addLine((String) clinician.attributes.get(Clinician.ADDRESS))
      .setCity((String) clinician.attributes.get(Clinician.CITY))
      .setPostalCode((String) clinician.attributes.get(Clinician.ZIP))
      .setState((String) clinician.attributes.get(Clinician.STATE));
  if (COUNTRY_CODE != null) {
    address.setCountry(COUNTRY_CODE);
  }
  practitionerResource.addAddress(address);

  if (clinician.attributes.get(Person.GENDER).equals("M")) {
    practitionerResource.setGender(AdministrativeGender.MALE);
  } else if (clinician.attributes.get(Person.GENDER).equals("F")) {
    practitionerResource.setGender(AdministrativeGender.FEMALE);
  }

  return newEntry(bundle, practitionerResource, clinician.getResourceID());
}
 
Example #22
Source Project: synthea   Author: synthetichealth   File: HospitalExporterStu3.java    License: 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 #23
Source Project: cqf-ruler   Author: DBCG   File: Dstu3ApelonFhirTerminologyProvider.java    License: Apache License 2.0 5 votes vote down vote up
public String resolveByIdentifier(ValueSetInfo valueSet) {
    String valueSetId = valueSet.getId();

    // Turns out we got a FHIR url. Let's use that.
    if (valueSetId.startsWith("http")) {
        return valueSetId;
    }
    
    valueSetId = valueSetId.replace("urn:oid:", "");

    IQuery<Bundle> bundleQuery = this.getFhirClient()
        .search()
        .byUrl("ValueSet?identifier=" + valueSetId)
        .returnBundle(Bundle.class)
        .accept("application/fhir+xml");
        
    Bundle searchResults = bundleQuery.execute();

    if (searchResults.hasEntry()) {
        for (BundleEntryComponent bec : searchResults.getEntry()) {
            if (bec.hasResource()) {
                String id = bec.getResource().getIdElement().getIdPart();
                if (id.equals(valueSetId)) {
                    return ((ValueSet)bec.getResource()).getUrl();
                }
            }

        }
    }

    return null;
}
 
Example #24
Source Project: org.hl7.fhir.core   Author: hapifhir   File: IGPackConverter102.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean ignoreEntry(BundleEntryComponent src) {
  return false;
}
 
Example #25
Source Project: org.hl7.fhir.core   Author: hapifhir   File: R2ToR3Loader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean ignoreEntry(BundleEntryComponent src) {
  return false;
}
 
Example #26
Source Project: org.hl7.fhir.core   Author: hapifhir   File: LoincToDEConvertor.java    License: Apache License 2.0 4 votes vote down vote up
private void processLoincCodes() {
	Element row = XMLUtil.getFirstChild(xml.getDocumentElement());
	int i = 0;
	while (row != null) {
		i++;
		if (i % 1000 == 0)
			System.out.print(".");
			String code = col(row, "LOINC_NUM");
			String comp = col(row, "COMPONENT");
			DataElement de = new DataElement();
			de.setId("loinc-"+code);
	    de.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
			bundle.getEntry().add(new BundleEntryComponent().setResource(de));
			Identifier id = new Identifier();
			id.setSystem("http://hl7.org/fhir/commondataelement/loinc");
			id.setValue(code);
			de.addIdentifier(id);
			de.setPublisher("Regenstrief + FHIR Project Team");
			if (!col(row, "STATUS").equals("ACTIVE"))
 				de.setStatus(PublicationStatus.DRAFT); // till we get good at this
			else
				de.setStatus(PublicationStatus.RETIRED);
			de.setDateElement(DateTimeType.now());
			de.setName(comp);
			ElementDefinition dee = de.addElement();

			// PROPERTY	ignore
			// TIME_ASPCT	
			// SYSTEM	
			// SCALE_TYP	
			// METHOD_TYP	
			// dee.getCategory().add(new CodeableConcept().setText(col(row, "CLASS")));
			// SOURCE	
			// DATE_LAST_CHANGED - should be in ?	
			// CHNG_TYPE	
			dee.setComment(col(row , "COMMENTS"));
			if (hasCol(row, "CONSUMER_NAME"))
				dee.addAlias(col(row, "CONSUMER_NAME"));	
			// MOLAR_MASS	
			// CLASSTYPE	
			// FORMULA	
			// SPECIES	
			// EXMPL_ANSWERS	
			// ACSSYM	
			// BASE_NAME - ? this is a relationship	
			// NAACCR_ID	
			// ---------- CODE_TABLE todo	
			// SURVEY_QUEST_TEXT	
			// SURVEY_QUEST_SRC	
			if (hasCol(row, "RELATEDNAMES2")) {
        String n = col(row, "RELATEDNAMES2");
        for (String s : n.split("\\;")) {
					if (!Utilities.noString(s))
						dee.addAlias(s);	
        }
			}
			dee.addAlias(col(row, "SHORTNAME"));	
			// ORDER_OBS	
			// CDISC Code	
			// HL7_FIELD_SUBFIELD_ID	
			//  ------------------ EXTERNAL_COPYRIGHT_NOTICE todo	
			dee.setDefinition(col(row, "LONG_COMMON_NAME"));	
			// HL7_V2_DATATYPE	
			String cc = makeType(col(row, "HL7_V3_DATATYPE"), code);
			if (cc != null)
			  dee.addType().setCode(cc);	
			// todo... CURATED_RANGE_AND_UNITS	
			// todo: DOCUMENT_SECTION	
			// STATUS_REASON	
			// STATUS_TEXT	
			// CHANGE_REASON_PUBLIC	
			// COMMON_TEST_RANK	
			// COMMON_ORDER_RANK	
			// COMMON_SI_TEST_RANK	
			// HL7_ATTACHMENT_STRUCTURE

			// units:
			// UNITSREQUIRED	
			// SUBMITTED_UNITS
			ToolingExtensions.setAllowableUnits(dee, makeUnits(col(row, "EXAMPLE_UNITS"), col(row, "EXAMPLE_UCUM_UNITS")));
			// EXAMPLE_SI_UCUM_UNITS	
		
		row = XMLUtil.getNextSibling(row);
	}
	System.out.println("done");
}
 
Example #27
Source Project: org.hl7.fhir.core   Author: hapifhir   File: BatchLoader.java    License: 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 #28
Source Project: org.hl7.fhir.core   Author: hapifhir   File: ResourceUtilities.java    License: 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 #29
Source Project: org.hl7.fhir.core   Author: hapifhir   File: GraphQLEngine.java    License: Apache License 2.0 4 votes vote down vote up
SearchEdge(String type, BundleEntryComponent be) {
  this.type = type;
  this.be = be;
}
 
Example #30
Source Project: org.hl7.fhir.core   Author: hapifhir   File: GraphQLEngine.java    License: Apache License 2.0 4 votes vote down vote up
private List<Base> getEdges() {
  List<Base> list = new ArrayList<>();
  for (BundleEntryComponent be : bnd.getEntry())
    list.add(new SearchEdge(type.substring(0, type.length() - 10) + "Edge", be));
  return list;
}