Search in sources :

Example 6 with FHIRContext

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;
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 7 with FHIRContext

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);
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Message(ca.uhn.hl7v2.model.Message) Hl7InputStreamMessageStringIterator(ca.uhn.hl7v2.util.Hl7InputStreamMessageStringIterator) HL7HapiParser(io.github.linuxforhealth.hl7.parsing.HL7HapiParser) InputStream(java.io.InputStream) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Example 8 with FHIRContext

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);
    }
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 9 with FHIRContext

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");
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Immunization(org.hl7.fhir.r4.model.Immunization) Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 10 with FHIRContext

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);
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Message(ca.uhn.hl7v2.model.Message) Hl7InputStreamMessageStringIterator(ca.uhn.hl7v2.util.Hl7InputStreamMessageStringIterator) HL7HapiParser(io.github.linuxforhealth.hl7.parsing.HL7HapiParser) InputStream(java.io.InputStream) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Aggregations

FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)14 Bundle (org.hl7.fhir.r4.model.Bundle)14 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)13 Resource (org.hl7.fhir.r4.model.Resource)12 Test (org.junit.jupiter.api.Test)10 Coding (org.hl7.fhir.r4.model.Coding)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)3 Encounter (org.hl7.fhir.r4.model.Encounter)3 Observation (org.hl7.fhir.r4.model.Observation)3 Message (ca.uhn.hl7v2.model.Message)2 Hl7InputStreamMessageStringIterator (ca.uhn.hl7v2.util.Hl7InputStreamMessageStringIterator)2 HL7HapiParser (io.github.linuxforhealth.hl7.parsing.HL7HapiParser)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Attachment (org.hl7.fhir.r4.model.Attachment)2 Base (org.hl7.fhir.r4.model.Base)2 Immunization (org.hl7.fhir.r4.model.Immunization)2 Reference (org.hl7.fhir.r4.model.Reference)2