Search in sources :

Example 16 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project eCRNow by drajer-health.

the class CdaFhirUtilities method getActualDate.

public static Pair<Date, TimeZone> getActualDate(Type dt) {
    Date d = null;
    TimeZone t = null;
    if (dt instanceof DateTimeType) {
        DateTimeType d1 = (DateTimeType) dt;
        d = d1.getValue();
        t = d1.getTimeZone();
    } else if (dt instanceof Period) {
        logger.debug("Found an instance of period");
        Period d1 = (Period) dt;
        if (d1.getStartElement() != null) {
            d = d1.getStart();
            t = d1.getStartElement().getTimeZone();
        } else if (d1.getEndElement() != null) {
            d = d1.getEnd();
            t = d1.getEndElement().getTimeZone();
        }
    } else if (dt instanceof InstantType) {
        InstantType d1 = (InstantType) dt;
        d = d1.getValue();
        t = d1.getTimeZone();
    } else if (dt instanceof Timing) {
        logger.debug(" Found an instance of timing ");
        Timing tmg = (Timing) (dt);
        if (tmg.getRepeat() != null && tmg.getRepeat().getBounds() != null) {
            logger.debug(" Found the bounds element ");
            return getActualDate(tmg.getRepeat().getBounds());
        }
    }
    return new Pair<>(d, t);
}
Also used : TimeZone(java.util.TimeZone) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Period(org.hl7.fhir.r4.model.Period) Timing(org.hl7.fhir.r4.model.Timing) InstantType(org.hl7.fhir.r4.model.InstantType) Date(java.util.Date) Pair(org.javatuples.Pair)

Example 17 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project nia-patient-switching-standard-adaptor by NHSDigital.

the class ObservationUtilTest method mapIssuedUsingEhrComposition.

@Test
public void mapIssuedUsingEhrComposition() {
    var ehrExtract = unmarshallEhrExtractElement("issued_using_ehr_composition_observation_example.xml");
    var ehrComposition = getEhrCompositionFromEhrExtract(ehrExtract);
    InstantType issued = ObservationUtil.getIssued(ehrExtract, ehrComposition);
    assertThat(issued.asStringValue()).isEqualTo(ISSUED_EHR_COMPOSITION_EXAMPLE);
}
Also used : InstantType(org.hl7.fhir.dstu3.model.InstantType) Test(org.junit.jupiter.api.Test)

Example 18 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7OrderRequestFHIRConversionTest method testBroadORCPlusOBRFields.

// This test is a companion to testBroadORCFields.   ORC and OBR records often have repeated data; one taking priority over the other.
// Read comments carefully.  This sometimes tests the secondary value and may be the opposite to the tests in testBroadORCFields.
@Test
// Suppress warnings about too many assertions in a test.  Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
void testBroadORCPlusOBRFields() {
    String hl7message = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + // PID.18 is used as backup identifier visit number because PV1.19 is empty
    "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||665544||||||||||||\n" + // PV1.19 is empty and not used as visit number identifier
    "PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // 7. ORC.16 is set to a reason code (but it is ignored because it is secondary to OBR.31, which is present in this case and therefore overrides ORC.16)
    "ORC|RE|248648498^|248648498^|||||||||||||042^Human immunodeficiency virus [HIV] disease [42]^I9CDX^^^^29|||||||||||||||\n" + // 14. OBR.6 creates ServiceRequest.authoredOn
    "OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C||20120606120606|20170707150707||||L|||||54321678^SCHMIDT^FRIEDA^^MD^^^^NPI^D^^^NPI||||||20180924152900|||F||||||HIV^HIV/Aids^L^^^^V1|323232&Mahoney&Paul&J||||||||||||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> serviceRequestList = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    // Important that we have exactly one service request (no duplication).  OBR creates it as a reference.
    assertThat(serviceRequestList).hasSize(1);
    ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequestList.get(0), context);
    assertThat(serviceRequest.hasStatus()).isTrue();
    assertThat(serviceRequest.hasIdentifier()).isTrue();
    assertThat(serviceRequest.getIdentifier()).hasSize(3);
    // Identifier 1: visit number should be set by in this test by secondary PID.18
    // ORU_RO1 records do not create the ServiceRequest directly.  They create a DiagnosticReport and it creates the ServiceRequest.
    // This makes sure the specification for ORU_RO1.DiagnosticReport is specifying PID correctly in AdditionalSegments.
    // Extensive testing of identifiers is done in Hl7IdentifierFHIRConversionTest.java
    Identifier identifier = serviceRequest.getIdentifier().get(0);
    String value = identifier.getValue();
    String system = identifier.getSystem();
    // PID.18
    assertThat(value).isEqualTo("665544");
    assertThat(system).isNull();
    CodeableConcept type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // No requisition in the serviceRequest.
    assertThat(serviceRequest.hasRequisition()).isFalse();
    // OBR.6 should create authoredOn because ORC.9 is not filled in
    assertThat(serviceRequest.hasAuthoredOn()).isTrue();
    assertThat(serviceRequest.getAuthoredOnElement().toString()).containsPattern("2012-06-06T12:06:06");
    // OBR.7 is used to create an ServiceRequest.occurrenceDateTime date because ORC.15 is empty
    assertThat(serviceRequest.hasOccurrenceDateTimeType()).isTrue();
    assertThat(serviceRequest.getOccurrenceDateTimeType().toString()).containsPattern("2017-07-07T15:07:07");
    // OBR.31 should create the ServiceRequest.reasonCode CWE
    assertThat(serviceRequest.hasReasonCode()).isTrue();
    assertThat(serviceRequest.getReasonCode()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptVersionedAssertions(serviceRequest.getReasonCodeFirstRep(), "HIV", "HIV/Aids", "urn:id:L", "HIV/Aids", "V1");
    // OBR.16 should create an ServiceRequest.requester reference & display
    assertThat(serviceRequest.hasRequester()).isTrue();
    assertThat(serviceRequest.getRequester().hasDisplay()).isTrue();
    assertThat(serviceRequest.getRequester().getDisplay()).isEqualTo("FRIEDA SCHMIDT MD");
    assertThat(serviceRequest.getRequester().hasReference()).isTrue();
    String requesterRef = serviceRequest.getRequester().getReference();
    Practitioner pract = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef);
    // Confirm that the matching practitioner by ID has the correct content (simple validation)
    // Should be OBR.16 because ORC.12 is empty.
    // Check the practitioner content in detail, validating subfields.
    assertThat(pract.getIdentifier()).hasSize(1);
    // OBR.16.1
    assertThat(pract.getIdentifierFirstRep().getValue()).isEqualTo("54321678");
    // OBR.16.9, tests known system logic
    assertThat(pract.getIdentifierFirstRep().getSystem()).isEqualTo("http://hl7.org/fhir/sid/us-npi");
    DatatypeUtils.checkCommonCodeableConceptAssertions(pract.getIdentifierFirstRep().getType(), "NPI", "National provider identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", // OBR.16.13
    null);
    assertThat(pract.getName()).hasSize(1);
    // Combined OBR.16.2 - OBR.16.7
    assertThat(pract.getNameFirstRep().getTextElement().toString()).hasToString("FRIEDA SCHMIDT MD");
    // OBR.16.10
    assertThat(pract.getNameFirstRep().getUseElement().getCode()).isEqualTo("usual");
    // OBR.4 maps to ServiceRequest.code.  Verify resulting CodeableConcept.
    assertThat(serviceRequest.hasCode()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(serviceRequest.getCode(), "83036E", "HEMOGLOBIN A1C", "urn:id:PACSEAP", "HEMOGLOBIN A1C");
    List<Resource> diagnosticReportList = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReportList).hasSize(1);
    DiagnosticReport diagnosticReport = ResourceUtils.getResourceDiagnosticReport(diagnosticReportList.get(0), context);
    // OBR.4 ALSO maps to DiagnosticReport.code.  Verify resulting CodeableConcept.
    assertThat(diagnosticReport.hasCode()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(diagnosticReport.getCode(), "83036E", "HEMOGLOBIN A1C", "urn:id:PACSEAP", "HEMOGLOBIN A1C");
    assertThat(diagnosticReport.hasBasedOn()).isTrue();
    assertThat(diagnosticReport.getBasedOn()).hasSize(1);
    // OBR.7 maps to create an DiagnosticReport.effectiveDateTime
    assertThat(diagnosticReport.hasEffectiveDateTimeType()).isTrue();
    assertThat(diagnosticReport.getEffectiveDateTimeType().toString()).containsPattern("2017-07-07T15:07:07");
    // Check for DiagnosticReport.issued instant of OBR.22
    assertThat(diagnosticReport.hasIssued()).isTrue();
    // NOTE: The data is kept as an InstantType, and is extracted with .toInstant
    // thus results in a different format than other time stamps that are based on DateTimeType
    assertThat(diagnosticReport.getIssued().toInstant().toString()).contains("2018-09-24T07:29:00Z");
    // Get the diagnosticReport.resultsInterpreter, which should match the Practitioner data from OBR.32
    assertThat(diagnosticReport.hasResultsInterpreter()).isTrue();
    assertThat(diagnosticReport.getResultsInterpreter()).hasSize(1);
    String resultsInterpreterRef = diagnosticReport.getResultsInterpreter().get(0).getReference();
    pract = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, resultsInterpreterRef);
    // Confirm that the matching practitioner by ID has the correct content (simple validation)
    // Should be the value OBR.32
    assertThat(pract.getIdentifierFirstRep().getValue()).isEqualTo("323232");
    assertThat(pract.getName()).hasSize(1);
    assertThat(pract.getName().get(0).getTextElement()).hasToString("Paul J Mahoney");
    // Check for OBR.25 mapped to DiagnosticReport.status
    assertThat(diagnosticReport.hasStatus()).isTrue();
    assertThat(diagnosticReport.getStatusElement().getCode()).isEqualTo("final");
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 19 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_date_test.

@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_date_test(String segment) {
    String documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT|||20180117144200|201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + "OBX|1|ST|100||This is content|||||||X\n";
    DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    InstantType date = report.getDateElement();
    // TXA.6
    assertThat(date.toString()).containsPattern("2018-01-17T14:42");
}
Also used : InstantType(org.hl7.fhir.r4.model.InstantType) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project openmrs-module-fhir2 by openmrs.

the class ObservationEffectiveDatetimeTranslatorImplTest method toOpenmrsType_shouldTranslateInstantTypeToObsDatetime.

@Test
public void toOpenmrsType_shouldTranslateInstantTypeToObsDatetime() {
    InstantType dateTime = new InstantType();
    dateTime.setValue(new Date());
    Obs result = datetimeTranslator.toOpenmrsType(obs, dateTime);
    assertThat(result, notNullValue());
    assertThat(result.getObsDatetime(), DateMatchers.sameDay(new Date()));
}
Also used : Obs(org.openmrs.Obs) InstantType(org.hl7.fhir.r4.model.InstantType) Date(java.util.Date) Test(org.junit.Test)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 InstantType (org.hl7.fhir.r4.model.InstantType)8 Test (org.junit.jupiter.api.Test)8 InstantType (org.hl7.fhir.r4b.model.InstantType)7 Date (java.util.Date)6 InstantType (org.hl7.fhir.dstu3.model.InstantType)6 Base64 (org.apache.commons.codec.binary.Base64)5 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)4 InstantType (org.hl7.fhir.r5.model.InstantType)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 DateTimeType (org.hl7.fhir.r5.model.DateTimeType)3 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3 DisplayName (org.junit.jupiter.api.DisplayName)3 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)2 BigDecimal (java.math.BigDecimal)2 TimeZone (java.util.TimeZone)2 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)2 Coding (org.hl7.fhir.dstu2.model.Coding)2 DateTimeType (org.hl7.fhir.dstu2.model.DateTimeType)2 Enumeration (org.hl7.fhir.dstu2.model.Enumeration)2