use of org.hl7.fhir.r4b.model.Reference 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/");
}
}
use of org.hl7.fhir.r4b.model.Reference 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/");
}
}
use of org.hl7.fhir.r4b.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7OMLMessageTest method testOMLO21WithPatientAndOrderWithPriorOrder.
@Test
public void testOMLO21WithPatientAndOrderWithPriorOrder() throws IOException {
String hl7message = "MSH|^~\\&||Test System|||20210917110100||OML^O21^OML_O21|||2.6\r" + "PID|1||7659afb9-0dfc-d744-1f40-5b9314807108^^^^MR||Feeney^Sam^^^^^L|||M||||||||\r" + "ORC|NW|8125550e-04db-11ec-a9a8-086d41d421ca^^ID^UUID|||||||\r" + "OBR|1|8125550e-04db-11ec-a9a8-086d41d421ca^^ID^UUID||58410-2^CBC panel - Blood by Automated count^LN||||||||||||\r" + "DG1|1||A013^Paratyphoid fever C^I10C|||A|||||||||1\r" + "ORC|NW|8125550e-04db-11ec-a9a8-086d41d421cb^^ID^UUID|||||||\r" + "OBR|2|8125550e-04db-11ec-a9a8-086d41d421cb^^ID^UUID||57698-3^Lipid panel with direct LDL - Serum or Plasma^LN||||||||||||\r" + "DG1|1||A001^Cholera due to Vibrio cholerae 01, biovar eltor^I10C|||A|||||||||1\r";
String json = ftv.convert(hl7message, OPTIONS_PRETTYPRINT);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
List<BundleEntryComponent> e = b.getEntry();
List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
// from PID
assertThat(patientResource).hasSize(1);
List<Resource> diagnosisResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
// from DG1
assertThat(diagnosisResource).hasSize(2);
List<Resource> serviceResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
// from ORC
assertThat(serviceResource).hasSize(2);
List<Resource> diagnosticresource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
// from OBR
assertThat(diagnosticresource).hasSize(2);
DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticresource.get(0), context);
Reference ref = diag.getSubject();
assertThat(ref.isEmpty()).isFalse();
// Confirm that there are no extra resources
assertThat(e.size()).isEqualTo(7);
}
use of org.hl7.fhir.r4b.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7OMLMessageTest method testOMLO21WithSpecimen.
@Test
public void testOMLO21WithSpecimen() throws IOException {
String hl7message = "MSH|^~\\&||Test System|||20210917110100||OML^O21^OML_O21|||2.6\r" + "PID|1||7659afb9-0dfc-d744-1f40-5b9314807108^^^^MR||Feeney^Sam^^^^^L|||M||||||||\r" + "ORC|NW|8125550e-04db-11ec-a9a8-086d41d421ca^^ID^UUID||||||||||\r" + "OBR|1|8125550e-04db-11ec-a9a8-086d41d421ca^^ID^UUID||58410-2^CBC panel - Blood by Automated count^LN||||||||||||\r" + "SPM|1|SpecimenID||BLD|||||||P||||||201410060535|201410060821||Y||||||1\r";
String json = ftv.convert(hl7message, OPTIONS_PRETTYPRINT);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
// from PID
assertThat(patientResource).hasSize(1);
List<Resource> specimenResource = ResourceUtils.getResourceList(e, ResourceType.Specimen);
// from SPM
assertThat(specimenResource).hasSize(1);
List<Resource> serviceResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
// from ORC
assertThat(serviceResource).hasSize(1);
List<Resource> diagnosticresource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
// from OBR
assertThat(diagnosticresource).hasSize(1);
// Verify the specimen reference
DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(diagnosticresource.get(0), context);
List<Reference> spmRef = diag.getSpecimen();
assertThat(spmRef.isEmpty()).isFalse();
// from SPM
assertThat(spmRef).hasSize(1);
assertThat(spmRef.get(0).isEmpty()).isFalse();
// Confirm that there are no extra resources
assertThat(e.size()).isEqualTo(4);
}
use of org.hl7.fhir.r4b.model.Reference 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");
}
Aggregations