Search in sources :

Example 51 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project hl7v2-fhir-converter by LinuxForHealth.

the class FHIRConverterTest method test_dosage_output.

@Test
void test_dosage_output() throws IOException {
    String hl7message = "MSH|^~\\&|MyEMR|DE-000001| |CAIRLO|20160701123030-0700||VXU^V04^VXU_V04|CA0001|P|2.6|||ER|AL|||||Z22^CDCPHINVS|DE-000001\r" + "PID|1||PA123456^^^MYEMR^MR||JONES^GEORGE^M^JR^^^L|MILLER^MARTHA^G^^^^M|20140227|M||2106-3^WHITE^CDCREC|1234 W FIRST ST^^BEVERLY HILLS^CA^90210^^H||^PRN^PH^^^555^5555555||ENG^English^HL70296|||||||2186-5^ not Hispanic or Latino^CDCREC||Y|2\r" + "ORC|RE||197023^CMC|||||||^Clark^Dave||1234567890^Smith^Janet^^^^^^NPPES^L^^^NPI^^^^^^^^MD\r" + "RXA|0|1|20140730||08^HEPB-PEDIATRIC/ADOLESCENT^CVX|.5|mL^mL^UCUM||00^NEW IMMUNIZATION RECORD^NIP001|1234567890^Smith^Janet^^^^^^NPPES^^^^NPI^^^^^^^^MD |^^^DE-000001||||0039F|20200531|MSD^MERCK^MVX|||CP|A";
    String json = ftv.convert(hl7message, OPTIONS);
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> immunization = e.stream().filter(v -> ResourceType.Immunization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(immunization).hasSize(1);
    String s = context.getParser().encodeResourceToString(immunization.get(0));
    Class<? extends IBaseResource> klass = Immunization.class;
    Immunization expectDoseQuantity = (Immunization) context.getParser().parseResource(klass, s);
    assertThat(expectDoseQuantity.hasDoseQuantity()).isTrue();
    Quantity dosage = expectDoseQuantity.getDoseQuantity();
    BigDecimal value = dosage.getValue();
    String unit = dosage.getUnit();
    assertThat(value).isEqualTo(BigDecimal.valueOf(.5));
    assertThat(unit).isEqualTo("mL");
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Immunization(org.hl7.fhir.r4.model.Immunization) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 52 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project hl7v2-fhir-converter by LinuxForHealth.

the class MedicationFHIRConverterTest method practitonerCreatedForRXA.

// Tests that we create a practitioner from the RXA segment in hl7 message.
// This uses the Performer resource (specifically actor)
@Test
void practitonerCreatedForRXA() {
    String hl7message = "MSH|^~\\&|EHR|12345^SiteName|MIIS|99990|20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "NK1|1|mother^patient|MTH^Mother^HL70063|5 elm st^^boston^MA^01234^^P|781-999-9999^PRN^PH^^1^781^9999999|||||||||||||||||01^No reminder/recall^HL70215\r" + "PV1|1|R||||||||||||||||||V01^20120901041038\r" + "IN1|1||8|Aetna Inc\r" + "ORC|RE||4242546^NameSpaceID||||||||||||||\r" + "RXA|0|1|20140701041038|20140701041038|48^HPV, quadrivalent^CVX|0.5|ml^MilliLiter [SI Volume Units]^UCUM||00^New Immunization^NIP001|NPI001^LastName^ClinicianFirstName^^^^Title^^AssigningAuthority|14509||||L987||MSD^Merck^MVX|||CP||20120901041038\r" + "RXR|C28161^Intramuscular^NCIT|LA^Leftarm^HL70163\r" + "OBX|1|CE|30963-3^ VACCINE FUNDING SOURCE^LN|1|VXC2^STATE FUNDS^HL70396||||||F|||20120901041038\r" + "OBX|2|CE|64994-7^Vaccine funding program eligibility category^LN|1|V01^Not VFC^HL70064||||||F|||20140701041038\r" + "OBX|3|TS|29768-9^DATE VACCINE INFORMATION STATEMENT PUBLISHED^LN|1|20010711||||||F|||20120720101321\r" + "OBX|4|TS|29769-7^DATE VACCINE INFORMATION STATEMENT PRESENTED^LN|1|19901207||||||F|||20140701041038\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Find the practitioner from the FHIR bundle.
    List<Resource> practitionerResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    // Verify we have one practitioner
    assertThat(practitionerResource).hasSize(1);
    // Get practitioner Resource
    Resource practitioner = practitionerResource.get(0);
    // Verify name text, family, and given are set correctly.
    Base name = ResourceUtils.getValue(practitioner, "name");
    assertThat(ResourceUtils.getValueAsString(name, "text")).isEqualTo("ClinicianFirstName LastName");
    assertThat(ResourceUtils.getValueAsString(name, "family")).isEqualTo("LastName");
    assertThat(ResourceUtils.getValueAsString(name, "given")).isEqualTo("ClinicianFirstName");
    // Verify asserter identifier is set correctly.
    Base identifier = ResourceUtils.getValue(practitioner, "identifier");
    assertThat(ResourceUtils.getValueAsString(identifier, "value")).isEqualTo("NPI001");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Base(org.hl7.fhir.r4.model.Base) Test(org.junit.jupiter.api.Test)

Example 53 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ImmunizationFHIRConversionTest method testImmunizationFailingFundingSource.

// 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 testImmunizationFailingFundingSource() throws IOException {
    // Tests that multiple OBX records are processed.
    // Checks that values which are created from all of the associated OBX records are found.
    // Checks that a bug where only the first of the OBX records were processed does not return.
    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||PA|||||^Clerk^Myron|||||||RI2050\r" + // RXA 5 purposely empty so OBX.3 30956-7 triggers
    "RXA|||20130531|||0.5|ML^^UCUM||||||||||||00^refusal|RE\r" + // Four different specialized OBX records.  See comments in tests.
    "OBX|1|CWE|30963-3^ VACCINE FUNDING SOURCE^LN|1|V02^VFC eligible Medicaid/MedicaidManaged Care^HL70064\r" + "OBX|2|CE|64994-7^Vaccine funding program eligibility category^LN|1|V05^VFC eligible - Federally Qualified Health Center Patient (under-insured)^HL70064||||||F|||20161107\r" + "OBX|3|CWE|30956-7^vaccine type^LN|1|107^DTAP^CVX||||||F|||20161108\r" + "OBX|4|CWE|31044-1^Reaction^LN|1|VXC9^Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose^CDCPHINVS||||||F|||20170201\r";
    List<Bundle.BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7VUXmessageRep);
    List<Resource> immunizations = ResourceUtils.getResourceList(e, ResourceType.Immunization);
    assertThat(immunizations).hasSize(1);
    Immunization immunization = ResourceUtils.getResourceImmunization(immunizations.get(0), ResourceUtils.context);
    // For OBX record 1, OBX.3 is 30963-3, use OBX.5 as funding source
    assertThat(immunization.hasFundingSource()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(immunization.getFundingSource(), "V02", "VFC eligible Medicaid/MedicaidManaged Care", "https://phinvads.cdc.gov/vads/ViewCodeSystem.action?id=2.16.840.1.113883.12.64#", "VFC eligible Medicaid/MedicaidManaged Care");
    // For OBX record 2, OBX.3 is 64994-7, use OBX.5 as programEligibility
    assertThat(immunization.hasProgramEligibility()).isTrue();
    assertThat(immunization.getProgramEligibility()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptAssertions(immunization.getProgramEligibilityFirstRep(), "V05", null, "https://phinvads.cdc.gov/vads/ViewCodeSystem.action?id=2.16.840.1.113883.12.64#", "VFC eligible - Federally Qualified Health Center Patient (under-insured)");
    // For OBX record 3, OBX.3 is 30956-7 and RXA.5 is empty, use OBX.5 as vaccineCode
    assertThat(immunization.hasVaccineCode()).isTrue();
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode()).isEqualTo("107");
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getDisplay()).isEqualTo("DTAP");
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getSystem()).isEqualTo("http://hl7.org/fhir/sid/cvx");
    assertThat(immunization.getVaccineCode().getText()).isEqualTo("DTAP");
    // For OBX record 4 OBX.3 is 31044-1, use OBX.5 as reaction and create a detail reference;
    // OBX.14
    assertThat(immunization.getReactionFirstRep().getDateElement().toString()).contains("2017-02-01");
    // OBX.5
    assertThat(immunization.getReactionFirstRep().getDetail().hasReference()).isTrue();
    // Looking for one Observation that matches the Reaction.Detail reference
    String reactionDetailReference = immunization.getReactionFirstRep().getDetail().getReference();
    // There is only one observation, and it should be the one for reaction
    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(reactionDetailReference);
    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");
    // Check for expected resources: Immunization, Observation, Patient
    assertThat(e).hasSize(3);
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test)

Example 54 with Immunization

use of org.hl7.fhir.r4.model.Immunization in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ImmunizationFHIRConversionTest method testDoubleMultipleNestedEducation.

// The following creates education records which combine information from related OBX's, indicated by matching OBX.4 value
// There are three ORC/RXA/RXR/OBX* sections, two differ only by dates and other small differences; enough to ensure we
// are finding the correct matching publication and presentation dates for the correct siblings and there is no data bleed.
// Others have handle various cases of completeness of data, according to rules outlined in Immunization.yml.
// For each of RXA sections below, Immunization.education should be (dates & xx vary):
// 
// "education": [
// {
// "documentType": "DTaP, xx UF",
// "publicationDate": "2007-05-17",
// "presentationDate": "2014-12-03"
// },
// {
// "documentType": "Hep B, xx UF",
// "publicationDate": "2012-02-02",
// "presentationDate": "2014-12-03"
// }
// ],
@Test
void testDoubleMultipleNestedEducation() throws IOException {
    String hl7VUXmessageRep = "MSH|^~\\&|||||20160106165800070+0000||VXU^V04^VXU_V04|20210205NH0000 01|P|2.5.1|||||||||Z22^CDCPHPHINVS|||\n" + "PID|1||12345^^^^MR||TestPatient^Jane^^^^^L||||||\n" + "NK1|1|LASTNAME^FIRST^^^^^L|SPO^SPOUSE^HL70063||^PRN^PH^^^603^7772222\n" + // ----- FIRST IMMUNIZATION SET. ----- Descriptions have AA, and dates 2007.
    "ORC|RE||2623980^EHR|||||||||^ORDERINGLASTNAME^FIRST^^^^^^^L^^^MD|\n" + "RXA|0|1|20160105||33^PNEUMOCOCCAL POLYSACCHARIDE PPV23^CVX|0.5|ML^^UCUM|||||||||||||||\n" + "RXR|C28161^Intramuscular^NCIT|LD^Left Deltoid^HL70163|\n" + // Reference will be used as DocumentType
    "OBX|1|CE|30956-7^Vaccine Type^LN|2|107^DTaP, AA1 UF^CVX||||||F\n" + "OBX|2|DT|29768-9^Date Vaccine Information Statement Published^LN|2|20070517||||||F\n" + "OBX|3|DT|29769-7^Date Vaccine Information Statement Presented^LN|2|20071203||||||F\n" + // Random OBX to prove it doesn't confuse searching or group association.
    "OBX|4|CWE|64994-7^funding pgm eligibility^LN||V01^Insured^HL70064||||||F||||||VXC40^per immunization^CDCPHINVS\n" + // Reference will be used as DocumentType
    "OBX|5|CE|30956-7^Vaccine Type^LN|3|45^Hep B, AA2 UF^CVX||||||F\n" + "OBX|6|DT|29768-9^Date Vaccine Information Statement Published^LN|3|20070202||||||F\n" + "OBX|7|DT|29769-7^Date Vaccine Information Statement Presented^LN|3|20071203||||||F\n" + // 48767-8 record in group will be ignore.
    "OBX|2|DT|69764-9^HIB Info Sheet^LN|8|20070505||||||F|||20130531\n" + "OBX|3|DT|29768-9^VIS Publication Date^LN|8|20070606||||||F|||20130531\n" + "OBX|4|DT|29769-7^VIS Presentation Date^LN|8|20070707||||||F|||20130531\n" + "OBX|5|ST|48767-8^Annotation^LN|8|Some text from doctor||||||F|||20130531\n" + // -----  SECOND IMMUNIZATION SET. ----- Descriptions have BB, and dates 2014.
    "ORC|RE||2623980^EHR|||||||||^ORDERINGLASTNAME^FIRST^^^^^^^L^^^MD|\n" + "RXA|0|1|20160105||33^PNEUMOCOCCAL POLYSACCHARIDE PPV23^CVX|0.5|ML^^UCUM||||||||||||||||\n" + "RXR|C28161^Intramuscular^NCIT|LD^Left Deltoid^HL70163|\n" + // Random OBX to prove it doesn't confuse searching or group association.
    "OBX|1|CWE|64994-7^funding pgm eligibility^LN||V01^Insured^HL70064||||||F||||||VXC40^per immunization^CDCPHINVS\n" + // Reference will be used as DocumentType
    "OBX|2|CE|30956-7^Vaccine Type^LN|2|107^DTaP, BB1 UF^CVX||||||F\n" + "OBX|3|DT|29768-9^Date Vaccine Information Statement Published^LN|2|20140517||||||F\n" + "OBX|4|DT|29769-7^Date Vaccine Information Statement Presented^LN|2|20141203||||||F\n" + // Reference will be used as DocumentType
    "OBX|5|CE|30956-7^Vaccine Type^LN|3|45^Hep B, BB2 UF^CVX||||||F\n" + "OBX|6|DT|29768-9^Date Vaccine Information Statement Published^LN|3|20140202||||||F\n" + "OBX|7|DT|29769-7^Date Vaccine Information Statement Presented^LN|3|20141203||||||F\n" + // 'unspecified' is used as DocumentType.
    "OBX|32|DT|29768-9^Date Vaccine Information Statement Published^LN|6|20140503||||||F\n" + "OBX|33|DT|29769-7^Date Vaccine Information Statement Presented^LN|6|20140505||||||F\n" + // -----  THIRD IMMUNIZATION SET. ----- Descriptions have CC, and dates 2017.
    "ORC|RE||2623980^EHR|||||||||^ORDERINGLASTNAME^FIRST^^^^^^^L^^^MD|\n" + "RXA|0|1|20160105||33^PNEUMOCOCCAL POLYSACCHARIDE PPV23^CVX|0.5|ML^^UCUM||||||||||||||||\n" + "RXR|C28161^Intramuscular^NCIT|LD^Left Deltoid^HL70163|\n" + // OBX times have type TS to prove that works
    "OBX|8|CE|69764-9^Vaccine Type^LN|4|45^Hep B, CC3a UF^CVX||||||F\n" + "OBX|9|CE|30956-7^Vaccine Type^LN|4|45^Hep B, CC3b UF^CVX||||||F\n" + "OBX|10|TS|29768-9^Date Vaccine Information Statement Published^LN|4|20170303||||||F\n" + "OBX|11|TS|29769-7^Date Vaccine Information Statement Presented^LN|4|20170305||||||F\n" + // OBX times have type DTM to prove that works
    "OBX|21|CE|69764-9^Vaccine Type^LN|5|45^Hep B, CC4 UF^CVX||||||F\n" + "OBX|22|DTM|29768-9^Date Vaccine Information Statement Published^LN|5|20170403011212000+0000||||||F\n" + "OBX|23|DTM|29769-7^Date Vaccine Information Statement Presented^LN|5|20170405011212000+0000||||||F\n" + // 'unspecified' is used as DocumentType.
    "OBX|43|DT|29769-7^Date Vaccine Information Statement Presented^LN|7|20170605||||||F\n" + "ORC|RE||9999^EHR|||||||\n";
    List<Bundle.BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7VUXmessageRep);
    List<Resource> immunizations = ResourceUtils.getResourceList(e, ResourceType.Immunization);
    assertThat(immunizations).hasSize(3);
    // First immunization set. Descriptions have AA, and dates 2007.
    Immunization immunization = (Immunization) immunizations.get(0);
    assertThat(immunization.getEducation()).hasSize(3);
    checkImmunizationEducation(immunization.getEducation().get(1), "DTaP, AA1 UF", "2007-05-17", "2007-12-03");
    checkImmunizationEducation(immunization.getEducation().get(2), "Hep B, AA2 UF", "2007-02-02", "2007-12-03");
    // Degenerate 69764-9 without CE/CWE data. DocumentType will default to "unspecified"
    checkImmunizationEducation(immunization.getEducation().get(0), "unspecified", "2007-06-06", "2007-07-07");
    // Second immunization set. Descriptions have BB, and dates 2014.
    immunization = (Immunization) immunizations.get(1);
    assertThat(immunization.getEducation()).hasSize(3);
    // Reference used as DocumentType
    checkImmunizationEducation(immunization.getEducation().get(0), "DTaP, BB1 UF", "2014-05-17", "2014-12-03");
    // Reference used as DocumentType
    checkImmunizationEducation(immunization.getEducation().get(1), "Hep B, BB2 UF", "2014-02-02", "2014-12-03");
    // Has no DocumentType nor Reference record. 'unspecified' is used as DocumentType.
    checkImmunizationEducation(immunization.getEducation().get(2), "unspecified", "2014-05-03", "2014-05-05");
    // Second immunization set. Descriptions have CC, and dates 2017.
    immunization = (Immunization) immunizations.get(2);
    assertThat(immunization.getEducation()).hasSize(3);
    // Has both DocumentType and Reference records.  DocumentType will be used.
    checkImmunizationEducation(immunization.getEducation().get(0), "Hep B, CC3a UF", "2017-03-03", "2017-03-05");
    // Has only DocumentType record.  DocumentType will be used.
    checkImmunizationEducation(immunization.getEducation().get(1), "Hep B, CC4 UF", "2017-04-03", "2017-04-05");
    // Has no DocumentType nor Reference record nor PublicationDate. 'unspecified' is used as DocumentType.
    checkImmunizationEducation(immunization.getEducation().get(2), "unspecified", null, "2017-06-05");
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Test(org.junit.jupiter.api.Test)

Example 55 with Immunization

use of org.hl7.fhir.r4.model.Immunization 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)

Aggregations

Immunization (org.hl7.fhir.r4.model.Immunization)47 Test (org.junit.Test)27 Test (org.junit.jupiter.api.Test)22 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)18 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)15 Resource (org.hl7.fhir.r4.model.Resource)13 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)8 Bundle (org.hl7.fhir.r4.model.Bundle)7 Organization (org.hl7.fhir.r4.model.Organization)7 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)6 Date (java.util.Date)5 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)5 IdType (org.hl7.fhir.r4.model.IdType)5 Observation (org.hl7.fhir.r4.model.Observation)5 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)5 InputStream (java.io.InputStream)4 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)4 Obs (org.openmrs.Obs)4 FhirContext (ca.uhn.fhir.context.FhirContext)3