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

The following examples show how to use org.hl7.fhir.r4.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: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static boolean isDeprecated(CodeSystem cs, ConceptDefinitionComponent def)  {
  try {
    for (ConceptPropertyComponent p : def.getProperty()) {
      if (p.getCode().equals("status") && p.hasValue() && p.hasValueCodeType() && p.getValueCodeType().getCode().equals("deprecated"))
        return true;
      // this, though status should also be set
      if (p.getCode().equals("deprecationDate") && p.hasValue() && p.getValue() instanceof DateTimeType) 
        return ((DateTimeType) p.getValue()).before(new DateTimeType(Calendar.getInstance()));
      // legacy  
      if (p.getCode().equals("deprecated") && p.hasValue() && p.getValue() instanceof BooleanType) 
        return ((BooleanType) p.getValue()).getValue();
    }
    return false;
  } catch (FHIRException e) {
    return false;
  }
}
 
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: 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 #4
Source File: VersionConvertorPrimitiveType40_50Test.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(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 #5
Source File: VersionConvertorPrimitiveType40_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 #6
Source File: XmlParser.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String convertForDateFormatFromExternal(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 #7
Source File: XmlParser.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String convertForDateFormatToExternal(String fmt, String av) throws FHIRException {
  if ("v3".equals(fmt)) {
    DateTimeType d = new DateTimeType(av);
    return d.getAsV3();
  } else
    throw new FHIRException("Unknown Date format '"+fmt+"'");
}
 
Example #8
Source File: CountryCodesConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void setMetadata(Document src, CodeSystem cs, String id, String url, String partName, String partTitle) {
  cs.setId(id);
  cs.setUrl(url);
  cs.setName("ISOCountryCodes"+partName);
  cs.setTitle("ISO Country Codes (ISO-3166)"+partTitle);
  cs.setVersion(XMLUtil.getFirstChild(src.getDocumentElement()).getAttribute("version"));
  cs.setStatus(PublicationStatus.ACTIVE);
  cs.setExperimental(false);
  cs.addContact().setName("FHIR Project Team").addTelecom().setSystem(ContactPointSystem.URL).setValue("http://hl7.org/fhir");
  cs.setDateElement(new DateTimeType(src.getDocumentElement().getAttribute("generated")));
  cs.setCopyright("Copyright ISO. See https://www.iso.org/obp/ui/#search/code/");
  cs.setCaseSensitive(true);
  cs.setContent(CodeSystemContentMode.COMPLETE);
  cs.setLanguage("en");
}
 
Example #9
Source File: FhirEncodersTest.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Test
public void choiceValue() {

  // Our test condition uses the DateTime choice, so use that type and column.
  Assert.assertEquals(((DateTimeType) condition.getOnset()).getValueAsString(),
      conditionsDataset.select("onsetDateTime").head().get(0));

  Assert.assertEquals(condition.getOnset().toString(),
      decodedCondition.getOnset().toString());
}
 
Example #10
Source File: FhirR4.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 #11
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 {
  setStatus(cs, concept, ConceptStatus.Deprecated);
  defineDeprecatedProperty(cs);
  concept.addProperty().setCode("deprecationDate").setValue(date);    
}
 
Example #12
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 #13
Source File: FhirR4.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("completed");

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

    // as_needed is false
    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());
        }
      }
    }
    if (rxInfo.has("refills")) {
      SimpleQuantity rate = new SimpleQuantity();
      rate.setValue(rxInfo.get("refills").getAsLong());
      dosage.setRate(rate);
    }
    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;
}