use of org.hl7.fhir.r5.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_observation.
@Test
void test_observation() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/Observation");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Observation").withResourceModel(rsm).withSegment("OBX").withIsReferenced(true).withRepeats(false).build();
HL7FHIRResourceTemplate observation = new HL7FHIRResourceTemplate(attributes);
HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(observation));
String hl7message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^Sr^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||\r" + "OBX|1|NM|0135-4^TotalProtein||7.3|gm/dl|5.9-8.4||||F|||||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^|\r";
String json = message.convert(hl7message, engine);
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
// We expect observation because not TX in OBX
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);
List<Resource> pracResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(pracResource).hasSize(5);
}
use of org.hl7.fhir.r5.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_encounter_with_observation.
@Test
void test_encounter_with_observation() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/Patient");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Patient").withResourceModel(rsm).withSegment("PID").withIsReferenced(true).withRepeats(false).build();
HL7FHIRResourceTemplate patient = new HL7FHIRResourceTemplate(attributes);
ResourceModel encounter = ResourceReader.getInstance().generateResourceModel("resource/Encounter");
HL7FHIRResourceTemplateAttributes attributesEncounter = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Encounter").withResourceModel(encounter).withSegment("PV1").withIsReferenced(true).withRepeats(false).withAdditionalSegments(Lists.newArrayList("PV2", "OBX")).build();
HL7FHIRResourceTemplate encounterFH = new HL7FHIRResourceTemplate(attributesEncounter);
ResourceModel obsModel = ResourceReader.getInstance().generateResourceModel("resource/Observation");
HL7FHIRResourceTemplateAttributes attributesObs = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Observation").withResourceModel(obsModel).withSegment("OBX").withIsReferenced(true).withRepeats(true).build();
HL7FHIRResourceTemplate obsTemplate = new HL7FHIRResourceTemplate(attributesObs);
HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(patient, encounterFH, obsTemplate));
String hl7message = "MSH|^~\\&|SE050|050|PACS|050|20120912011230||ADT^A01|102|T|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN||201209122222\r" + "PID|0010||PID1234^5^M11^A^MR^HOSP~1234568965^^^USA^SS||DOE^JOHN^A^||19800202|F||W|111 TEST_STREET_NAME^^TEST_CITY^NY^111-1111^USA||(905)111-1111|||S|ZZ|12^^^124|34-13-312||||TEST_BIRTH_PLACE\r" + "PV1|1|ff|yyy|EL|ABC||200^ATTEND_DOC_FAMILY_TEST^ATTEND_DOC_GIVEN_TEST|201^REFER_DOC_FAMILY_TEST^REFER_DOC_GIVEN_TEST|202^CONSULTING_DOC_FAMILY_TEST^CONSULTING_DOC_GIVEN_TEST|MED|||||B6|E|272^ADMITTING_DOC_FAMILY_TEST^ADMITTING_DOC_GIVEN_TEST||48390|||||||||||||||||||||||||201409122200|20150206031726\r" + "OBX|1|NM|0135-4^TotalProtein||7.3|gm/dl|5.9-8.4||||F|||||2740^TRDSE^Janetary~2913^MRTTE^Darren^F~3065^MGHOBT^Paul^J~4723^LOTHDEW^Robert^L|\r" + "AL1|1|DRUG|00000741^OXYCODONE||HYPOTENSION\r" + "AL1|2|DRUG|00001433^TRAMADOL||SEIZURES~VOMITING\r";
String json = message.convert(hl7message, engine);
LOGGER.debug(json);
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);
List<Resource> pracResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(pracResource).hasSize(8);
List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(encounterResource).hasSize(1);
Encounter encounterRes = ResourceUtils.getResourceEncounter(encounterResource.get(0), context);
Reference patRef = encounterRes.getSubject();
assertThat(patRef.isEmpty()).isFalse();
List<Reference> obsRef = encounterRes.getReasonReference();
assertThat(obsRef).hasSize(1);
}
use of org.hl7.fhir.r5.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_messageHeader_with_ORU.
@Test
void test_messageHeader_with_ORU() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/MessageHeader");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("MessageHeader").withResourceModel(rsm).withSegment("MSH").withAdditionalSegments(Lists.newArrayList("EVN")).withIsReferenced(false).withRepeats(false).build();
HL7FHIRResourceTemplate messageHeaderTemplate = new HL7FHIRResourceTemplate(attributes);
HL7MessageModel message = new HL7MessageModel("ORU", Lists.newArrayList(messageHeaderTemplate));
String hl7message = "MSH|^~\\&|Amalga HIS|BUM|New Tester|MS|20111121103141||ORU^R01|2847970-201111211031|P|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644||01\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^Sr^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||";
String json = message.convert(hl7message, engine);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> messageHeader = e.stream().filter(v -> ResourceType.MessageHeader == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(messageHeader).hasSize(1);
MessageHeader msgH = ResourceUtils.getResourceMessageHeader(messageHeader.get(0), context);
assertThat(msgH.getId()).isNotNull();
assertThat(msgH.getEventCoding()).isNotNull();
assertThat(msgH.getEventCoding().getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0003");
assertThat(msgH.getEventCoding().getCode()).isEqualTo("R01");
assertThat(msgH.getEventCoding().getDisplay()).isEqualTo("ORU/ACK - Unsolicited transmission of an observation message");
assertThat(msgH.getDestination()).hasSize(1);
assertThat(msgH.getDestinationFirstRep().getName()).isEqualTo("New Tester");
assertThat(msgH.getDestinationFirstRep().getEndpoint()).isEqualTo("MS");
assertThat(msgH.getSource()).isNotNull();
assertThat(msgH.getSource().getName()).isEqualTo("Amalga HIS");
assertThat(msgH.getReason()).isNotNull();
assertThat(msgH.getReason().getCoding().get(0).getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0062");
assertThat(msgH.getReason().getCoding().get(0).getCode()).isEqualTo("01");
assertThat(msgH.getReason().getCoding().get(0).getDisplay()).isEqualTo("Patient request");
}
use of org.hl7.fhir.r5.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_specimen_multiple_type_coding.
@Test
void test_specimen_multiple_type_coding() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/Specimen");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Specimen").withResourceModel(rsm).withSegment("SPM").withIsReferenced(true).withRepeats(false).build();
HL7FHIRResourceTemplate observation = new HL7FHIRResourceTemplate(attributes);
HL7MessageModel message = new HL7MessageModel("ORU", Lists.newArrayList(observation));
String hl7message = "MSH|^~\\&|Amalga HIS|BUM|New Tester|MS|20111121103141||ORU^R01|2847970-201111211031|P|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^Sr^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||\r" + "OBX|1|NM|0135-4^TotalProtein||7.3|gm/dl|5.9-8.4||||F\r" + "SPM|1|SpecimenID||BLOOD^Blood^^87612001^BLOOD^SCT^^||||Cord Art^Blood, Cord Arterial^^^^^^^|||P||||||201110060535|201110060821||Y||||||1";
String json = message.convert(hl7message, engine);
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> spmResource = e.stream().filter(v -> ResourceType.Specimen == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(spmResource).hasSize(1);
Specimen spm = (Specimen) spmResource.get(0);
assertThat(spm.getType().getCoding()).hasSize(2);
}
use of org.hl7.fhir.r5.model.Observation 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/");
}
}
Aggregations