use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.
the class ResourceUtils method createFHIRBundleFromHL7MessageReturnEntryList.
public static List<BundleEntryComponent> createFHIRBundleFromHL7MessageReturnEntryList(HL7ToFHIRConverter ftv, String inputSegment, ConverterOptions options) {
String json = ftv.convert(inputSegment, options);
assertThat(json).isNotBlank();
LOGGER.debug("FHIR json result:\n" + json);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
return e;
}
use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method test_adt_40_message.
@Test
// Test an example of a message with no message structure specifed
void test_adt_40_message() throws Exception {
Message hl7message = null;
// Test that an ADT A40 message with no MSH-9.3 is successfully parsed and converted.
String hl7messageString = "MSH|^~\\&|REGADT|MCM|RSP1P8|MCM|200301051530|SEC|ADT^A40|00000003|P|2.6\n" + "PID|||MR1^^^XYZ||MAIDENNAME^EVE\n" + "MRG|MR2^^^XYZ\n";
InputStream ins = IOUtils.toInputStream(hl7messageString, StandardCharsets.UTF_8);
Hl7InputStreamMessageStringIterator iterator = new Hl7InputStreamMessageStringIterator(ins);
if (iterator.hasNext()) {
HL7HapiParser hparser = new HL7HapiParser();
hl7message = hparser.getParser().parse(iterator.next());
}
String messageType = HL7DataExtractor.getMessageType(hl7message);
assertThat(messageType).isEqualTo("ADT_A40");
// Convert and check for a patient resource
String json = ftv.convert(hl7messageString, ConverterOptions.SIMPLE_OPTIONS);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
assertThat(b.getId()).isNotNull();
assertThat(b.getMeta().getLastUpdated()).isNotNull();
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(2);
}
use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method verifyResult.
private void verifyResult(String json, BundleType expectedBundleType, boolean messageHeaderExpected) {
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(expectedBundleType);
assertThat(b.getId()).isNotNull();
assertThat(b.getMeta().getLastUpdated()).isNotNull();
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);
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
// No Observation resource because OBX.2 is type TX
assertThat(obsResource).isEmpty();
List<Resource> pracResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(pracResource).hasSize(4);
List<Resource> allergyResources = e.stream().filter(v -> ResourceType.AllergyIntolerance == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(allergyResources).hasSize(2);
if (messageHeaderExpected) {
List<Resource> messageHeader = e.stream().filter(v -> ResourceType.MessageHeader == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(messageHeader).hasSize(1);
}
}
use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method testCodingSystems.
@Test
/*
* This tests some of coding systems of interest or potential problems
*/
void testCodingSystems() throws FHIRException {
String hl7VUXmessageRep = "MSH|^~\\&|MYEHR2.5|RI88140101|KIDSNET_IFL|RIHEALTH|201305330||VXU^V04^VXU_V04|20130531RI881401010105|P|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644||01\r" + "PID|1||12345678^^^MYEMR^MR||TestPatient^John|||M|\r" + "ORC|RE||197027|||||||^Clerk^Myron||MD67895^Pediatric^MARY^^^^MD^^RIA|||||RI2050\r" + // Test MVX
"RXA|0|1|20130528|20130529|48^HIB PRP-T^CVX|0.5|ML^^ISO+||00^new immunization record^NIP001|^Sticker^Nurse|^^^RI2050||||33k2a|20131210|PMC^sanofi^MVX|||CP|A\r" + // Test HL70162 & HL70163
"RXR|C28161^IM^NCIT^IM^INTRAMUSCULAR^HL70162|RT^right thigh^HL70163\r";
String json = ftv.convert(hl7VUXmessageRep, OPTIONS);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
assertThat(b.getId()).isNotNull();
List<BundleEntryComponent> e = b.getEntry();
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Immunization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);
Immunization immunization = (Immunization) obsResource.get(0);
// Check that organization identifier (MVX) has a system
Organization org = (Organization) immunization.getManufacturer().getResource();
List<Identifier> li = org.getIdentifier();
Identifier ident = li.get(0);
assertThat(ident.hasSystem()).isTrue();
assertThat(ident.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/MVX");
assertThat(ident.hasValue()).isTrue();
assertThat(ident.getValue()).isEqualTo("PMC");
// Check that route (HL70162) has a system
CodeableConcept route = immunization.getRoute();
assertThat(route.hasCoding()).isTrue();
List<Coding> codings = route.getCoding();
assertThat(codings.size()).isEqualTo(2);
Coding coding = codings.get(0);
// If the first one is not the one we want look at the second one.
if (coding.getCode().contains("C28161")) {
coding = codings.get(1);
}
assertThat(coding.hasSystem()).isTrue();
assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0162");
// Check that site (HL70163) has a system
CodeableConcept site = immunization.getSite();
coding = site.getCodingFirstRep();
assertThat(coding.hasSystem()).isTrue();
assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0163");
}
use of io.github.linuxforhealth.fhir.FHIRContext in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method test_adt_40_message_with_adt_a39_structure_specified.
@Test
// Test an example of a message with message structure specified
void test_adt_40_message_with_adt_a39_structure_specified() throws Exception {
Message hl7message = null;
// Test that an ADT A40 message with MSH-9.3 of 'ADT_A39' is successfully parsed and converted as an ADT A40 message.
// Note that ADT_A39 is the expected structure of an ADT_A40 message.
String hl7messageString = "MSH|^~\\&|REGADT|MCM|RSP1P8|MCM|200301051530|SEC|ADT^A40^ADT_A39|00000003|P|2.6\n" + "PID|||MR1^^^XYZ||MAIDENNAME^EVE\n" + "MRG|MR2^^^XYZ\n";
InputStream ins = IOUtils.toInputStream(hl7messageString, StandardCharsets.UTF_8);
Hl7InputStreamMessageStringIterator iterator = new Hl7InputStreamMessageStringIterator(ins);
if (iterator.hasNext()) {
HL7HapiParser hparser = new HL7HapiParser();
hl7message = hparser.getParser().parse(iterator.next());
}
String messageType = HL7DataExtractor.getMessageType(hl7message);
assertThat(messageType).isEqualTo("ADT_A40");
// Convert and check for a patient resource
String json = ftv.convert(hl7messageString, ConverterOptions.SIMPLE_OPTIONS);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
assertThat(b.getId()).isNotNull();
assertThat(b.getMeta().getLastUpdated()).isNotNull();
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(2);
}
Aggregations