Search in sources :

Example 1 with ServiceRequest

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

the class Hl7MDMMessageTest method test_mdm_ORDER_with_OBXnotTX.

@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void test_mdm_ORDER_with_OBXnotTX(String message) throws IOException {
    // Also check NTE working for MDM messages.
    String hl7message = "MSH|^~\\&|HNAM|W|RAD_IMAGING_REPORT|W|20180118111520||" + message + "|<MESSAGEID>|P|2.6\r" + "EVN||20150502090000|\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "PV1||O||||||||||||||||||||||||||||||||||||||||||199501102300\r" + "ORC|NW|622470H432|||||^^^^^R||||||||||||||\r" + "OBR|1|622470H432|102397CE432|||20170725143849|20180102|||||||||||||||||RAD|O||^^^^^R||||REASON_ID_1^REASON_TEXT_1||||\r" + // 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" + "TXA|1|HP^History and physical examination|TX||||201801171442||||||||||||AV|||||\r" + "OBX|1|NM|Most Current Weight^Most current measured weight (actual)||90|kg\r" + // Observation NTE has a practitioner reference in second NTE.5. Annotation uses the first valid NTE.5
    "NTE|1|L|TEST OBX NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2||Pract2ID^Pract2Last^Pract2First|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Check for the expected resources
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // from EVN, PV1
    assertThat(encounterResource).hasSize(1);
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // from PID
    assertThat(patientResource).hasSize(1);
    List<Resource> serviceRequestResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    // from ORC, OBR
    assertThat(serviceRequestResource).hasSize(1);
    // Light check that ServiceRequest contains NTE for ORC/OBR;  Deep check of NTE in Hl7NoteFHIRConverterTest.
    ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequestResource.get(0), ResourceUtils.context);
    assertThat(serviceRequest.hasNote()).isTrue();
    assertThat(serviceRequest.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(serviceRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST ORC/OBR NOTE AA line 1  \nTEST NOTE AA line 2");
    assertThat(serviceRequest.getNote().get(0).hasAuthorReference()).isTrue();
    List<Resource> documentReferenceResource = ResourceUtils.getResourceList(e, ResourceType.DocumentReference);
    // from TXA
    assertThat(documentReferenceResource).hasSize(1);
    List<Resource> observationResources = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // from OBX(not type TX)
    assertThat(observationResources).hasSize(1);
    // Light check that Observation contains NTE for OBX;  Deep check of NTE in Hl7NoteFHIRConverterTest.
    Observation observation = ResourceUtils.getResourceObservation(observationResources.get(0), ResourceUtils.context);
    // Validate the note contents and reference existance.
    assertThat(observation.hasNote()).isTrue();
    assertThat(observation.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(observation.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBX NOTE BB line 1  \nTEST NOTE BB line 2");
    assertThat(observation.getNote().get(0).hasAuthorReference()).isTrue();
    // Two Practitioners, one for the serviceRequest, one for the Observation
    List<Resource> practitioners = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    // from NTE.4 references
    assertThat(practitioners).hasSize(2);
    // Confirm that no extra resources are created
    assertThat(e.size()).isEqualTo(7);
}
Also used : 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) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ServiceRequest

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

the class Hl7ORUMessageTest method test_oru_with_specimen.

// 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 test_oru_with_specimen() throws IOException {
    String hl7message = "MSH|^~\\\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|ORU^R01|MSGID000005|T|2.6\r" + "PID||45483|45483||SMITH^SUZIE^||20160813|M|||123 MAIN STREET^^SCHENECTADY^NY^12345||(123)456-7890|||||^^^T||||||||||||\r" + "OBR|1||986^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|1051-2^New Born Screening^LN|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3065^Mahoney^Paul^J|\r" + "OBX|1|ST|TS-F-01-002^Endocrine Disorders^L||obs report||||||F\r" + "SPM|1|SpecimenID||BLD|||||||P||||||201410060535|201410060821||Y||||||1\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Verify that the right resources are created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> diagnosticReport = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReport).hasSize(1);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(1);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(1);
    List<Resource> specimenResource = ResourceUtils.getResourceList(e, ResourceType.Specimen);
    assertThat(specimenResource).hasSize(1);
    // Expecting only the above resources, no extras!
    assertThat(e).hasSize(6);
    // /////////////////////////////////////////
    // Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag.hasCode()).isTrue();
    List<Coding> codings = diag.getCode().getCoding();
    assertThat(codings).hasSize(1);
    Coding coding = codings.get(0);
    assertThat(coding.hasDisplay()).isTrue();
    assertThat(coding.getDisplay()).hasToString("New Born Screening");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("1051-2");
    assertThat(coding.hasSystem()).isTrue();
    assertThat(coding.getSystem()).hasToString("http://loinc.org");
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag.getResultsInterpreter()).hasSize(1);
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    List<Reference> spmRef = diag.getSpecimen();
    assertThat(spmRef).hasSize(1);
    assertThat(spmRef.get(0).isEmpty()).isFalse();
    // Verify result reference
    List<Reference> obsRef = diag.getResult();
    assertThat(obsRef).hasSize(1);
    assertThat(obsRef.get(0).isEmpty()).isFalse();
    // Verify presentedForm from OBX of type ST - No attachments expected because OBX of type not TX creates an Observation.
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(0, attachments.size(), "Unexpected number of attachments");
    // //////////////////////////////////
    for (Resource res : obsResource) {
        // Verify encounter reference
        Observation obs = (Observation) res;
        assertThat(obs.getEncounter().isEmpty()).isTrue();
        // Verify subject reference to Patient exists
        assertThat(obs.getSubject().isEmpty()).isFalse();
        assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
    }
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Attachment(org.hl7.fhir.r4.model.Attachment) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceRequest

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

the class Hl7ORUMessageTest method test_oru_with_multiple_reports.

// 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 test_oru_with_multiple_reports() throws IOException {
    String hl7message = "MSH|^~\\\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|ORU^R01|MSGID000005|T|2.6\r" + "PID||45483|45483||SMITH^SUZIE^||20160813|M|||123 MAIN STREET^^SCHENECTADY^NY^12345||(123)456-7890|||||^^^T||||||||||||\r" + "OBR|1||986^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|112^Final Echocardiogram Report|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3068^JOHN^Paul^J|\r" + "OBX|1|ST|TS-F-01-007^Endocrine Disorders 7^L||obs report||||||F\r" + "OBX|2|ST|TS-F-01-008^Endocrine Disorders 8^L||ECHOCARDIOGRAPHIC REPORT||||||F\r" + "OBR|1||98^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|113^Echocardiogram Report|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3065^Mahoney^Paul^J|\r" + "OBX|1|CWE|625-4^Bacteria identified in Stool by Culture^LN^^^^2.33^^result1|1|27268008^Salmonella^SCT^^^^20090731^^Salmonella species|||A^A^HL70078^^^^2.5|||P|||20120301|||^^^^^^^^Bacterial Culture||201203140957||||||\r" + "OBX|2|ST|TS-F-01-002^Endocrine Disorders^L||ECHOCARDIOGRAPHIC REPORT Group 2||||||F\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Verify that the right resources are being created
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(4);
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(2);
    List<Resource> diagnosticReport = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
    assertThat(diagnosticReport).hasSize(2);
    List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    assertThat(servReqResource).hasSize(2);
    // Expecting only the above resources, no extras!
    assertThat(e).hasSize(11);
    // /////////////////////////////////////////
    // Now confirm content of the FIRST diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag.hasCode()).isTrue();
    List<Coding> codings = diag.getCode().getCoding();
    assertThat(codings).hasSize(1);
    Coding coding = codings.get(0);
    assertThat(coding.hasDisplay()).isTrue();
    assertThat(coding.getDisplay()).hasToString("Final Echocardiogram Report");
    assertThat(coding.hasCode()).isTrue();
    assertThat(coding.getCode()).hasToString("112");
    assertThat(coding.hasSystem()).isFalse();
    // Verify encounter reference
    assertThat(diag.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag.getResultsInterpreter()).hasSize(1);
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    assertThat(diag.getSpecimen()).isEmpty();
    // Verify result reference
    List<Reference> obsRef = diag.getResult();
    assertThat(obsRef).hasSize(2);
    assertThat(obsRef.get(0).isEmpty()).isFalse();
    // Verify presentedForm from OBX of type TX - In this case no attachments created because the OBX is not of type TX.
    List<Attachment> attachments = diag.getPresentedForm();
    Assertions.assertEquals(0, attachments.size(), "Unexpected number of attachments");
    // /////////////////////////////////////////
    // Now confirm content of the SECOND diagnosticReport because we don't have separate tests for DiagnosticReport
    // /////////////////////////////////////////
    DiagnosticReport diag2 = ResourceUtils.getResourceDiagnosticReport(diagnosticReport.get(0), context);
    // Verify status from OBR.25
    assertThat(diag2.getStatus().toCode()).isEqualTo("final");
    // Verify category from OBR.24
    assertThat(diag2.getCategory()).isEmpty();
    // Verify code from OBR.4
    assertThat(diag2.hasCode()).isTrue();
    List<Coding> codings2 = diag2.getCode().getCoding();
    assertThat(codings2).hasSize(1);
    Coding coding2 = codings.get(0);
    assertThat(coding2.hasDisplay()).isTrue();
    assertThat(coding2.getDisplay()).hasToString("Final Echocardiogram Report");
    assertThat(coding2.hasCode()).isTrue();
    assertThat(coding2.getCode()).hasToString("112");
    assertThat(coding2.hasSystem()).isFalse();
    // Verify encounter reference
    assertThat(diag2.getEncounter().isEmpty()).isTrue();
    // Verify subject reference
    assertThat(diag2.getSubject().isEmpty()).isFalse();
    // Verify effectiveDateTime from OBR.7 and OBR.8
    // This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
    assertThat(diag2.getEffectiveDateTimeType().asStringValue()).isEqualTo("2015-10-09T17:36:44+08:00");
    // Verify issued from OBR.22
    assertThat(diag2.getIssued()).isNull();
    // Verify resultsInterpreter from OBR.32
    assertThat(diag2.getResultsInterpreter()).hasSize(1);
    // Verify basedOn is ref to the ServiceRequest created for ORC or OBR
    assertThat(diag.getBasedOn()).hasSize(1);
    assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
    // Verify specimen reference
    assertThat(diag2.getSpecimen()).isEmpty();
    // Verify result reference
    List<Reference> obsRef2 = diag2.getResult();
    assertThat(obsRef2).hasSize(2);
    assertThat(obsRef2.get(0).isEmpty()).isFalse();
    // Verify presentedForm from OBX of type TX - In this case no attachments created because the OBX is not type TX.
    List<Attachment> attachments2 = diag2.getPresentedForm();
    Assertions.assertEquals(0, attachments2.size(), "Unexpected number of attachments");
    // //////////////////////////////////
    for (Resource res : obsResource) {
        // Verify encounter reference is not set
        Observation obs = (Observation) res;
        assertThat(obs.getEncounter().isEmpty()).isTrue();
        // Verify subject reference to Patient exists
        Base subject = ResourceUtils.getValue(obs, "subject");
        assertThat(ResourceUtils.getValueAsString(subject, "reference").substring(0, 8)).isEqualTo("Patient/");
    }
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Attachment(org.hl7.fhir.r4.model.Attachment) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceRequest

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

the class Hl7IdentifierFHIRConversionTest method serviceRequestIdentifierTest2.

@Test
void serviceRequestIdentifierTest2() {
    // Test 3:
    // - Visit number with PV1-19
    // - filler from OBR
    // - placer from ORC
    String serviceRequest = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1||I|6N^1234^A^GENERAL HOSPITAL2|||||||SUR||||||||S|8846511|A|||||||||||||||||||SF|K||||20170215080000\n" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\n" + "ORC||PON001||||E|^Q6H^D10^^^R\n" + "OBR|1||CD150920001336|||20150930000000|20150930164100|||||||||25055^MARCUSON^PATRICIA^L|||||||||F|||5755^DUNN^CHAD^B~25055^MARCUSON^PATRICIA^L|||WEAKNESS|DAS, SURJYA P||SHIELDS, SHARON A|||||||||";
    ServiceRequest serviceReq = ResourceUtils.getServiceRequest(ftv, serviceRequest);
    // Expect 3 identifiers
    assertThat(serviceReq.hasIdentifier()).isTrue();
    assertThat(serviceReq.getIdentifier()).hasSize(3);
    List<Identifier> identifiers = serviceReq.getIdentifier();
    // Match the id's to position; we can't depend on an order.
    int posVN = getIdentifierPositionByValue("8846511", identifiers);
    assertThat(posVN).isNotSameAs(-1);
    int posFILLER = getIdentifierPositionByValue("CD150920001336", identifiers);
    assertThat(posFILLER).isNotSameAs(-1);
    int posPLACER = getIdentifierPositionByValue("PON001", identifiers);
    assertThat(posPLACER).isNotSameAs(-1);
    // Identifier 1: visit number
    Identifier identifier = serviceReq.getIdentifier().get(posVN);
    String value = identifier.getValue();
    String system = identifier.getSystem();
    // PV1.19
    assertThat(value).isEqualTo("8846511");
    assertThat(system).isNull();
    CodeableConcept type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Identifier 2: filler
    identifier = serviceReq.getIdentifier().get(posFILLER);
    value = identifier.getValue();
    system = identifier.getSystem();
    // OBR.3.1
    assertThat(value).isEqualTo("CD150920001336");
    assertThat(system).isNull();
    type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "FILL", "Filler Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Identifier 3: placer
    identifier = serviceReq.getIdentifier().get(posPLACER);
    value = identifier.getValue();
    system = identifier.getSystem();
    // ORC.2.1
    assertThat(value).isEqualTo("PON001");
    assertThat(system).isNull();
    type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "PLAC", "Placer Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceRequest

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

the class Hl7IdentifierFHIRConversionTest method serviceRequestIdentifierTest5.

// NOTE: ORU_RO1 records do not create the ServiceRequest directly.  They create a DiagnosticReport and it creates the ServiceRequest.
// This test makes sure the specification for ORU_RO1.DiagnosticReport is specifying PID and PV1 correctly in AdditionalSegments.
@Test
void serviceRequestIdentifierTest5() {
    // Test 3:
    // - MSH.7 as the visit number
    // - filler from ORC
    // - placer from ORC
    String serviceRequest = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + // PID.18 is empty so MSH.7 with be used as backup identifier visit number
    "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // PV1.19 is empty so MSH.7 with be used as backup identifier visit number
    "PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // 1. ORC.3 is used as Filler because it has priority over OBR.3
    "ORC|RE|222298|222299|ML18267-C00001^Beaker||||||||||||||||||||||||||||\n" + // 11. OBR.3 ignored as Filler
    "OBR|1|||83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C|||||||||||||||||||||||||||||||||||||||||||\n";
    ServiceRequest serviceReq = ResourceUtils.getServiceRequest(ftv, serviceRequest);
    // Expect 3 identifiers
    assertThat(serviceReq.hasIdentifier()).isTrue();
    assertThat(serviceReq.getIdentifier()).hasSize(3);
    // Expect 3 identifiers
    assertThat(serviceReq.hasIdentifier()).isTrue();
    assertThat(serviceReq.getIdentifier()).hasSize(3);
    List<Identifier> identifiers = serviceReq.getIdentifier();
    // Match the three id's to position; we can't depend on an order.
    int posVN = getIdentifierPositionByValue("20180924152907", identifiers);
    assertThat(posVN).isNotSameAs(-1);
    int posFILLER = getIdentifierPositionByValue("222299", identifiers);
    assertThat(posFILLER).isNotSameAs(-1);
    int posPLACER = getIdentifierPositionByValue("222298", identifiers);
    assertThat(posPLACER).isNotSameAs(-1);
    // Identifier 1: visit number should be set by MSH.7
    Identifier identifier = serviceReq.getIdentifier().get(posVN);
    String value = identifier.getValue();
    String system = identifier.getSystem();
    // MSH.7
    assertThat(value).isEqualTo("20180924152907");
    assertThat(system).isNull();
    CodeableConcept type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Identifier 2: filler
    identifier = serviceReq.getIdentifier().get(posFILLER);
    value = identifier.getValue();
    system = identifier.getSystem();
    // ORC.3
    assertThat(value).isEqualTo("222299");
    assertThat(system).isNull();
    type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "FILL", "Filler Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Identifier 3: placer
    identifier = serviceReq.getIdentifier().get(posPLACER);
    value = identifier.getValue();
    system = identifier.getSystem();
    // ORC.2
    assertThat(value).isEqualTo("222298");
    assertThat(system).isNull();
    type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "PLAC", "Placer Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)131 Test (org.junit.Test)111 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)76 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)52 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)52 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)50 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)44 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)44 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)44 Bundle (org.hl7.fhir.r4.model.Bundle)32 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)31 Resource (org.hl7.fhir.r4.model.Resource)29 Test (org.junit.jupiter.api.Test)28 Task (org.hl7.fhir.r4.model.Task)23 Reference (org.hl7.fhir.r4.model.Reference)22 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)20 TokenParam (ca.uhn.fhir.rest.param.TokenParam)20 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20 IdType (org.hl7.fhir.r4.model.IdType)14 Observation (org.hl7.fhir.r4.model.Observation)14