use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7MergeFHIRConversionTest method validateHappyPathADT_A34WithMRG.
// Test ADT_A34 with one MRG segment (the most it supports).
@Test
void validateHappyPathADT_A34WithMRG() {
String hl7message = "MSH|^~\\&|SENDING_APPLICATION|SENDING_FACILITY|RECEIVING_APPLICATION|RECEIVING_FACILITY|||ADT^A34||P|2.3||||\r" + "EVN|A40|20110613122406637||01\r" + // Identifier value 234 with no system and no identifier type
"PID|1||123^^^^MR||||||||||||||||||||||||||||||||||||\r" + // Identifier value 456 with no system and no identifier type
"MRG|456||||||\r";
// Convert hl7 message
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
// Find the patient resources in the FHIR bundle.
List<Resource> patientResources = ResourceUtils.getResourceList(e, ResourceType.Patient);
// There should be 2 - One for the PID segment and one for the MRG segment
assertThat(patientResources).hasSize(2);
// Get first patient and associated identifiers and id.
Patient patientOne = PatientUtils.getPatientFromResource(patientResources.get(0));
String patientOneId = patientOne.getId();
List<Identifier> patientOneIdentifierList = patientOne.getIdentifier();
// Get second patient and associated identifiers and id.
Patient patientTwo = PatientUtils.getPatientFromResource(patientResources.get(1));
String patientTwoId = patientTwo.getId();
List<Identifier> patientTwoIdentifierList = patientTwo.getIdentifier();
/*-----------Verify Patient One-----------*/
// Verify patient one's identifier is set correctly (this is the patient build
// from the PID segment)
//
// "identifier":[
// {
// "type":{
// "coding":[
// {
// "system":"http://terminology.hl7.org/CodeSystem/v2-0203",
// "code":"MR",
// "display":"Medical record number"
// }
// ]
// },
// "value":"123"
// },
// {
// "use":"old",
// "value":"456"
// }
// ]
// Verify the patient has two identifiers
assertThat(patientOneIdentifierList).hasSize(2);
// Verify the identifier values are correct.
assertThat(patientOneIdentifierList.get(0).getValue()).isEqualTo("123");
assertThat(patientOneIdentifierList.get(1).getValue()).isEqualTo("456");
// Verify the system values are not present
assertThat(patientOneIdentifierList.get(0).getSystem()).isNull();
assertThat(patientOneIdentifierList.get(1).getSystem()).isNull();
// Verify the first identifier has no use field.
assertThat(patientOneIdentifierList.get(0).getUse()).isNull();
// Verify the second identifier is marked as old
assertThat(patientOneIdentifierList.get(1).getUse()).isEqualTo(Identifier.IdentifierUse.OLD);
// Verify identifier type is set correctly for the first identifier
CodeableConcept patientOneIdentifierType = patientOneIdentifierList.get(0).getType();
assertThat(patientOneIdentifierType.getCoding().get(0).getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0203");
assertThat(patientOneIdentifierType.getCoding().get(0).getDisplay()).isEqualTo("Medical record number");
assertThat(patientOneIdentifierType.getCoding().get(0).getCode()).isEqualTo("MR");
// Verify the identifier type for the second identifier is not present.
assertThat(patientOneIdentifierList.get(1).getType().getCoding()).isEmpty();
// Verify first patient has these fields
//
// "active":true,
// "link":[
// {
// "other":{
// "reference":"Patient/expiringID-MRG"
// },
// "type":"replaces"
// }
// ]
// The first patient should be active.
assertThat(patientOne.getActive()).isTrue();
// Verify link.other.reference references the MRG (2nd) patient with of a type of 'replaces'
PatientLinkComponent linkOne = patientOne.getLink().get(0);
assertThat(linkOne.getType()).isEqualTo(Patient.LinkType.REPLACES);
assertThat(linkOne.getOther().getReference()).isEqualTo(patientTwoId);
/*-----------Verify Patient Two-----------*/
// Verify patient two's identifier is set correctly (this is the patient build
// from the MRG segment)
//
// "identifier":[
// {
// "use":"old",
// "value":"456"
// }
// ]
// Verify has only 1 identifier
assertThat(patientTwoIdentifierList).hasSize(1);
// Verify the identifier value is correct.
assertThat(patientTwoIdentifierList.get(0).getValue()).isEqualTo("456");
// Verify the system is not present
assertThat(patientTwoIdentifierList.get(0).getSystem()).isNull();
// Verify the identifier is marked as old
assertThat(patientTwoIdentifierList.get(0).getUse()).isEqualTo(Identifier.IdentifierUse.OLD);
// Verify identifier type is not present
assertThat(patientTwoIdentifierList.get(0).getType().getCoding()).isEmpty();
// Verify second patient has these fields.
// "active":false,
// "link":[
// {
// "other":{
// "reference":"Patient/survivingID"
// },
// "type":"replaced-by"
// }
// ]
// The second patient should NOT be active.
assertThat(patientTwo.getActive()).isFalse();
// We should have link.other.reference to the PID (1st) patient with a type of 'replaced-by'
PatientLinkComponent linkTwo = patientTwo.getLink().get(0);
assertThat(linkTwo.getType()).isEqualTo(Patient.LinkType.REPLACEDBY);
assertThat(linkTwo.getOther().getReference()).isEqualTo(patientOneId);
;
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent 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);
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent 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.dstu2016may.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_specimen_multiple.
@Test
void test_specimen_multiple() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/Specimen");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Specimen").withResourceModel(rsm).withSegment("SPM").withIsReferenced(true).withRepeats(true).build();
HL7FHIRResourceTemplate specimen = new HL7FHIRResourceTemplate(attributes);
HL7MessageModel message = new HL7MessageModel("ORU", Lists.newArrayList(specimen));
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|TX|1234||First line: ECHOCARDIOGRAPHIC REPORT||||||F|||||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^|\r" + "SPM|1|SpecimenID||BLOOD^Blood^^87612001^BLOOD^SCT^^||||Cord Art^Blood, Cord Arterial^^^^^^^|||P||||||201110060535|201110060821||Y||||||1\r" + "SPM|2|SpecimenID||BLD|||||||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(2);
}
use of org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent 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);
}
Aggregations