Search in sources :

Example 56 with Use

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

the class CodeableConceptTest method testCodeableConceptDoubleRaceWithVersionAndAlternate.

@Test
void testCodeableConceptDoubleRaceWithVersionAndAlternate() {
    // This has both a known and an unknown system.
    // "valueCodeableConcept": {
    // "coding": [ {
    // "system": <known-to-FHIR>,  << FIRST CODING
    // "display": <original-display-value>
    // "code": <code-from-input>
    // "version": <version>
    // },
    // {
    // "system": <unknown, so made up "urn:id:L">,  << SECOND (ALTERNATE CODING)
    // "display": <original-alternate display-value>
    // "code": <altenate-code>
    // "version": <alternate-version>
    // } ],
    // "text": <original-display-value>
    // },
    String patientWithDoubleRaceWithVersionAndAlternate = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + // Test double race in the SAME CWE (not a second CWE) and versions.  Use made up Cauc to ensure test doesn't mix up whites.
    "PID|1||12345678^^^^MR||TestPatientLastName^Jane|||||2106-3^White^CDCREC^CA^Caucasian^L^1.1^4|\n";
    Patient patient = PatientUtils.createPatientFromHl7Segment(ftv, patientWithDoubleRaceWithVersionAndAlternate);
    assertThat(patient.hasExtension()).isTrue();
    List<Extension> extensions = patient.getExtensionsByUrl(UrlLookup.getExtensionUrl("race"));
    assertThat(extensions).isNotNull();
    assertThat(extensions.size()).isEqualTo(1);
    assertThat(extensions.get(0).hasValue()).isTrue();
    CodeableConcept ccW = (CodeableConcept) extensions.get(0).getValue();
    assertThat(ccW.hasCoding()).isTrue();
    assertThat(ccW.hasText()).isTrue();
    assertThat(ccW.getText()).hasToString("White");
    List<Coding> codings = ccW.getCoding();
    assertThat(codings.size()).isEqualTo(2);
    DatatypeUtils.checkCommonCodingAssertions(codings.get(0), "2106-3", "White", V3_RACE_SYSTEM, "1.1");
    DatatypeUtils.checkCommonCodingAssertions(codings.get(1), "CA", "Caucasian", "urn:id:L", "4");
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) Patient(org.hl7.fhir.r4.model.Patient) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with Use

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

the class Hl7FinancialInsuranceTest method testInsuranceCoverageByRelatedFields.

// 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")
@ParameterizedTest
// The breadth of this test is sufficent for multiple message type coverage, so other tests are not parameterized.
@ValueSource(strings = { "DFT^P03^DFT_P03", "VXU^V04^VXU_V04", "ADT^A01^ADT_A01", "ADT^A03^ADT_A03", // ADT^A04 uses structure ADT_A01
"ADT^A04^ADT_A01", // ADT^A08 uses structure ADT_A01
"ADT^A08^ADT_A01", // ADT^A28 uses structure ADT_A05
"ADT^A28^ADT_A05", // ADT^A31 uses structure ADT_A05
"ADT^A31^ADT_A05" })
// Also test IN2.2 Social Security number
void testInsuranceCoverageByRelatedFields(String messageType) throws IOException {
    String hl7message = "MSH|^~\\&|||||20151008111200||" + messageType + "|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "PID|||MR1^^^XYZ^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + // FT1.7 is required transaction code (currently not used)
    "FT1||||20201231145045||CG|FAKE|||||||||||||||||||||||||||||||||||||\n" + // IN1.2.4, IN1.2.6 to second XV Coverage.identifier
    "IN1|1|Value1^^System3^Value4^^System6" + // IN1.5 to 15 NOT REFERENCED (See test testBasicInsuranceCoverageFields)
    "|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.23 through IN1.35 NOT REFERENCED
    "|DoeFake^Judy^^^Rev.|PAR|19780429|19 Rose St^^Faketown^CA^ZIP5||||||||||||||||" + // IN1.50 through IN1.53 NOT REFERENCED
    "|MEMBER36|||||||F|||Value46|||J494949^^^Large HMO^XX||||\n" + // IN2.9 through IN2.60 not used
    "IN2||777-88-9999||||MEDICARE06||MEDICAID08|| |||||||||| ||||||||||| |||||||||| |||||||||| ||||||||||" + // IN2.63.18 to Organization Contact telecom .rank
    "MEMBER61||^^^^^555^7677777^^^^^^20201231145045^20211231145045^^^^1|";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> encounters = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // From PV1
    assertThat(encounters).hasSize(1);
    List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // From PID
    assertThat(patients).hasSize(1);
    Patient patient = (Patient) patients.get(0);
    String patientId = patient.getId();
    // From PID.3, IN1.49, IN2.6, IN2.8
    assertThat(patient.getIdentifier()).hasSize(4);
    Identifier patientIdentifier = patient.getIdentifier().get(0);
    // PID.3.1
    assertThat(patientIdentifier.getValue()).isEqualTo("MR1");
    // PID.3.4
    assertThat(patientIdentifier.getSystem()).isEqualTo("urn:id:XYZ");
    DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MR", "Medical record number", "http://terminology.hl7.org/CodeSystem/v2-0203", // PID.3.5
    null);
    patientIdentifier = patient.getIdentifier().get(1);
    // IN1.49.1
    assertThat(patientIdentifier.getValue()).isEqualTo("J494949");
    // IN1.49.4
    assertThat(patientIdentifier.getSystem()).isEqualTo("urn:id:Large_HMO");
    DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "XX", null, "http://terminology.hl7.org/CodeSystem/v2-0203", // IN1.49.5
    null);
    patientIdentifier = patient.getIdentifier().get(2);
    // IN2.8
    assertThat(patientIdentifier.getValue()).isEqualTo("MEDICAID08");
    // No system for IN2.8
    assertThat(patientIdentifier.hasSystem()).isFalse();
    DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MA", "Patient Medicaid number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    patientIdentifier = patient.getIdentifier().get(3);
    // IN2.6
    assertThat(patientIdentifier.getValue()).isEqualTo("MEDICARE06");
    // No system for IN2.6
    assertThat(patientIdentifier.hasSystem()).isFalse();
    DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MC", "Patient's Medicare number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // From Payor created by IN1
    assertThat(organizations).hasSize(1);
    List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
    // From IN1 segment
    assertThat(coverages).hasSize(1);
    Coverage coverage = (Coverage) coverages.get(0);
    // Confirm Coverage Identifiers - Order matches order of identifier_X in Coverage.yml
    // XV, XV, XV, MB, MA, MC, SN
    assertThat(coverage.getIdentifier()).hasSize(7);
    // IN1.2.1
    assertThat(coverage.getIdentifier().get(0).getValue()).isEqualTo("Value1");
    // IN1.2.3
    assertThat(coverage.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:System3");
    // No use, here
    assertThat(coverage.getIdentifier().get(0).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(0).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.2.4
    assertThat(coverage.getIdentifier().get(1).getValue()).isEqualTo("Value4");
    // IN1.2.6
    assertThat(coverage.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:System6");
    // No use, here
    assertThat(coverage.getIdentifier().get(1).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(1).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.46
    assertThat(coverage.getIdentifier().get(2).getValue()).isEqualTo("Value46");
    // No system, here
    assertThat(coverage.getIdentifier().get(2).getSystem()).isNull();
    // Use is enumeration "old"
    assertThat(coverage.getIdentifier().get(2).getUseElement().getCode()).hasToString("old");
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(2).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN2.61 takes priority over IN1.36
    assertThat(coverage.getIdentifier().get(3).getValue()).isEqualTo("MEMBER61");
    // No system, here
    assertThat(coverage.getIdentifier().get(3).getSystem()).isNull();
    // No use, here
    assertThat(coverage.getIdentifier().get(3).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(3).getType(), "MB", "Member Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN2.8
    assertThat(coverage.getIdentifier().get(4).getValue()).isEqualTo("MEDICAID08");
    // No system, here
    assertThat(coverage.getIdentifier().get(4).getSystem()).isNull();
    // No use, here
    assertThat(coverage.getIdentifier().get(4).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(4).getType(), "MA", "Patient Medicaid number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN2.6
    assertThat(coverage.getIdentifier().get(5).getValue()).isEqualTo("MEDICARE06");
    // No system, here
    assertThat(coverage.getIdentifier().get(5).getSystem()).isNull();
    // No use, here
    assertThat(coverage.getIdentifier().get(5).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(5).getType(), "MC", "Patient's Medicare number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.36
    assertThat(coverage.getIdentifier().get(6).getValue()).isEqualTo("MEMBER36");
    // No system, here
    assertThat(coverage.getIdentifier().get(6).getSystem()).isNull();
    // No use, here
    assertThat(coverage.getIdentifier().get(6).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(6).getType(), "SN", "Subscriber Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Confirm Coverage Beneficiary references to Patient, and Payor references to Organization
    assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
    assertThat(coverage.getPayorFirstRep().getReference()).isEqualTo(organizations.get(0).getId());
    // Expect one RelatedPerson
    List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
    // From IN1.16 through IN1.19; IN1.43; INI.49
    assertThat(relatedPersons).hasSize(1);
    RelatedPerson related = (RelatedPerson) relatedPersons.get(0);
    // Check RelatedPerson identifiers
    assertThat(related.getIdentifier()).hasSize(2);
    // IN1.49.1
    assertThat(related.getIdentifier().get(0).getValue()).isEqualTo("J494949");
    // IN1.49.4
    assertThat(related.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:Large_HMO");
    // IN1.49.5
    DatatypeUtils.checkCommonCodeableConceptAssertions(// IN1.49.5
    related.getIdentifier().get(0).getType(), // IN1.49.5
    "XX", // Display value looked up from code 'XX'
    "Organization identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN2.2
    assertThat(related.getIdentifier().get(1).getValue()).isEqualTo("777-88-9999");
    // No system to assign
    assertThat(related.getIdentifier().get(1).hasSystem()).isFalse();
    DatatypeUtils.checkCommonCodeableConceptAssertions(related.getIdentifier().get(1).getType(), "SS", "Social Security number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Check RelatedPerson name. IN1.16 name is standard XPN, tested exhaustively in other tests.
    assertThat(related.getName()).hasSize(1);
    HumanName relatedName = related.getName().get(0);
    // IN1.16.1
    assertThat(relatedName.getFamily()).isEqualTo("DoeFake");
    // IN1.16.2
    assertThat(relatedName.getGiven().get(0).getValueAsString()).isEqualTo("Judy");
    // IN1.16.6
    assertThat(relatedName.getPrefixAsSingleString()).hasToString("Rev.");
    // from IN1.16 aggregate
    assertThat(relatedName.getText()).isEqualTo("Rev. Judy DoeFake");
    // Check RelatedPerson birth and gender
    // IN1.18
    assertThat(related.getBirthDateElement().toString()).containsPattern("1978-04-29");
    Enumerations.AdministrativeGender gen = related.getGender();
    // IN1.43
    assertThat(gen).isNotNull().isEqualTo(Enumerations.AdministrativeGender.FEMALE);
    // Check the RelatedPerson address. IN1.19 is a standard XAD address, which is tested exhaustively in other tests.
    assertThat(related.getAddress()).hasSize(1);
    assertThat(related.getAddress().get(0).getLine().get(0).getValueAsString()).isEqualTo(// IN1.19.1
    "19 Rose St");
    // IN1.19.3
    assertThat(related.getAddress().get(0).getCity()).isEqualTo("Faketown");
    // IN1.19.4
    assertThat(related.getAddress().get(0).getState()).isEqualTo("CA");
    // IN1.19.5
    assertThat(related.getAddress().get(0).getPostalCode()).isEqualTo("ZIP5");
    // Check RelatedPerson telecom.  IN2.63 is standard XTN, tested exhaustively in other tests.
    // telecom is type ContactPoint
    ContactPoint contactPoint = related.getTelecomFirstRep();
    // default type hardcoded.
    assertThat(contactPoint.getSystemElement().getCode()).hasToString("phone");
    // Hard-coded to home.  IN2.63.2 is not mapped (ignored).
    assertThat(contactPoint.getUseElement().getCode()).isEqualTo("home");
    // Hard-coded to home.  IN2.63.2 is not mapped (ignored).
    ;
    // IN2.63.6, IN2.63.7 via getFormattedTelecomNumberValue
    assertThat(contactPoint.getValue()).hasToString("(555) 767 7777");
    // IN2.63.13
    assertThat(contactPoint.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
    // IN2.63.14
    assertThat(contactPoint.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
    // IN2.63.18
    assertThat(contactPoint.getRank()).isEqualTo(1);
    // Check coverage relationship
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "child", "Child", "http://terminology.hl7.org/CodeSystem/subscriber-relationship", // IN1.17
    null);
    // Check relatedPerson relationship
    assertThat(related.getRelationship()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptAssertions(related.getRelationship().get(0), "PRN", "parent", "http://terminology.hl7.org/CodeSystem/v3-RoleCode", // IN1.17
    null);
    // Confirm the Coverage (subscriber) references the RelatedPerson
    assertThat(coverage.getSubscriber().getReference()).isEqualTo(related.getId());
    // Confirm the RelatedPerson references the Patient
    assertThat(related.getPatient().getReference()).isEqualTo(patientId);
    // Confirm coverage.Order
    // IN1.1 backup for missing IN1.22
    assertThat(coverage.getOrder()).isEqualTo(1);
    // Confirm there are no unaccounted for resources
    // Expected: Coverage, Organization, Patient, Encounter, RelatedPerson
    assertThat(e).hasSize(5);
}
Also used : Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) Coverage(org.hl7.fhir.r4.model.Coverage) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Enumerations(org.hl7.fhir.r4.model.Enumerations) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with Use

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

the class Hl7OrderRequestFHIRConversionTest method testAdditionalOBRFieldsNoORCSegment.

@Test
void testAdditionalOBRFieldsNoORCSegment() {
    String hl7message = "MSH|^~\\&|Epic|ATRIUS|||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||PHLabReport-Ack^^2.16.840.1.114222.4.10.3^ISO||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // ORC.15 is missing, so use OBR.7 as ServiceRequest.occurrenceDateTime
    "OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C|||20170707120707|20180808120808|||||||||||||||||F|||||||||||||||||||||||||\n";
    String json = ftv.convert(hl7message, PatientUtils.OPTIONS);
    assertThat(json).isNotBlank();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle bundle = (Bundle) bundleResource;
    List<BundleEntryComponent> e = bundle.getEntry();
    List<Resource> diagnosticReportList = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    DiagnosticReport diagnosticReport = ResourceUtils.getResourceDiagnosticReport(diagnosticReportList.get(0), context);
    // OBR.7 and OBR.8 together map to DiagnosticReport.effectivePeriod
    assertThat(diagnosticReport.hasEffectivePeriod()).isTrue();
    assertThat(diagnosticReport.getEffectivePeriod().getStartElement().toString()).containsPattern("2017-07-07T12:07:07");
    assertThat(diagnosticReport.getEffectivePeriod().getEndElement().toString()).containsPattern("2018-08-08T12:08:08");
    List<Resource> serviceRequestList = e.stream().filter(v -> ResourceType.ServiceRequest == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    // 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();
    // OBR.7 should create an ServiceRequest.occurrenceDateTime date
    assertThat(serviceRequest.hasOccurrenceDateTimeType()).isTrue();
    assertThat(serviceRequest.getOccurrenceDateTimeType().toString()).containsPattern("2017-07-07T12:07:07");
    // ORC.5 is missing, so serviceRequest.status() should be unknown
    assertThat(serviceRequest.hasStatus()).isTrue();
    assertThat(serviceRequest.getStatusElement().getCode()).isEqualTo("unknown");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Test(org.junit.jupiter.api.Test)

Example 59 with Use

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

the class Hl7NoteFHIRConverterTest method testNoteCreationMutiplePPR.

// Test that multiple problems (PRB) each with multiple notes (NTE) are associated with the correct NTE / PRB
// and that there is no "bleed"
@Test
void testNoteCreationMutiplePPR() throws IOException {
    // TODO: Add PC2 and PC3 tests in future
    String message = "PPR^PC1";
    String hl7message = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|" + message + "|1|P^I|2.6||||||ASCII||\n" + "PID|||555444222111^^^MPI&GenHosp&L^MR||james^anderson|||M||||||||||||||\n" + "PV1||I|||||||||||||||||1400|||||||||||||||||||||||||199501102300\n" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\n" + "NTE|1|O|TEST PRBa NOTE AA line 1|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "NTE|3|O|TEST NOTE AA line 3|\n" + "OBX|1|NM|17985^GLYCOHEMOGLOBIN HGB A1C^LRR^^^^^^GLYCOHEMOGLOBIN HGB A1C||5.6|%|<6.0||||F||||||||||||||\n" + "NTE|1|L|TEST OBXb NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2|\n" + "NTE|3|L|TEST NOTE BB line 3|\n" + "OBX|2|NM|17853^MEAN BLOOD GLUCOSE^LRR^^^^^^MEAN BLOOD GLUCOSE||114.02|mg/dL|||||F||||||||||||||\n" + "NTE|1|L|TEST OBXc NOTE CC line 1|\n" + "NTE|2|L|TEST NOTE CC line 2|\n" + "NTE|3|L|TEST NOTE CC line 3|\n" + "PRB|AD|200603150625|I47.2^Ventricular tachycardia^ICD-10-CM|53692||2||200603150625\n" + "NTE|1|O|TEST PRBd NOTE DD line 1|\n" + "NTE|2|O|TEST NOTE DD line 2|\n" + "NTE|3|O|TEST NOTE DD line 3|\n" + "OBX|1|NM|8595^BP Mean|1|88|MM HG|||||F|||20180520230000|||\n" + "NTE|1|L|TEST OBXe NOTE EE line 1|\n" + "NTE|2|L|TEST NOTE EE line 2|\n" + "NTE|3|L|TEST NOTE EE line 3|\n" + "OBX|2|NM|7302^Resp Rate|1|19||||||F|||20180520230000|||\n" + // Single NTE to ensure it is created correctly
    "NTE|1|L|TEST OBXf NOTE FF line 1|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patients).hasSize(1);
    // Two Conditions from two PRBs. One has "... stenosis" and notes AA, One has "... Tachycardia" and notes DD
    List<Resource> conditions = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditions).hasSize(2);
    Condition condStenosis = ResourceUtils.getResourceCondition(conditions.get(0), ResourceUtils.context);
    Condition condTachy = ResourceUtils.getResourceCondition(conditions.get(1), ResourceUtils.context);
    // Figure out which is first and reassign if needed for testing
    if (!condStenosis.getCode().getCodingFirstRep().getCode().contains("aortic stenosis")) {
        Condition temp = condStenosis;
        condStenosis = condTachy;
        condTachy = temp;
    }
    // Test the conditions have the correct NTE's associated and have correct content.
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(condStenosis.hasNote()).isTrue();
    assertThat(condStenosis.getNote()).hasSize(1);
    assertThat(condStenosis.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST PRBa NOTE AA line 1  \nTEST NOTE AA line 2  \nTEST NOTE AA line 3");
    assertThat(condTachy.hasNote()).isTrue();
    assertThat(condTachy.getNote()).hasSize(1);
    assertThat(condTachy.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST PRBd NOTE DD line 1  \nTEST NOTE DD line 2  \nTEST NOTE DD line 3");
    // Four observations.  Two associated with the first problem and two with the second
    // This map tells us what Annotation text is associated with an Observation code
    Map<String, String> matchObsCodeToNotes = new HashMap<>();
    matchObsCodeToNotes.put("17985", "TEST OBXb NOTE BB line 1  \nTEST NOTE BB line 2  \nTEST NOTE BB line 3");
    matchObsCodeToNotes.put("17853", "TEST OBXc NOTE CC line 1  \nTEST NOTE CC line 2  \nTEST NOTE CC line 3");
    matchObsCodeToNotes.put("8595", "TEST OBXe NOTE EE line 1  \nTEST NOTE EE line 2  \nTEST NOTE EE line 3");
    matchObsCodeToNotes.put("7302", "TEST OBXf NOTE FF line 1");
    // This map tells us what Parent should be associated with an Observation code
    Map<String, String> matchObsCodeToParent = new HashMap<>();
    matchObsCodeToParent.put("17985", "aortic stenosis");
    matchObsCodeToParent.put("17853", "aortic stenosis");
    matchObsCodeToParent.put("8595", "I47.2");
    matchObsCodeToParent.put("7302", "I47.2");
    List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(observations).hasSize(4);
    int observationsVerified = 0;
    // For the list of Conditions
    for (int condIndex = 0; condIndex < conditions.size(); condIndex++) {
        // condIndex is index for condition
        // Get the list of Observation references
        Condition cond = ResourceUtils.getResourceCondition(conditions.get(condIndex), ResourceUtils.context);
        List<ConditionEvidenceComponent> evidences = cond.getEvidence();
        for (int evidenceIndex = 0; evidenceIndex < evidences.size(); evidenceIndex++) {
            // Get the evidence Observation reference
            String obsReferenceId = evidences.get(evidenceIndex).getDetailFirstRep().getReference();
            // Find the referenced observation
            for (int obsIndex = 0; obsIndex < observations.size(); obsIndex++) {
                // If the Id's match
                if (obsReferenceId.contains(observations.get(obsIndex).getId())) {
                    // Check the contents and the parent
                    Observation obs = ResourceUtils.getResourceObservation(observations.get(obsIndex), ResourceUtils.context);
                    String code = obs.getCode().getCodingFirstRep().getCode().toString();
                    // The Annotation text should match the mapped text for this key
                    assertThat(obs.getNoteFirstRep().getText()).hasToString(matchObsCodeToNotes.get(code));
                    // The parent Condition code.coding.code should match the expected mapped code for this key
                    assertThat(cond.getCode().getCodingFirstRep().getCode()).hasToString(matchObsCodeToParent.get(code));
                    observationsVerified++;
                    break;
                }
            }
        }
    }
    // This confirms ALL of the observations were checked.
    assertThat(observationsVerified).isEqualTo(4);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) HashMap(java.util.HashMap) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with Use

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

the class Hl7NoteFHIRConverterTest method testMedicationRequestNoteCreation.

// 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")
@ParameterizedTest
@MethodSource("parmsTestMedicationRequestNoteCreation")
void testMedicationRequestNoteCreation(String message, String medicalRequestSegments) {
    // Minimal valid ORC message.  Requires RXO and RXR segments.
    String hl7message = "MSH|^~\\&||||IBM|20210101000000||" + message + "|MSGID|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|OP|1234|1234|0827||||||||||||||||||||\n" + // May be RXO or RXO+RXE values from parmsTestMedicationRequestNoteCreation
    medicalRequestSegments + "NTE|1|O|TEST MedReq NOTE AA line 1||Pract1ID^Pract1Last^Pract1First|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "NTE|3|O|TEST NOTE AA line 3|\n" + "OBX|1|NM|17985^GLYCOHEMOGLOBIN HGB A1C^LRR^^^^^^GLYCOHEMOGLOBIN HGB A1C||5.6|%|<6.0||||F||||||||||||||\n" + // GLYCOHEMOGLOBIN Observation NTE has a practitioner reference in NTE.5.  Note in second NTE. The first valid NTE.5 is used.
    "NTE|1|L|TEST OBXa NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2||Pract2ID^Pract2Last^Pract2First|\n" + "NTE|3|L|TEST NOTE BB line 3|\n" + "OBX|2|NM|17853^MEAN BLOOD GLUCOSE^LRR^^^^^^MEAN BLOOD GLUCOSE||114.02|mg/dL|||||F||||||||||||||\n" + // Glucose Observation NTE has no practitioner reference in NTE.5
    "NTE|1|L|TEST OBXb NOTE CC line 1|\n" + "NTE|2|L|TEST NOTE CC line 2|\n" + // Test that blank lines are preserved.
    "NTE|3|L| |\n" + "NTE|4|L|TEST NOTE CC line 4|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Expect MedicationRequest containing NTE for RXO or RXE
    List<Resource> medicationRequests = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    assertThat(medicationRequests).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequests.get(0), ResourceUtils.context);
    assertThat(medicationRequest.hasNote()).isTrue();
    assertThat(medicationRequest.getNote()).hasSize(1);
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(medicationRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST MedReq NOTE AA line 1  \nTEST NOTE AA line 2  \nTEST NOTE AA line 3");
    assertThat(medicationRequest.getNote().get(0).hasAuthorReference()).isTrue();
    String practitionerServReqRefId = medicationRequest.getNote().get(0).getAuthorReference().getReference();
    // Two observations.  One has GLYCOHEMOGLOBIN and notes BB, One has GLUCOSE and notes CC
    List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // Should be 2 for ORU and ORM
    assertThat(observations).hasSize(2);
    Observation obsGlucose = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
    Observation obsHemoglobin = ResourceUtils.getResourceObservation(observations.get(1), ResourceUtils.context);
    // Figure out which is first and reassign if needed for testing
    if (obsGlucose.getCode().getText() != "MEAN BLOOD GLUCOSE") {
        Observation temp = obsGlucose;
        obsGlucose = obsHemoglobin;
        obsHemoglobin = temp;
    }
    // Validate the note contents and references
    assertThat(obsHemoglobin.hasNote()).isTrue();
    assertThat(obsHemoglobin.getNote()).hasSize(1);
    assertThat(obsHemoglobin.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBXa NOTE BB line 1  \nTEST NOTE BB line 2  \nTEST NOTE BB line 3");
    assertThat(obsHemoglobin.getNote().get(0).hasAuthorReference()).isTrue();
    String practitionerObsHemoglobinRefId = obsHemoglobin.getNote().get(0).getAuthorReference().getReference();
    assertThat(obsGlucose.hasNote()).isTrue();
    assertThat(obsGlucose.getNote()).hasSize(1);
    assertThat(obsGlucose.getNote().get(0).getTextElement().getValueAsString()).isEqualTo(// Test that blank lines are preserved.
    "TEST OBXb NOTE CC line 1  \nTEST NOTE CC line 2  \n   \nTEST NOTE CC line 4");
    assertThat(obsGlucose.getNote().get(0).hasAuthorReference()).isFalse();
    // Two Practitioners, one for the serviceRequest, one for the GLYCOHEMOGLOBIN Observation
    List<Resource> practitioners = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitioners).hasSize(2);
    Practitioner practitionerServReq = ResourceUtils.getResourcePractitioner(practitioners.get(0), ResourceUtils.context);
    Practitioner practitionerObsHemoglobin = ResourceUtils.getResourcePractitioner(practitioners.get(1), ResourceUtils.context);
    // Adjust to correct practitioner if needed
    if (!practitionerServReq.getIdentifierFirstRep().getValue().contentEquals("Pract1ID")) {
        Practitioner temp = practitionerObsHemoglobin;
        practitionerObsHemoglobin = practitionerServReq;
        practitionerServReq = temp;
    }
    // Check the values for the Practitioners and validate match to references.
    assertThat(practitionerServReq.getIdentifier()).hasSize(1);
    assertThat(practitionerServReq.getIdentifierFirstRep().getValue()).isEqualTo("Pract1ID");
    assertThat(practitionerServReq.getName()).hasSize(1);
    assertThat(practitionerServReq.getNameFirstRep().getText()).isEqualTo("Pract1First Pract1Last");
    // Check the cross-reference
    assertThat(practitionerServReq.getId()).isEqualTo(practitionerServReqRefId);
    // Sanity check to confirm data corruption in meta content has not returned.
    CodeableConcept ccSourceEventTrigger = (CodeableConcept) practitionerServReq.getMeta().getExtensionByUrl("http://ibm.com/fhir/cdm/StructureDefinition/source-event-trigger").getValue();
    assertThat(ccSourceEventTrigger.hasText()).isFalse();
    assertThat(practitionerObsHemoglobin.getIdentifier()).hasSize(1);
    assertThat(practitionerObsHemoglobin.getIdentifierFirstRep().getValue()).isEqualTo("Pract2ID");
    assertThat(practitionerObsHemoglobin.getName()).hasSize(1);
    assertThat(practitionerObsHemoglobin.getNameFirstRep().getText()).isEqualTo("Pract2First Pract2Last");
    // Check the cross-reference
    assertThat(practitionerObsHemoglobin.getId()).isEqualTo(practitionerObsHemoglobinRefId);
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ArrayList (java.util.ArrayList)82 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)43 List (java.util.List)41 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 Date (java.util.Date)39 IOException (java.io.IOException)38 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)35 Test (org.junit.jupiter.api.Test)35 Resource (org.hl7.fhir.r4.model.Resource)34 Collectors (java.util.stream.Collectors)29 Coding (org.hl7.fhir.r4.model.Coding)27 Reference (org.hl7.fhir.r4.model.Reference)27 Timer (com.codahale.metrics.Timer)26 HashMap (java.util.HashMap)25 Bundle (org.hl7.fhir.r4.model.Bundle)25 Reference (org.hl7.fhir.dstu3.model.Reference)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 JsonObject (com.google.gson.JsonObject)20