Search in sources :

Example 21 with Time

use of org.hl7.elm.r1.Time in project hl7v2-fhir-converter by LinuxForHealth.

the class JvmTimeZoneIdTest method testEmptyDefaultTimeZoneYieldsJVMZoneId.

@Test
void testEmptyDefaultTimeZoneYieldsJVMZoneId() throws IOException {
    // Create our own properties file
    File configFile = new File(folder, "config.properties");
    writeSimpleProperties(configFile);
    System.setProperty(CONF_PROP_HOME, configFile.getParent());
    ConverterConfiguration.reset();
    // Prove that we're using our custom properties file with no ZoneId
    ConverterConfiguration theConvConfig = ConverterConfiguration.getInstance();
    // Four messages supported.  (Proves we're using our created file, not the default.)
    assertThat(theConvConfig.getSupportedMessageTemplates()).hasSize(13);
    // Purposely empty
    assertThat(theConvConfig.getZoneId()).isNull();
    // IMPORTANT: TimeZoneId's are different than an offset.  TimeZoneId's are a location.
    // The offset of the location changes depending on whether Daylight savings time is in effect.
    // Because we compare after processing, we can't compare locations, only offsets.
    // It is critical that when we compare offsets, we start with the same date, so the same daylight savings rules apply!
    // Otherwise a test might work only half of the year.
    // Calculate the local server zone offset
    // 20020202020000
    LocalDateTime localDateTime = LocalDateTime.of(2002, Month.FEBRUARY, 2, 2, 0, 0);
    String defaultLocalZone = TimeZone.getDefault().getID();
    ZoneId localZoneId = ZoneId.of(defaultLocalZone);
    ZonedDateTime localZonedDateTime = localDateTime.atZone(localZoneId);
    ZoneOffset localOffset = localZonedDateTime.getOffset();
    // PART 1
    // Test the format utility (which will fallback to local server time and zone offset)
    String testDateTime = DateUtil.formatToDateTimeWithDefaultZone("20020202020000");
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    ZonedDateTime testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
    ZoneOffset testOffset = testZonedDateTime.getOffset();
    // Offset from our function call test should equal offset of the local time
    assertThat(testOffset).isEqualTo(localOffset);
    // PART 2
    // Do the same for a date going through the entire conversion
    String hl7message = "MSH|^~\\&|||||20020202020000|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.2 to recordedDateTime (check time ZoneId)
    "PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956||||||||||||\r";
    ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
    // Find the condition from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    Condition condition = (Condition) conditionResource.get(0);
    // Get the recordedDate value; convert it back to a zoned time; get the offset for comparison
    // PRB.2
    testDateTime = condition.getRecordedDateElement().getValueAsString();
    testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
    testOffset = testZonedDateTime.getOffset();
    // Offset from our test should equal offset of the local time
    assertThat(testOffset).isEqualTo(localOffset);
// After the test, the properties file resets.
}
Also used : LocalDateTime(java.time.LocalDateTime) Condition(org.hl7.fhir.r4.model.Condition) ZoneId(java.time.ZoneId) ConverterOptions(io.github.linuxforhealth.hl7.ConverterOptions) Builder(io.github.linuxforhealth.hl7.ConverterOptions.Builder) Resource(org.hl7.fhir.r4.model.Resource) ConverterConfiguration(io.github.linuxforhealth.core.config.ConverterConfiguration) ZoneOffset(java.time.ZoneOffset) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ZonedDateTime(java.time.ZonedDateTime) File(java.io.File) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.jupiter.api.Test)

Example 22 with Time

use of org.hl7.elm.r1.Time in project cqf-ruler by DBCG.

the class JpaTerminologyProvider method expand.

@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
    // This could possibly be refactored into a single call to the underlying HAPI
    // Terminology service. Need to think through that..,
    IBaseResource vs;
    if (hasUrlId(valueSet)) {
        if (hasVersion(valueSet) || hasVersionedCodeSystem(valueSet)) {
            throw new UnsupportedOperationException(String.format("Could not expand value set %s; version and code system bindings are not supported at this time.", valueSet.getId()));
        }
        IBundleProvider bundleProvider = search(getClass("ValueSet"), Searches.byUrl(valueSet.getId()), myRequestDetails);
        List<IBaseResource> valueSets = bundleProvider.getAllResources();
        if (valueSets.isEmpty()) {
            throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
        } else if (valueSets.size() == 1) {
            vs = valueSets.get(0);
        } else {
            throw new IllegalArgumentException("Found more than 1 ValueSet with url: " + valueSet.getId());
        }
    } else {
        vs = read(Ids.newId(this.myTerminologySvc.getFhirContext(), "ValueSet", valueSet.getId()), myRequestDetails);
        if (vs == null) {
            throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSet.getId()));
        }
    }
    // relies heavily on reflection.
    switch(vs.getStructureFhirVersionEnum()) {
        case DSTU3:
            return getCodes((org.hl7.fhir.dstu3.model.ValueSet) vs);
        case R4:
            return getCodes((org.hl7.fhir.r4.model.ValueSet) vs);
        case R5:
            return getCodes((org.hl7.fhir.r5.model.ValueSet) vs);
        default:
            throw new IllegalArgumentException(String.format("expand does not support FHIR version %s", vs.getStructureFhirVersionEnum().getFhirVersionString()));
    }
}
Also used : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 23 with Time

use of org.hl7.elm.r1.Time in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testTime.

@Test
public void testTime() {
    String timeString = "00:10:00.000";
    Time expected = new Time(timeString);
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(expected);
    assertTrue(fhirTypeValue instanceof TimeType);
    assertEquals(timeString, ((TimeType) fhirTypeValue).getValueAsString());
}
Also used : IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) LocalDateTime(java.time.LocalDateTime) Time(org.opencds.cqf.cql.engine.runtime.Time) OffsetDateTime(java.time.OffsetDateTime) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) Test(org.junit.Test)

Example 24 with Time

use of org.hl7.elm.r1.Time in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testTime__shouldReturnTimeParameter.

@Test
public void testTime__shouldReturnTimeParameter() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("time");
    String timeString = "12:30:00";
    TimeType fhirValue = new TimeType(timeString);
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    assertEquals(new TimeParameter(timeString), R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
Also used : TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) Test(org.junit.Test)

Example 25 with Time

use of org.hl7.elm.r1.Time in project summary-care-record-api by NHSDigital.

the class DiagnosisMapper method mapAuthor.

private void mapAuthor(List<Resource> resources, Encounter encounter, Node author) {
    DateTimeType time = parseDate(xmlUtils.getValueByXPath(author, DIAGNOSIS_PARTICIPANT_TIME_XPATH), DateTimeType.class);
    participantMapper.map(author).stream().peek(it -> resources.add(it)).filter(it -> it instanceof PractitionerRole).forEach(it -> encounter.addParticipant(new EncounterParticipantComponent().setPeriod(new Period().setStartElement(time)).addType(getParticipationType("AUT", "author")).setIndividual(new Reference(it))));
}
Also used : SneakyThrows(lombok.SneakyThrows) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Encounter(org.hl7.fhir.r4.model.Encounter) Node(org.w3c.dom.Node) CodedEntryMapper(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntryMapper) Observation(org.hl7.fhir.r4.model.Observation) NodeList(org.w3c.dom.NodeList) Period(org.hl7.fhir.r4.model.Period) Resource(org.hl7.fhir.r4.model.Resource) FINISHED(org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Component(org.springframework.stereotype.Component) List(java.util.List) XmlToFhirMapper.parseDate(uk.nhs.adaptors.scr.mappings.from.hl7.XmlToFhirMapper.parseDate) Coding(org.hl7.fhir.r4.model.Coding) FhirHelper.randomUUID(uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID) Optional(java.util.Optional) XmlUtils(uk.nhs.adaptors.scr.utils.XmlUtils) Annotation(org.hl7.fhir.r4.model.Annotation) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Reference(org.hl7.fhir.r4.model.Reference) Period(org.hl7.fhir.r4.model.Period) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole)

Aggregations

Time (com.android.calendarcommon2.Time)178 ArrayList (java.util.ArrayList)64 List (java.util.List)40 Timer (com.codahale.metrics.Timer)27 Trace (com.newrelic.api.agent.Trace)23 Date (java.util.Date)23 Test (org.junit.jupiter.api.Test)23 IOException (java.io.IOException)21 FHIRException (org.hl7.fhir.exceptions.FHIRException)21 Paint (android.graphics.Paint)20 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)19 Resource (org.hl7.fhir.r4.model.Resource)19 BadCodeMonkeyException (gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException)18 Condition (org.hl7.fhir.r4.model.Condition)16 Optional (java.util.Optional)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)15 Bundle (org.hl7.fhir.r4.model.Bundle)15 Coding (org.hl7.fhir.r4.model.Coding)15 Reference (org.hl7.fhir.r4.model.Reference)15 HashMap (java.util.HashMap)14