org.hl7.fhir.dstu3.model.DateTimeType Java Examples

The following examples show how to use org.hl7.fhir.dstu3.model.DateTimeType. 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 7 votes vote down vote up
private static void addAge(Bundle b, int y, int m, String v) throws FHIRException {
  Observation obs = new Observation();
  obs.setId("obs-example-age-weight-"+Integer.toString(y)+"-"+Integer.toString(m));
  obs.setSubject(new Reference().setReference("Patient/123"));
  obs.setStatus(ObservationStatus.FINAL);
  Calendar when = Calendar.getInstance();
  when.add(Calendar.YEAR, -y);
  when.add(Calendar.MONTH, m);
  obs.setEffective(new DateTimeType(when));
  obs.getCode().addCoding().setCode("29463-7").setSystem("http://loinc.org");
  obs.setValue(new Quantity());
  obs.getValueQuantity().setCode("kg");
  obs.getValueQuantity().setSystem("http://unitsofmeasure.org");
  obs.getValueQuantity().setUnit("kg");
  obs.getValueQuantity().setValue(new BigDecimal(v));
  b.addEntry().setFullUrl("http://hl7.org/fhir/Observation/"+obs.getId()).setResource(obs);
}
 
Example #2
Source File: NUCCConvertor.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public void execute() throws IOException, FHIRException {
  CSVReader csv = new CSVReader(new FileInputStream("c:\\temp\\nucc.csv"));
  CodeSystem cs = new CodeSystem();
  cs.setId("nucc-provider-taxonomy");
  cs.setUrl("http://nucc.org/provider-taxonomy");
  cs.setName("NUCC Provider Taxonomy");
  cs.setDateElement(new DateTimeType());
  cs.setDescription("The Health Care Provider Taxonomy code is a unique alphanumeric code, ten characters in length. The code set is structured into three distinct 'Levels' including Provider Type, Classification, and Area of Specialization");
  cs.setCopyright("See NUCC copyright statement");
  cs.setStatus(PublicationStatus.ACTIVE);
  cs.setContent(CodeSystemContentMode.COMPLETE);
  cs.setExperimental(false);
  cs.setValueSet("http://hl7.org/fhir/ValueSet/nucc-provider-taxonomy"); 
  cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.CLASSIFIEDWITH);
  csv.parseLine();
  while (csv.ready())
  {
    String[] values = csv.parseLine();
    processLine(cs, values);
  }     
  csv.close();
  new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\nucc.xml"), cs);
}
 
Example #3
Source File: ObservationAccessor.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public Optional<LocalDateTime> getEffectiveTime(DomainResource resource){
	org.hl7.fhir.dstu3.model.Observation fhirObservation =
		(org.hl7.fhir.dstu3.model.Observation) resource;
	Type effective = fhirObservation.getEffective();
	if (effective instanceof DateTimeType) {
		return Optional.of(getLocalDateTime(((DateTimeType) effective).getValue()));
	} else if (effective instanceof Period) {
		Date start = ((Period) effective).getStart();
		if (start != null) {
			return Optional.of(getLocalDateTime(start));
		}
		Date end = ((Period) effective).getEnd();
		if (end != null) {
			return Optional.of(getLocalDateTime(end));
		}
	}
	return Optional.empty();
}
 
Example #4
Source File: ConditionAccessor.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public Optional<String> getEnd(DomainResource resource){
	org.hl7.fhir.dstu3.model.Condition fhirCondition =
		(org.hl7.fhir.dstu3.model.Condition) resource;
	try {
		if (fhirCondition.hasAbatementDateTimeType()) {
			DateTimeType dateTime = fhirCondition.getAbatementDateTimeType();
			if (dateTime != null) {
				Date date = dateTime.getValue();
				SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
				return Optional.of(format.format(date));
			}
		} else if (fhirCondition.hasAbatementStringType()) {
			return Optional.of(fhirCondition.getAbatementStringType().getValue());
		}
	} catch (FHIRException e) {
		LoggerFactory.getLogger(ConditionAccessor.class).error("Could not access end.", e);
	}
	return Optional.empty();
}
 
Example #5
Source File: ConditionAccessor.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public Optional<String> getStart(DomainResource resource){
	org.hl7.fhir.dstu3.model.Condition fhirCondition =
		(org.hl7.fhir.dstu3.model.Condition) resource;
	try {
		if (fhirCondition.hasOnsetDateTimeType()) {
			DateTimeType dateTime = fhirCondition.getOnsetDateTimeType();
			if (dateTime != null) {
				Date date = dateTime.getValue();
				SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
				return Optional.of(format.format(date));
			}
		} else if (fhirCondition.hasOnsetStringType()) {
			return Optional.of(fhirCondition.getOnsetStringType().getValue());
		}
	} catch (FHIRException e) {
		LoggerFactory.getLogger(ConditionAccessor.class).error("Could not access start time.",
			e);
	}
	return Optional.empty();
}
 
Example #6
Source File: VersionConvertorPrimitiveType30_50Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static Stream<Arguments> dstu3PrimitiveTypes() {
  return Stream.of(
    Arguments.arguments(BooleanType.class.getSimpleName(), new BooleanType()),
    Arguments.arguments(CodeType.class.getSimpleName(), new CodeType()),
    Arguments.arguments(DateType.class.getSimpleName(), new DateType()),
    Arguments.arguments(DateTimeType.class.getSimpleName(), new DateTimeType()),
    Arguments.arguments(DecimalType.class.getSimpleName(), new DecimalType()),
    Arguments.arguments(InstantType.class.getSimpleName(), new InstantType()),
    Arguments.arguments(PositiveIntType.class.getSimpleName(), new PositiveIntType()),
    Arguments.arguments(UnsignedIntType.class.getSimpleName(), new UnsignedIntType()),
    Arguments.arguments(IntegerType.class.getSimpleName(), new IntegerType()),
    Arguments.arguments(MarkdownType.class.getSimpleName(), new MarkdownType()),
    Arguments.arguments(OidType.class.getSimpleName(), new OidType()),
    Arguments.arguments(StringType.class.getSimpleName(), new StringType()),
    Arguments.arguments(TimeType.class.getSimpleName(), new TimeType()),
    Arguments.arguments(UuidType.class.getSimpleName(), new UuidType()),
    Arguments.arguments(Base64BinaryType.class.getSimpleName(), new Base64BinaryType()),
    Arguments.arguments(UriType.class.getSimpleName(), new UriType()));
}
 
Example #7
Source File: VersionConvertorPrimitiveType30_50Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static Stream<Arguments> r5PrimitiveTypes() {
  return Stream.of(
    Arguments.arguments(org.hl7.fhir.r5.model.BooleanType.class.getSimpleName(), new org.hl7.fhir.r5.model.BooleanType()),
    Arguments.arguments(org.hl7.fhir.r5.model.CodeType.class.getSimpleName(), new org.hl7.fhir.r5.model.CodeType()),
    Arguments.arguments(org.hl7.fhir.r5.model.DateType.class.getSimpleName(), new org.hl7.fhir.r5.model.DateType()),
    Arguments.arguments(org.hl7.fhir.r5.model.DateTimeType.class.getSimpleName(), new org.hl7.fhir.r5.model.DateTimeType()),
    Arguments.arguments(org.hl7.fhir.r5.model.DecimalType.class.getSimpleName(), new org.hl7.fhir.r5.model.DecimalType()),
    Arguments.arguments(org.hl7.fhir.r5.model.InstantType.class.getSimpleName(), new org.hl7.fhir.r5.model.InstantType()),
    Arguments.arguments(org.hl7.fhir.r5.model.PositiveIntType.class.getSimpleName(), new org.hl7.fhir.r5.model.PositiveIntType()),
    Arguments.arguments(org.hl7.fhir.r5.model.UnsignedIntType.class.getSimpleName(), new org.hl7.fhir.r5.model.UnsignedIntType()),
    Arguments.arguments(org.hl7.fhir.r5.model.IntegerType.class.getSimpleName(), new org.hl7.fhir.r5.model.IntegerType()),
    Arguments.arguments(org.hl7.fhir.r5.model.MarkdownType.class.getSimpleName(), new org.hl7.fhir.r5.model.MarkdownType()),
    Arguments.arguments(org.hl7.fhir.r5.model.OidType.class.getSimpleName(), new org.hl7.fhir.r5.model.OidType()),
    Arguments.arguments(org.hl7.fhir.r5.model.StringType.class.getSimpleName(), new org.hl7.fhir.r5.model.StringType()),
    Arguments.arguments(org.hl7.fhir.r5.model.TimeType.class.getSimpleName(), new org.hl7.fhir.r5.model.TimeType()),
    Arguments.arguments(org.hl7.fhir.r5.model.UuidType.class.getSimpleName(), new org.hl7.fhir.r5.model.UuidType()),
    Arguments.arguments(org.hl7.fhir.r5.model.Base64BinaryType.class.getSimpleName(), new org.hl7.fhir.r5.model.Base64BinaryType()),
    Arguments.arguments(org.hl7.fhir.r5.model.UriType.class.getSimpleName(), new org.hl7.fhir.r5.model.UriType()));
}
 
Example #8
Source File: VersionConvertorPrimitiveType30_40Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static Stream<Arguments> dstu3PrimitiveTypes() {
  return Stream.of(
    Arguments.arguments(BooleanType.class.getSimpleName(), new BooleanType()),
    Arguments.arguments(CodeType.class.getSimpleName(), new CodeType()),
    Arguments.arguments(DateType.class.getSimpleName(), new DateType()),
    Arguments.arguments(DateTimeType.class.getSimpleName(), new DateTimeType()),
    Arguments.arguments(DecimalType.class.getSimpleName(), new DecimalType()),
    Arguments.arguments(InstantType.class.getSimpleName(), new InstantType()),
    Arguments.arguments(PositiveIntType.class.getSimpleName(), new PositiveIntType()),
    Arguments.arguments(UnsignedIntType.class.getSimpleName(), new UnsignedIntType()),
    Arguments.arguments(IntegerType.class.getSimpleName(), new IntegerType()),
    Arguments.arguments(MarkdownType.class.getSimpleName(), new MarkdownType()),
    Arguments.arguments(OidType.class.getSimpleName(), new OidType()),
    Arguments.arguments(StringType.class.getSimpleName(), new StringType()),
    Arguments.arguments(TimeType.class.getSimpleName(), new TimeType()),
    Arguments.arguments(UuidType.class.getSimpleName(), new UuidType()),
    Arguments.arguments(Base64BinaryType.class.getSimpleName(), new Base64BinaryType()),
    Arguments.arguments(UriType.class.getSimpleName(), new UriType()));
}
 
Example #9
Source File: VersionConvertorPrimitiveType30_40Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static Stream<Arguments> r4PrimitiveTypes() {
  return Stream.of(
    Arguments.arguments(org.hl7.fhir.r4.model.BooleanType.class.getSimpleName(), new org.hl7.fhir.r4.model.BooleanType()),
    Arguments.arguments(org.hl7.fhir.r4.model.CodeType.class.getSimpleName(), new org.hl7.fhir.r4.model.CodeType()),
    Arguments.arguments(org.hl7.fhir.r4.model.DateType.class.getSimpleName(), new org.hl7.fhir.r4.model.DateType()),
    Arguments.arguments(org.hl7.fhir.r4.model.DateTimeType.class.getSimpleName(), new org.hl7.fhir.r4.model.DateTimeType()),
    Arguments.arguments(org.hl7.fhir.r4.model.DecimalType.class.getSimpleName(), new org.hl7.fhir.r4.model.DecimalType()),
    Arguments.arguments(org.hl7.fhir.r4.model.InstantType.class.getSimpleName(), new org.hl7.fhir.r4.model.InstantType()),
    Arguments.arguments(org.hl7.fhir.r4.model.PositiveIntType.class.getSimpleName(), new org.hl7.fhir.r4.model.PositiveIntType()),
    Arguments.arguments(org.hl7.fhir.r4.model.UnsignedIntType.class.getSimpleName(), new org.hl7.fhir.r4.model.UnsignedIntType()),
    Arguments.arguments(org.hl7.fhir.r4.model.IntegerType.class.getSimpleName(), new org.hl7.fhir.r4.model.IntegerType()),
    Arguments.arguments(org.hl7.fhir.r4.model.MarkdownType.class.getSimpleName(), new org.hl7.fhir.r4.model.MarkdownType()),
    Arguments.arguments(org.hl7.fhir.r4.model.OidType.class.getSimpleName(), new org.hl7.fhir.r4.model.OidType()),
    Arguments.arguments(org.hl7.fhir.r4.model.StringType.class.getSimpleName(), new org.hl7.fhir.r4.model.StringType()),
    Arguments.arguments(org.hl7.fhir.r4.model.TimeType.class.getSimpleName(), new org.hl7.fhir.r4.model.TimeType()),
    Arguments.arguments(org.hl7.fhir.r4.model.UuidType.class.getSimpleName(), new org.hl7.fhir.r4.model.UuidType()),
    Arguments.arguments(org.hl7.fhir.r4.model.Base64BinaryType.class.getSimpleName(), new org.hl7.fhir.r4.model.Base64BinaryType()),
    Arguments.arguments(org.hl7.fhir.r4.model.UriType.class.getSimpleName(), new org.hl7.fhir.r4.model.UriType()));
}
 
Example #10
Source File: LoincToDEConvertor.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public void process() throws FHIRFormatError, IOException, XmlPullParserException, SAXException, ParserConfigurationException {
	log("Begin. Produce Loinc CDEs in "+dest+" from "+definitions);
	loadLoinc();
	log("LOINC loaded");

	now = DateTimeType.now();

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

	processLoincCodes();
	if (dest != null) {
		log("Saving...");
		saveBundle();
	}
	log("Done");

}
 
Example #11
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 #12
Source File: ProcedureRequest.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setScheduledTime(LocalDateTime time){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		org.hl7.fhir.dstu3.model.ProcedureRequest fhirProcedureRequest =
			(org.hl7.fhir.dstu3.model.ProcedureRequest) resource.get();
		fhirProcedureRequest.setOccurrence(new DateTimeType(getDate(time)));
		
		saveResource(resource.get());
	}
}
 
Example #13
Source File: FhirStu3.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the timestamp into a FHIR DateType or DateTimeType.
 *
 * @param datetime Timestamp
 * @param time If true, return a DateTime; if false, return a Date.
 * @return a DateType or DateTimeType representing the given timestamp
 */
private static Type convertFhirDateTime(long datetime, boolean time) {
  Date date = new Date(datetime);

  if (time) {
    return new DateTimeType(date);
  } else {
    return new DateType(date);
  }
}
 
Example #14
Source File: QuestionnaireBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
  ValueSet vs = new ValueSet();
  vs.setName("Type options for "+path);
  vs.setDescription(vs.getName());
 vs.setStatus(PublicationStatus.ACTIVE);
  vs.setExpansion(new ValueSetExpansionComponent());
  vs.getExpansion().setIdentifier(Factory.createUUID());
  vs.getExpansion().setTimestampElement(DateTimeType.now());
  for (TypeRefComponent t : types) {
    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
   if (t.getCode().equals("Reference") && (t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/"))) { 
     cc.setCode(t.getTargetProfile().substring(40));
      cc.setSystem("http://hl7.org/fhir/resource-types");
     cc.setDisplay(cc.getCode());
    } else {
      ProfileUtilities pu = new ProfileUtilities(context, null, null);
      StructureDefinition ps = null;
      if (t.hasTargetProfile()) 
        ps = pu.getProfile(profile, t.getTargetProfile());
      else if (t.hasProfile()) 
        ps = pu.getProfile(profile, t.getProfile());
      
      if (ps != null) {
       cc.setCode(t.getTargetProfile());
        cc.setDisplay(ps.getType());
        cc.setSystem("http://hl7.org/fhir/resource-types");
      } else {
       cc.setCode(t.getCode());
       cc.setDisplay(t.getCode());
        cc.setSystem("http://hl7.org/fhir/data-types");
      }
    }
   t.setUserData("text", cc.getCode());
  }

  return vs;
}
 
Example #15
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean isDeprecated(CodeSystem cs, ConceptDefinitionComponent def) {
  for (ConceptPropertyComponent p : def.getProperty()) {
    if (p.getCode().equals("deprecated") && p.hasValue() && p.getValue() instanceof BooleanType) 
      return ((BooleanType) p.getValue()).getValue();
    if (p.getCode().equals("deprecationDate") && p.hasValue() && p.getValue() instanceof DateTimeType) 
      return ((DateTimeType) p.getValue()).before(new DateTimeType());
  }
  return false;
}
 
Example #16
Source File: XmlParser.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String convertForDateFormat(String fmt, String av) throws FHIRException {
 	if ("v3".equals(fmt)) {
 		DateTimeType d = DateTimeType.parseV3(av);
 		return d.asStringValue();
 	} else
 		throw new FHIRException("Unknown Data format '"+fmt+"'");
}
 
Example #17
Source File: IEEE11073Convertor.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static ConceptMap generateLoincMdcMap(CodeSystem mdc, String dst, String src) throws IOException, FHIRException {
  ConceptMap cm = new ConceptMap();
  cm.setId("loinc-mdc");
  cm.setUrl("http:/???/fhir/ConceptMap/loinc-mdc");
  cm.setVersion("[todo]");
  cm.setName("LoincMdcCrossMap");
  cm.setTitle("Cross Map between LOINC and MDC");
  cm.setStatus(PublicationStatus.DRAFT);
  cm.setExperimental(true);
  cm.setDateElement(new DateTimeType());
  cm.setPublisher("HL7, Inc");
  ContactDetail cd = cm.addContact();
  cd.setName("LOINC + IEEE");
  ContactPoint cp = cd.addTelecom();
  cp.setSystem(ContactPointSystem.URL);
  cp.setValue("http://loinc.org");
  cm.setDescription("A Cross Map between the LOINC and MDC Code systems");
  cm.setPurpose("To implementers map between medical device codes and LOINC codes");
  cm.setCopyright("This content LOINC \u00ae is copyright \u00a9 1995 Regenstrief Institute, Inc. and the LOINC Committee, and available at no cost under the license at http://loinc.org/terms-of-use");
  cm.setSource(new UriType("http://loinc.org/vs"));
  cm.setTarget(new UriType(MDC_ALL_VALUES));
  ConceptMapGroupComponent g = cm.addGroup();
  g.setSource("urn:iso:std:iso:11073:10101");
  g.setTarget("http://loinc.org");

  CSVReader csv = new CSVReader(new FileInputStream(src));
  csv.readHeaders();
  while (csv.line()) {
    SourceElementComponent e = g.addElement();
    e.setCode(csv.cell("IEEE_CF_CODE10"));
    e.setDisplay(csv.cell("IEEE_DESCRIPTION"));
    TargetElementComponent t = e.addTarget();
    t.setEquivalence(ConceptMapEquivalence.EQUIVALENT);
    t.setCode(csv.cell("LOINC_NUM"));
    t.setDisplay(csv.cell("LOINC_LONG_COMMON_NAME"));
  }
  new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dst, "conceptmap-"+cm.getId()+".xml")), cm);
  System.out.println("Done");
  return cm;
}
 
Example #18
Source File: Convert.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public DateTimeType makeDateTimeFromIVL(Element ivl) throws Exception {
 if (ivl == null)
 	return null;
 if (ivl.hasAttribute("value")) 
 	return makeDateTimeFromTS(ivl);
 Element high =  cda.getChild(ivl, "high");
 if (high != null)
 	return makeDateTimeFromTS(high);
 Element low =  cda.getChild(ivl, "low");
 if (low != null)
 	return makeDateTimeFromTS(low);
 return null;
}
 
Example #19
Source File: Convert.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public DateTimeType makeDateTimeFromTS(Element ts) throws Exception {
if (ts == null)
	return null;

  String v = ts.getAttribute("value");
  if (Utilities.noString(v))
  	return null;
  
  if (v.length() > 8 && !hasTimezone(v))
  	v += defaultTimezone;
  DateTimeType d = DateTimeType.parseV3(v);
  return d;
}
 
Example #20
Source File: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static Observation baseVitals(Bundle b, Calendar when, int min, String name, String lCode, String text) throws FHIRFormatError {
  Observation obs = new Observation();
  obs.setId("obs-vitals-"+name+"-"+Integer.toString(min));
  obs.setSubject(new Reference().setReference("Patient/123"));
  obs.setStatus(ObservationStatus.FINAL);
  obs.setEffective(new DateTimeType(when));
  obs.addCategory().setText("Vital Signs").addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("vital-signs").setDisplay("Vital Signs");
  obs.getCode().setText(text).addCoding().setCode(lCode).setSystem("http://loinc.org");
  b.addEntry().setFullUrl("http://hl7.org/fhir/Observation/"+obs.getId()).setResource(obs);
  return obs;
}
 
Example #21
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public static void setDeprecated(CodeSystem cs, ConceptDefinitionComponent concept, DateTimeType date) throws FHIRFormatError {
  defineDeprecatedProperty(cs);
  concept.addProperty().setCode("deprecationDate").setValue(date);    
}
 
Example #22
Source File: LoincToDEConvertor.java    From org.hl7.fhir.core with 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 #23
Source File: TestData.java    From bunsen with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 *
 * @return a FHIR Condition for testing.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example #24
Source File: TestData.java    From bunsen with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example #25
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 #26
Source File: ObservationAccessor.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public void setEffectiveTime(DomainResource resource, LocalDateTime time){
	org.hl7.fhir.dstu3.model.Observation fhirObservation =
		(org.hl7.fhir.dstu3.model.Observation) resource;
	fhirObservation.setEffective(new DateTimeType(getDate(time)));
}