use of org.hl7.fhir.r4.model.Patient 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.r4.model.Patient 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.r4.model.Patient in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_patient.
@Test
void test_patient() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/Patient");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Patient").withResourceModel(rsm).withSegment("PID").withIsReferenced(false).withRepeats(false).build();
HL7FHIRResourceTemplate patient = new HL7FHIRResourceTemplate(attributes);
HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(patient));
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|||||||||";
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> patientResource = e.stream().filter(v -> ResourceType.Patient == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(patientResource).hasSize(1);
}
use of org.hl7.fhir.r4.model.Patient in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_patient_encounter.
@Test
void test_patient_encounter() 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")).build();
HL7FHIRResourceTemplate encounterFH = new HL7FHIRResourceTemplate(attributesEncounter);
HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(patient, encounterFH));
String hl7message = "MSH|^~\\&|SE050|050|PACS|050|201209121212||ADT^A01|102|T|2.7|||AL|NE\r" + "EVN||201209122222\r" + "PID|||1234^^^^SR^20021212^20200120~1234-12^^^^LR^~3872^^^^MR~221345671^^^^SS^~430078856^^^^MA^||KENNEDY^JOHN^FITZGERALD^JR^^^L| BOUVIER^^^^^^M|19900607|M|KENNEDY^BABYBOY^^^^^^B|2106-3^linuxforhealthTE^HL70005|123 MAIN ST^APT 3B^LEXINGTON^MA^00210^^M^MSA CODE^MA034~345 ELM\r" + "PV1|1|ff|yyy|EL|||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|20000206031726\r" + "AL1|0001|DA|98798^problem|SV|sneeze|20120808\r";
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> patientResource = e.stream().filter(v -> ResourceType.Patient == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(patientResource).hasSize(1);
List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(encounterResource).hasSize(1);
Encounter enc = ResourceUtils.getResourceEncounter(encounterResource.get(0), context);
Reference ref = enc.getSubject();
assertThat(ref.isEmpty()).isFalse();
}
use of org.hl7.fhir.r4.model.Patient 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");
}
Aggregations