Search in sources :

Example 86 with DateTimeType

use of org.hl7.fhir.dstu2.model.DateTimeType in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ImmunizationFHIRConversionTest method testImmunizationRXA20Priority.

// 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")
@Test
void testImmunizationRXA20Priority() throws IOException {
    // RXA.20 is "completed" this takes precedence over rxa.18 having a value and orc.5
    // ORC.5 is here to prove RXA.20 is taking precedence
    // ORC.9 is here to prove RXA.22 is taking precedence
    String hl7VUXmessageRep = "MSH|^~\\&|EHR|12345^SiteName|MIIS|99990|20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "ORC|RE||197027||ER||||20130905041038|||MD67895^Pediatric^MARY^^^^MD^^RIA|||||\r" + // RXA.11 to Performer Organization
    "RXA|||20130531||48^HIB PRP-T^CVX|0.5|ML^^ISO+||00^new immunization record^NIP001|^Sticker^Nurse|^^^RI2050||||33k2a|20131210|PMC^sanofi^MVX|00^Patient refusal^NIP002||PA|A|20120901041038\r" + "OBX|1|CWE|31044-1^Reaction^LN|1|VXC9^Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose^CDCPHINVS||||||F|||20130531|||VXC40^per imm^CDCPHINVS\r";
    List<Bundle.BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7VUXmessageRep);
    List<Resource> immu = ResourceUtils.getResourceList(e, ResourceType.Immunization);
    assertThat(immu).hasSize(1);
    Immunization resource = ResourceUtils.getResourceImmunization(immu.get(0), ResourceUtils.context);
    assertThat(resource).isNotNull();
    // RXA.20 is "completed" this takes precedence over rxa.18 having a value and orc.5
    assertThat(resource.getStatus().getDisplay()).isEqualTo("completed");
    assertThat(resource.hasStatusReason()).isTrue();
    // RXA.18
    assertThat(resource.getStatusReason().getCodingFirstRep().getCode()).isEqualTo("00");
    // RXA.18
    assertThat(resource.getStatusReason().getCodingFirstRep().getSystem()).isEqualTo("urn:id:NIP002");
    // RXA.18
    assertThat(resource.getStatusReason().getCodingFirstRep().getDisplay()).isEqualTo("Patient refusal");
    assertThat(resource.getStatusReason().getText()).isEqualTo("Patient refusal");
    assertThat(resource.getIsSubpotent()).isTrue();
    // RXA.5.1 + 5.3
    assertThat(resource.getIdentifier().get(0).getValue()).isEqualTo("48-CVX");
    assertThat(resource.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:extID");
    assertThat(resource.getVaccineCode().getCoding().get(0).getSystem()).isEqualTo(// RXA.5.3
    "http://hl7.org/fhir/sid/cvx");
    // RXA.5.1
    assertThat(resource.getVaccineCode().getCoding().get(0).getCode()).isEqualTo("48");
    // RXA.5.2
    assertThat(resource.getVaccineCode().getText()).isEqualTo("HIB PRP-T");
    // RXA.3
    assertThat(resource.getOccurrence()).hasToString("DateTimeType[2013-05-31]");
    // RXA.9.3
    assertThat(resource.getReportOrigin().getCoding().get(0).getSystem()).isEqualTo("urn:id:NIP001");
    // RXA.9.
    assertThat(resource.getReportOrigin().getCoding().get(0).getCode()).isEqualTo("00");
    // RXA.9.2
    assertThat(resource.getReportOrigin().getCoding().get(0).getDisplay()).isEqualTo("new immunization record");
    // RXA.9.2
    assertThat(resource.getReportOrigin().getText()).isEqualTo("new immunization record");
    // RXA.17
    assertThat(resource.getManufacturer().isEmpty()).isFalse();
    // RXA.22
    assertThat(resource.hasRecorded()).isTrue();
    // RXA.22
    assertThat(resource.getRecordedElement().toString()).contains("2012-09-01");
    String manufacturerRef = resource.getManufacturer().getReference();
    // RXA.15
    assertThat(resource.getLotNumber()).isEqualTo("33k2a");
    // RXA.16
    assertThat(resource.getExpirationDate()).isEqualTo("2013-12-10");
    // dose Quantity with an unknown system
    assertThat(resource.hasDoseQuantity()).isTrue();
    assertThat(resource.getDoseQuantity().getValue()).hasToString("0.5");
    assertThat(resource.getDoseQuantity().getUnit()).isEqualTo("ML");
    assertThat(resource.getDoseQuantity().getCode()).isEqualTo("ML");
    assertThat(resource.getDoseQuantity().getSystem()).isEqualTo("urn:id:ISO+");
    String requesterRef1 = resource.getPerformer().get(0).getActor().getReference();
    Practitioner practBundle1 = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef1);
    assertThat(resource.getPerformer()).hasSize(3);
    DatatypeUtils.checkCommonCodingAssertions(resource.getPerformer().get(0).getFunction().getCoding().get(0), "OP", "Ordering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // ORC.12
    null);
    assertThat(resource.getPerformer().get(0).getFunction().hasText()).isFalse();
    // ORC.12
    assertThat(resource.getPerformer().get(0).getActor().getReference()).isNotEmpty();
    assertThat(practBundle1.getNameFirstRep().getText()).isEqualTo("MARY Pediatric");
    assertThat(practBundle1.getNameFirstRep().getFamily()).isEqualTo("Pediatric");
    assertThat(practBundle1.getNameFirstRep().getGiven().get(0)).hasToString("MARY");
    assertThat(practBundle1.getIdentifierFirstRep().getValue()).isEqualTo("MD67895");
    String requesterRef2 = resource.getPerformer().get(1).getActor().getReference();
    Practitioner practBundle2 = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef2);
    DatatypeUtils.checkCommonCodingAssertions(resource.getPerformer().get(1).getFunction().getCoding().get(0), "AP", "Administering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // RXA.10
    null);
    assertThat(resource.getPerformer().get(1).getFunction().hasText()).isFalse();
    // RXA.10
    assertThat(resource.getPerformer().get(1).getActor().isEmpty()).isFalse();
    assertThat(practBundle2.getNameFirstRep().getText()).isEqualTo("Nurse Sticker");
    assertThat(practBundle2.getNameFirstRep().getFamily()).isEqualTo("Sticker");
    assertThat(practBundle2.getNameFirstRep().getGiven().get(0)).hasToString("Nurse");
    String requesterRef3 = resource.getPerformer().get(2).getActor().getReference();
    DatatypeUtils.checkCommonCodingAssertions(resource.getPerformer().get(2).getFunction().getCoding().get(0), "AP", "Administering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // RXA.11
    null);
    assertThat(resource.getPerformer().get(1).getFunction().hasText()).isFalse();
    // Immunization.Reaction Date (OBX.14) and Detail (OBX.5 if OBX 3 is 31044-1)
    // OBX.14
    assertThat(resource.getReactionFirstRep().getDateElement().toString()).contains("2013-05-31");
    // OBX.5
    assertThat(resource.getReactionFirstRep().getDetail().hasReference()).isTrue();
    // Looking for one Observation that matches the Reaction.Detail reference
    String reactionDetail = resource.getReactionFirstRep().getDetail().getReference();
    List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(observations).hasSize(1);
    Observation obs = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
    assertThat(obs.getId()).isEqualTo(reactionDetail);
    assertThat(obs.getCode().getCodingFirstRep().getDisplay()).isEqualTo("Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose");
    assertThat(obs.getCode().getCodingFirstRep().getCode()).isEqualTo("VXC9");
    assertThat(obs.getCode().getCodingFirstRep().getSystem()).isEqualTo("urn:id:CDCPHINVS");
    assertThat(obs.getCode().getText()).isEqualTo("Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose");
    assertThat(obs.getIdentifierFirstRep().getValue()).isEqualTo("197027-VXC9-CDCPHINVS");
    assertThat(obs.getIdentifierFirstRep().getSystem()).isEqualTo("urn:id:extID");
    // Looking for two Organizations: one for the manufacturer reference and one for the Immunization.performer
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    assertThat(organizations).hasSize(2);
    Organization org = ResourceUtils.getResourceOrganization(organizations.get(0), ResourceUtils.context);
    assertThat(org.getName()).isEqualTo("RI2050");
    assertThat(org.getId()).isEqualTo(requesterRef3);
    assertThat(org.hasContact()).isFalse();
    org = ResourceUtils.getResourceOrganization(organizations.get(1), ResourceUtils.context);
    assertThat(org.getName()).isEqualTo("sanofi");
    assertThat(org.getId()).isEqualTo(manufacturerRef);
    assertThat(org.hasContact()).isFalse();
    // Test that a ServiceRequest is not created for VXU_V04
    List<Resource> serviceRequestList = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    // Confirm that a serviceRequest was not created.
    assertThat(serviceRequestList).isEmpty();
    // Check for expected resources: Organizations (2), Immunization, Patient, Observation, Practitioner (2)
    assertThat(e).hasSize(7);
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) Immunization(org.hl7.fhir.r4.model.Immunization) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Organization(org.hl7.fhir.r4.model.Organization) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test)

Example 87 with DateTimeType

use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.

the class ConditionTranslatorImpl method toFhirResource.

@Override
public org.hl7.fhir.r4.model.Condition toFhirResource(@Nonnull Obs obsCondition) {
    notNull(obsCondition, "The Openmrs Condition object should not be null");
    org.hl7.fhir.r4.model.Condition fhirCondition = new org.hl7.fhir.r4.model.Condition();
    fhirCondition.setId(obsCondition.getUuid());
    Person obsPerson = obsCondition.getPerson();
    if (obsPerson != null) {
        if (obsPerson instanceof HibernateProxy) {
            obsPerson = HibernateUtil.getRealObjectFromProxy(obsPerson);
        }
        if (obsPerson instanceof Patient) {
            fhirCondition.setSubject(patientReferenceTranslator.toFhirResource((Patient) obsPerson));
        }
    }
    if (obsCondition.getValueCoded() != null) {
        fhirCondition.setCode(conceptTranslator.toFhirResource(obsCondition.getValueCoded()));
    }
    fhirCondition.setOnset(new DateTimeType().setValue(obsCondition.getObsDatetime()));
    fhirCondition.setRecorder(practitionerReferenceTranslator.toFhirResource(obsCondition.getCreator()));
    fhirCondition.setRecordedDate(obsCondition.getDateCreated());
    fhirCondition.getMeta().setLastUpdated(obsCondition.getDateChanged());
    fhirCondition.addContained(provenanceTranslator.getCreateProvenance(obsCondition));
    fhirCondition.addContained(provenanceTranslator.getUpdateProvenance(obsCondition));
    return fhirCondition;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Patient(org.openmrs.Patient) Person(org.openmrs.Person) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 88 with DateTimeType

use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.

the class FhirImmunizationServiceImplTest method saveImmunization_shouldCreateEncounterAndObsGroupWhenNewImmunization.

@Test
public void saveImmunization_shouldCreateEncounterAndObsGroupWhenNewImmunization() {
    // setup
    FhirContext ctx = FhirContext.forR4();
    IParser parser = ctx.newJsonParser();
    Immunization newImmunization = parser.parseResource(Immunization.class, "{\n" + "  \"resourceType\": \"Immunization\",\n" + "  \"status\": \"completed\",\n" + "  \"vaccineCode\": {\n" + "    \"coding\": [\n" + "      {\n" + "        \"code\": \"15f83cd6-64e9-4e06-a5f9-364d3b14a43d\",\n" + "        \"display\": \"Aspirin as a vaccine\"\n" + "      }\n" + "    ]\n" + "  },\n" + "  \"patient\": {\n" + "    \"reference\": \"Patient/a7e04421-525f-442f-8138-05b619d16def\",\n" + "    \"type\": \"Patient\"\n" + "  },\n" + "  \"encounter\": {\n" + "    \"reference\": \"Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc\",\n" + "    \"type\": \"Encounter\"\n" + "  },\n" + "  \"occurrenceDateTime\": \"2020-07-08T18:30:00.000Z\",\n" + "  \"manufacturer\": {\n" + "    \"display\": \"Acme\"\n" + "  },\n" + "  \"lotNumber\": \"FOO1234\",\n" + "  \"expirationDate\": \"2022-07-31T18:30:00.000Z\",\n" + "  \"performer\": [\n" + "    {\n" + "      \"actor\": {\n" + "        \"reference\": \"Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66\",\n" + "        \"type\": \"Practitioner\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"protocolApplied\": [\n" + "    {\n" + "      \"doseNumberPositiveInt\": 2,\n" + "      \"series\": \"Dose 2\"\n" + "    }\n" + "  ]\n" + "}");
    // replay
    Immunization savedImmunization = service.create(newImmunization);
    Obs obs = obsService.getObsByUuid(savedImmunization.getId());
    // verify
    helper.validateImmunizationObsGroup(obs);
    assertObsCommons(obs, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
    obs.getGroupMembers().forEach(o -> assertObsCommons(o, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66"));
    Map<String, Obs> members = helper.getObsMembersMap(obs);
    assertThat(members.get(CIEL_984).getValueCoded().getUuid(), is("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(members.get(CIEL_1410).getValueDatetime(), equalTo(new DateTimeType("2020-07-08T18:30:00.000Z").getValue()));
    assertThat(members.get(CIEL_1418).getValueNumeric(), equalTo(2.0));
    assertThat(members.get(CIEL_1419).getValueText(), is("Acme"));
    assertThat(members.get(CIEL_1420).getValueText(), is("FOO1234"));
    assertThat(members.get(CIEL_165907).getValueDatetime(), equalTo(new DateTimeType("2022-07-31T18:30:00.000Z").getValue()));
}
Also used : Obs(org.openmrs.Obs) FhirContext(ca.uhn.fhir.context.FhirContext) Immunization(org.hl7.fhir.r4.model.Immunization) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) IParser(ca.uhn.fhir.parser.IParser) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 89 with DateTimeType

use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.

the class ObservationTranslatorImplTest method toOpenmrsType_shouldTranslateEffectiveDatetimeToObsDatetime.

@Test
public void toOpenmrsType_shouldTranslateEffectiveDatetimeToObsDatetime() {
    Observation observation = new Observation();
    DateTimeType dateTime = new DateTimeType();
    dateTime.setValue(new Date());
    observation.setEffective(dateTime);
    Obs obs = new Obs();
    Obs expected = new Obs();
    expected.setObsDatetime(new Date());
    observationTranslator.toOpenmrsType(obs, observation);
    assertThat(expected, notNullValue());
    assertThat(expected.getObsDatetime(), notNullValue());
    assertThat(expected.getObsDatetime(), DateMatchers.sameDay(new Date()));
}
Also used : Obs(org.openmrs.Obs) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Observation(org.hl7.fhir.r4.model.Observation) Date(java.util.Date) Test(org.junit.Test)

Example 90 with DateTimeType

use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.

the class ObservationValueTranslatorImplTest method toFhirResource_shouldConvertObsWithDatetimeToDateTimeType.

@Test
public void toFhirResource_shouldConvertObsWithDatetimeToDateTimeType() {
    Date expected = new Date();
    obs.setValueDate(expected);
    Type result = obsValueTranslator.toFhirResource(obs);
    assertThat(result, notNullValue());
    assertThat(result, instanceOf(DateTimeType.class));
    assertThat(((DateTimeType) result).getValue(), equalTo(expected));
}
Also used : Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Date(java.util.Date) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Aggregations

DateTimeType (org.hl7.fhir.r4.model.DateTimeType)65 Date (java.util.Date)28 Test (org.junit.Test)25 Coding (org.hl7.fhir.r4.model.Coding)23 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)18 Period (org.hl7.fhir.r4.model.Period)18 ArrayList (java.util.ArrayList)17 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 Observation (org.hl7.fhir.r4.model.Observation)16 Test (org.junit.jupiter.api.Test)16 Patient (org.hl7.fhir.r4.model.Patient)14 DateTimeType (org.hl7.fhir.r4b.model.DateTimeType)14 HashMap (java.util.HashMap)13 DateTimeType (org.hl7.fhir.r5.model.DateTimeType)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 Reference (org.hl7.fhir.r4.model.Reference)12 List (java.util.List)11 Reference (org.hl7.fhir.dstu3.model.Reference)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 Resource (org.hl7.fhir.r4.model.Resource)11