Search in sources :

Example 61 with Use

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

the class Hl7NoteFHIRConverterTest method testNoteCreationServiceRequestMutipleOBX.

// 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("provideParmsForNoteCreationServiceRequestMutipleOBX")
void testNoteCreationServiceRequestMutipleOBX(String message, int numExpectedDiagnosticReports) {
    String hl7ORU = "MSH|^~\\&|||||20180924152907||" + message + "|213|T|2.3.1|||||||||||\n" + "PID|||Pract1ID^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // "NTE|1|O|TEST NOTE DD line 1|\n" + "NTE|2|O|TEST NOTE DD line 2 |\n" + "NTE|3|O|TEST NOTE D line 3|\n"
    "PV1|1|I||||||||||||||||||||||||||||||||||||||||||20180924152707|\n" + "ORC|RE|248648498^|248648498^|ML18267-C00001^Beaker|||||||||||||||||||||||||||\n" + "OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C||||||||||||||||||||||||||||||||||||\n" + // ServiceRequest NTE has a practitioner reference in NTE.5
    "NTE|1|O|TEST ORC/OBR 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 valied 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, hl7ORU);
    List<Resource> diagnosticReports = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    // DiagnosticReport expected for ORU, but not for ORM
    // From the OBR in the ORU test case
    assertThat(diagnosticReports).hasSize(numExpectedDiagnosticReports);
    // One ServiceRequest contains NTE for ORC/OBR
    List<Resource> serviceRequests = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(serviceRequests).hasSize(1);
    ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequests.get(0), ResourceUtils.context);
    assertThat(serviceRequest.hasNote()).isTrue();
    assertThat(serviceRequest.getNote()).hasSize(1);
    // Processing adds "  \n" two spaces and a line feed between each line.
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(serviceRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST ORC/OBR NOTE AA line 1  \nTEST NOTE AA line 2  \nTEST NOTE AA line 3");
    assertThat(serviceRequest.getNote().get(0).hasAuthorReference()).isTrue();
    String practitionerServReqRefId = serviceRequest.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) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 62 with Use

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

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestRateQuantityRXO.

@Test
void dosageInstructionTestRateQuantityRXO() {
    // Test dosageInstruction.rateQuantity where RXO.21 exists and RXO.17 does not exist -> use RXO segment, no range
    String hl7message = "MSH|^~\\\\&|||||20210101000000||OMP^O09|MSGID|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|OP||||||||||||||||||||||\n" + // RXO.22.3 purposely empty to check that default system is used
    "RXO|00054418425^Dexamethasone 4 MG Oral Tablet^NDC||||||||||||||||||||6|PC||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Quantity rateQuantity = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getRateQuantity();
    // dosageInstruction.doseAndRate.rateQuantity RXO.21
    // RXO.21
    assertThat(rateQuantity.getValue()).hasToString("6.0");
    // RXO.22.1
    assertThat(rateQuantity.getUnit()).isEqualTo("PC");
    // default
    assertThat(rateQuantity.getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, and Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with Use

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

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestRateQuantityRXE.

@Test
void dosageInstructionTestRateQuantityRXE() {
    // Test dosageInstruction.rateQuantity where RXE.23 exists and RXE.22 does not exist -> use RXE segment, no range
    String hl7message = "MSH|^~\\&||||||S1|RDE^O11||T|2.6|||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|NW|||||E|||||||||||||||||||||||I\n" + "RXE||DUONEB3INH^3 ML PLAS CONT : IPRATROPIUM-ALBUTEROL 0.5-2.5 (3) MG/3ML IN SOLN^ADS|||||||||||||||||||" + // RXE.24.3 purposely empty to check that default system is used
    "||7|PC^^http://unitsofmeasure.org||||||||||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Quantity rateQuantity = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getRateQuantity();
    // dosageInstruction.doseAndRate.rateQuantity RXE.23
    // RXO.23
    assertThat(rateQuantity.getValue()).hasToString("7.0");
    // RXO.24.1
    assertThat(rateQuantity.getUnit()).isEqualTo("PC");
    // RXO.24.3
    assertThat(rateQuantity.getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, and Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with Use

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

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestDoseQuantityRXO.

@Test
void dosageInstructionTestDoseQuantityRXO() {
    // Test dosageInstruction.DoseQuantity where RXO.2 exists -> use RXO segment, no range
    String hl7message = "MSH|^~\\\\&|||||20210101000000||OMP^O09|MSGID|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|OP||||||||||||||||||||||\n" + // RXO.5 through RXO.35 not used.
    "RXO|00054418425^Dexamethasone 4 MG Oral Tablet^NDC|100||CC||||||||||||||||||||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Quantity doseQuantity = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getDoseQuantity();
    // dosageInstruction.doseAndRate.doseQuantity RXO.2
    // RXO.2
    assertThat(doseQuantity.getValue()).hasToString("100.0");
    // RXO.4.1
    assertThat(doseQuantity.getUnit()).isEqualTo("CC");
    // default
    assertThat(doseQuantity.getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, and Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with Use

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

the class Hl7ImmunizationFHIRConversionTest method testImmunizationUsePATOBJ.

@Test
void testImmunizationUsePATOBJ() throws IOException {
    // Test should only return RXA.10, ORC.12  is empty
    // If RXA.20 is RE but RXA.18 is blank then we use PATOBJ from v3ActReason
    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|||20130531||48^HIB PRP-T^CVX|0.5|ML^^UCUM||||||||||||00^refusal|RE\r" + "OBX|1|CWE|30963-3^ VACCINE FUNDING SOURCE^LN|1|V02^VFC eligible Medicaid/MedicaidManaged Care^HL70064\r";
    Immunization immunization = ResourceUtils.getImmunization(ftv, hl7VUXmessageRep);
    assertThat(immunization.hasReasonCode()).isTrue();
    assertThat(immunization.getReasonCodeFirstRep().getCodingFirstRep().getCode()).isEqualTo("00");
    assertThat(immunization.getReasonCodeFirstRep().getCodingFirstRep().getDisplay()).isEqualTo("refusal");
    assertThat(immunization.getReasonCodeFirstRep().getCodingFirstRep().getSystem()).isNull();
    assertThat(immunization.getReasonCodeFirstRep().getText()).isEqualTo("refusal");
    assertThat(immunization.getStatus().getDisplay()).isEqualTo("not-done");
    assertThat(immunization.hasStatusReason()).isTrue();
    // If RXA.20 is RE but RXA.18 is blank then we use PATOBJ from v3ActReason
    assertThat(immunization.getStatusReason().getCodingFirstRep().getCode()).isEqualTo("PATOBJ");
    assertThat(immunization.getStatusReason().getCodingFirstRep().getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v3-ActReason");
    assertThat(immunization.getStatusReason().getCodingFirstRep().getDisplay()).isEqualTo("Patient Refusal");
    // dose Quantity with a known system
    assertThat(immunization.hasDoseQuantity()).isTrue();
    assertThat(immunization.getDoseQuantity().getValue()).hasToString("0.5");
    assertThat(immunization.getDoseQuantity().getUnit()).isEqualTo("ML");
    assertThat(immunization.getDoseQuantity().getSystem()).isEqualTo("http://unitsofmeasure.org");
    // If OBX.3 is 30963-3 the OBX.5 is for funding source
    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");
    assertThat(immunization.hasProgramEligibility()).isFalse();
    assertThat(immunization.hasReaction()).isFalse();
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) Test(org.junit.jupiter.api.Test)

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