use of org.hl7.fhir.r4b.model.Observation 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.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7VXUMessageTest method test_VXU_with_minimum_patient_group_plus_multiple_order_groups.
// 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_VXU_with_minimum_patient_group_plus_multiple_order_groups() throws IOException {
String hl7message = "MSH|^~\\&|EHR|12345^SiteName|MIIS|99990|20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "PV1|1|R||||||||||||||||||V01^20120901041038\r" + "ORC|RE||4242546^NameSpaceID||||||||||||||\r" + "RXA|0|1|20140701041038|20140701041038|48^HPV, quadrivalent^CVX|0.5|ml^MilliLiter [SI Volume Units]^UCUM||||14509|||||||||CP||\r" + "OBX|1|CWE|31044-1^Immunization reaction^LN|1|VXC12^fever of >40.5C within 48 hrs.^CDCPHINVS||||||F|||20120901041038\r" + "OBX|2|CWE|31044-1^Immunization reaction^LN|1|VXC14^Rash within 14 days of dose^CDCPHINVS||||||F|||20140701041038\r" + "ORC|RE||4242546^NameSpaceID||||||||||||||\r" + "RXA|0|1|20140701041038|20140701041038|48^HPV, quadrivalent^CVX|0.5|ml^MilliLiter [SI Volume Units]^UCUM||||14509|||||||||CP||\r" + "RXR|C28161^Intramuscular^NCIT||||\r" + "OBX|1|CWE|31044-1^Immunization reaction^LN|1|39579001^Anaphylaxis (disorder)^SCT||||||F|||20120901041038\r" + "OBX|2|TS|29768-9^DATE VACCINE INFORMATION STATEMENT PUBLISHED^LN|1|20010711||||||F|||20120720101321\r";
List<Bundle.BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
// Validate that the correct resources are created
List<Resource> patient = ResourceUtils.getResourceList(e, ResourceType.Patient);
assertThat(patient).hasSize(1);
List<Resource> enc = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(enc).hasSize(1);
List<Resource> immu = ResourceUtils.getResourceList(e, ResourceType.Immunization);
assertThat(immu).hasSize(2);
List<Resource> obs = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obs).hasSize(3);
// verify that the correct Observations are associated with the correct Immunizations.
// The first two reaction details come from the first immunization resource.
// Too confirm both observations match we compare the IDs of the reaction detail and the actual observation resource id
// The first two sets of assertions are from the first RXA segment
Immunization resource = ResourceUtils.getResourceImmunization(immu.get(0), ResourceUtils.context);
List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
String reactionDetail = resource.getReactionFirstRep().getDetail().getReference();
Observation obsResource = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
assertThat(obsResource.getId()).isEqualTo(reactionDetail);
assertThat(obsResource.getCode().getCodingFirstRep().getDisplay()).isEqualTo("fever of >40.5C within 48 hrs.");
assertThat(obsResource.getCode().getCodingFirstRep().getCode()).isEqualTo("VXC12");
assertThat(obsResource.getCode().getCodingFirstRep().getSystem()).isEqualTo("urn:id:CDCPHINVS");
assertThat(obsResource.getCode().getText()).isEqualTo("fever of >40.5C within 48 hrs.");
assertThat(obsResource.getIdentifierFirstRep().getValue()).isEqualTo("4242546-VXC12-CDCPHINVS");
// Expecting only the above resources, no extras!
assertThat(obsResource.getIdentifierFirstRep().getSystem()).isEqualTo("urn:id:extID");
reactionDetail = resource.getReaction().get(1).getDetail().getReference();
obsResource = ResourceUtils.getResourceObservation(observations.get(1), ResourceUtils.context);
assertThat(obsResource.getId()).isEqualTo(reactionDetail);
assertThat(obsResource.getCode().getCodingFirstRep().getDisplay()).isEqualTo("Rash within 14 days of dose");
assertThat(obsResource.getCode().getCodingFirstRep().getCode()).isEqualTo("VXC14");
assertThat(obsResource.getCode().getCodingFirstRep().getSystem()).isEqualTo("urn:id:CDCPHINVS");
assertThat(obsResource.getCode().getText()).isEqualTo("Rash within 14 days of dose");
assertThat(obsResource.getIdentifierFirstRep().getValue()).isEqualTo("4242546-VXC14-CDCPHINVS");
assertThat(obsResource.getIdentifierFirstRep().getSystem()).isEqualTo("urn:id:extID");
assertThat(e).hasSize(7);
// The second set of assertions are from the second RXA segment
resource = ResourceUtils.getResourceImmunization(immu.get(1), ResourceUtils.context);
reactionDetail = resource.getReaction().get(0).getDetail().getReference();
obsResource = ResourceUtils.getResourceObservation(observations.get(2), ResourceUtils.context);
assertThat(obsResource.getId()).isEqualTo(reactionDetail);
assertThat(obsResource.getCode().getCodingFirstRep().getDisplay()).isEqualTo("Anaphylaxis (disorder)");
assertThat(obsResource.getCode().getCodingFirstRep().getCode()).isEqualTo("39579001");
assertThat(obsResource.getCode().getCodingFirstRep().getSystem()).isEqualTo("http://snomed.info/sct");
assertThat(obsResource.getCode().getText()).isEqualTo("Anaphylaxis (disorder)");
assertThat(obsResource.getIdentifierFirstRep().getValue()).isEqualTo("4242546-39579001-SCT");
assertThat(obsResource.getIdentifierFirstRep().getSystem()).isEqualTo("urn:id:extID");
}
use of org.hl7.fhir.r4b.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7IdentifierFHIRConversionTest method observationIdentifierTest.
@Test
void observationIdentifierTest() {
// identifier uses the logic from BUILD_IDENTIFIER_FROM_CWE (OBX.3) and joins FILL or PLAC values with it
// Filler from OBR-3; OBX-3.1/OBX-3.3
String joinFillPlaAndObx3 = "MSH|^~\\&|SOARF|E_AMC|||201512201012||ADT^A01|MSG$1|P|2.7||1|||||||\r" + "EVN|A01|201512201012||CI|wiestc|201512201007|1488\r" + "PID|||MRN12345678^^^ID-XYZ^MR~111223333^^^USA^SS~MN1234567^^^MNDOT^DL||||||||||||||\r" + "PV1|1|I|E2^E211^E211B^1488|Elective||||||||||V\r" + "OBR|1|ORD448811^NIST EHR|R-511^NIST Lab Filler|1000^Hepatitis A B C Panel^99USL|||20120628070100|||||||||\r" + "OBX|1|ST|DINnumber^^LSFUSERDATAE||N/A||||||R||||||\r";
Observation observation = ResourceUtils.getObservation(ftv, joinFillPlaAndObx3);
// Expect a single identifier
assertThat(observation.hasIdentifier()).isTrue();
assertThat(observation.getIdentifier()).hasSize(1);
// Identifier 1: extID from OBR.3 plus OBX-3.1/OBX-3.3
Identifier identifier = observation.getIdentifier().get(0);
String value = identifier.getValue();
String system = identifier.getSystem();
// OBR.3.1-OBX.3.1-OBX.3.3
assertThat(value).isEqualTo("R-511-DINnumber-LSFUSERDATAE");
assertThat(system).isEqualTo("urn:id:extID");
// Placer from OBR-2; OBX-3.1
String msg = "MSH|^~\\&|SOARF|E_AMC|||201512201012||ADT^A01|MSG$1|P|2.7||1|||||||\r" + "EVN|A01|201512201012||CI|wiestc|201512201007|1488\r" + "PID|||MRN12345678^^^ID-XYZ^MR~111223333^^^USA^SS~MN1234567^^^MNDOT^DL||||||||||||||\r" + "PV1|1|I|E2^E211^E211B^1488|Elective||||||||||V\r" + "OBR|1|ORD448811^NIST EHR|^NIST Lab Filler|1000^Hepatitis A B C Panel^99USL|||20120628070100|||||||||\r" + "OBX|1|ST|DINnumber^^||N/A||||||R||||||\r";
observation = ResourceUtils.getObservation(ftv, msg);
// Expect a single identifier
assertThat(observation.hasIdentifier()).isTrue();
assertThat(observation.getIdentifier()).hasSize(1);
// Identifier 1: extID from OBR.2 and OBX-3.1
identifier = observation.getIdentifier().get(0);
value = identifier.getValue();
system = identifier.getSystem();
// OBR.2.1-OBX.3.1
assertThat(value).isEqualTo("ORD448811-DINnumber");
assertThat(system).isEqualTo("urn:id:extID");
// Filler from ORC-3; OBX-3.2
msg = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\r" + "PID|||555444222111^^^MPI&GenHosp&L^MR||james^anderson||19600614|M||C|||^^^^^626^5641111|^^^^^626^5647654||||||||N\r" + "PV1||I|6N^1234^A^GENHOS||||0100^ANDERSON^CARL|0148^ADDISON^JAMES||SUR|||||||0148^ANDERSON^CARL|S|1400|A|||||||||||||||||||SF|K||||199501102300\r" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\r" + "OBX|1|ST|DINnumber^^LSFUSERDATAE||ECHOCARDIOGRAPHIC REPORT||||||F|||20150930164100|||\r" + "ORC|NW|PON001|FON001|PGN001|SC|D|1||20170825010500|MS|MS||||20170825010500|";
observation = ResourceUtils.getObservation(ftv, msg);
// Expect a single identifier
assertThat(observation.hasIdentifier()).isTrue();
assertThat(observation.getIdentifier()).hasSize(1);
// Identifier 1: extID from OBR.3 plus OBX-3.1/OBX-3.3
identifier = observation.getIdentifier().get(0);
value = identifier.getValue();
system = identifier.getSystem();
// ORC.3-OBX.3.1-OBX.3.3
assertThat(value).isEqualTo("FON001-DINnumber-LSFUSERDATAE");
assertThat(system).isEqualTo("urn:id:extID");
// Placer from ORC-2; OBX-3.1
msg = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\r" + "PID|||555444222111^^^MPI&GenHosp&L^MR||james^anderson||19600614|M||C|99 Oakland #106^^qwerty^OH^44889||||||||||N\r" + "PV1||I|6N^1234^A^GENHOS||||0100^ANDERSON^CARL|0148^ADDISON^JAMES||SUR|||||||0148^ANDERSON^CARL|S|1400|A||SF|K||||199501102300\r" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\r" + "OBX|1|ST|DINnumber||ECHOCARDIOGRAPHIC REPORT||||||F|||20150930164100|||\r" + "ORC|NW|PON001|||SC|D|1||20170825010500|MS|MS|||||";
observation = ResourceUtils.getObservation(ftv, msg);
// Expect a single identifier
assertThat(observation.hasIdentifier()).isTrue();
assertThat(observation.getIdentifier()).hasSize(1);
// Identifier 1: extID from OBR.2 and OBX-3.1
identifier = observation.getIdentifier().get(0);
value = identifier.getValue();
system = identifier.getSystem();
// ORC.2-OBX.3.1
assertThat(value).isEqualTo("PON001-DINnumber");
assertThat(system).isEqualTo("urn:id:extID");
}
use of org.hl7.fhir.r4b.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ServiceRequestFHIRConversionTest method test_ppr_pc1_service_request.
@Test
void test_ppr_pc1_service_request() throws IOException {
// Currently only tests limited items, TODO add tests for other field
String hl7message = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|202101010000|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F|||||||||||||||||||||\n" + "PV1||I|6N^1234^A^GENHOS|||||||SUR||||||||S||||||||||||||||||||||||||\n" + "PRB|AD||202101010000|aortic stenosis|53692||2|||202101010000\n" + "OBX|1|NM|111^TotalProtein||7.5|gm/dl|5.9-8.4||||W\n" + "ORC|NW|1000^OE|9999999^RX||SC|E|^Q6H^D10^^^R\n" + "OBR|1|TESTID|TESTID|||202101010000|202101010000||||||||||||||||||F||||||WEAKNESS||||||||||||\n" + "OBX|1|TX|||ECHOCARDIOGRAPHIC REPORT||||||F|||202101010000|||\n" + "OBX|2|TX|||NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH||||||F|||202101010000|||\n";
String json = ftv.convert(hl7message, OPTIONS);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
// OBX under PRB (the PROBLEM.PROBLEM_OBSERVATION.OBSERVATION) creates an Observation resource
// Verifying this OBX to assure ServiceRequest is using correct OBX information
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
Observation o = (Observation) obsResource.get(0);
assertEquals("111", o.getCode().getCodingFirstRep().getCode());
assertEquals("TotalProtein", o.getCode().getText());
// From OBX.11 'W'
assertEquals("Entered in Error", o.getStatus().getDisplay());
List<Resource> serviceRequestResource = e.stream().filter(v -> ResourceType.ServiceRequest == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
ServiceRequest sr = (ServiceRequest) serviceRequestResource.get(0);
assertEquals(1, serviceRequestResource.size());
// From ORC.5 'SC'
assertEquals("Active", sr.getStatus().getDisplay());
// Ensure the intent is set to "order" for all messages
assertEquals("order", sr.getIntentElement().getValueAsString());
// status defaults to "unknown"
hl7message = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|202101010000|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F|||||||||||||||||||||\n" + "PV1||I|6N^1234^A^GENHOS|||||||SUR||||||||S||||||||||||||||||||||||||\n" + "PRB|AD||202101010000|aortic stenosis|53692||2|||202101010000\n" + "ORC|NW|1000^OE|9999999^RX|||E|^Q6H^D10^^^R\n";
json = ftv.convert(hl7message, OPTIONS);
assertThat(json).isNotBlank();
bundleResource = context.getParser().parseResource(json);
b = (Bundle) bundleResource;
e = b.getEntry();
serviceRequestResource = e.stream().filter(v -> ResourceType.ServiceRequest == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
sr = (ServiceRequest) serviceRequestResource.get(0);
// Default since no OBX in message
assertEquals("Unknown", sr.getStatus().getDisplay());
}
use of org.hl7.fhir.r4b.model.Observation 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);
}
Aggregations