Search in sources :

Example 81 with BundleEntryComponent

use of org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent 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 82 with BundleEntryComponent

use of org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ObservationFHIRConversionTest method testObservationSN_valueRatio_slash_result.

@Test
void testObservationSN_valueRatio_slash_result() throws IOException {
    String hl7message = baseMessage + "OBX|1|SN|111^LabWithRatio||^2^/^3|";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    assertTrue(obs.hasValueRatio());
    Ratio r = obs.getValueRatio();
    assertEquals(2f, r.getNumerator().getValue().floatValue());
    assertEquals(3f, r.getDenominator().getValue().floatValue());
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Ratio(org.hl7.fhir.r4.model.Ratio) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 83 with BundleEntryComponent

use of org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ObservationFHIRConversionTest method testObservationStNullResult.

@Test
void testObservationStNullResult() throws IOException {
    String hl7message = baseMessage + "OBX|1|ST|14151-5^HCO3 BldCo-sCnc^LN|TEST|||||||F|||20210311122016|||||20210311122153||||";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    assertThat(obs.getValueStringType()).isNotNull();
    StringType q = obs.getValueStringType();
    assertThat(q.asStringValue()).isNull();
    // Check the coding  (OBX.3)
    assertThat(obs.hasCode()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getCode(), "14151-5", "HCO3 BldCo-sCnc", "http://loinc.org", "HCO3 BldCo-sCnc");
    // Check the effective Date Time  (OBX 14)
    assertThat(obs.hasEffective()).isTrue();
    assertThat(obs.hasEffectiveDateTimeType()).isTrue();
    assertThat(obs.getEffectiveDateTimeType().asStringValue()).isEqualTo("2021-03-11T12:20:16+08:00");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) StringType(org.hl7.fhir.r4.model.StringType) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 84 with BundleEntryComponent

use of org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent 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 85 with BundleEntryComponent

use of org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent 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)

Aggregations

BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)265 Resource (org.hl7.fhir.r4.model.Resource)167 Test (org.junit.jupiter.api.Test)126 Bundle (org.hl7.fhir.r4.model.Bundle)116 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)96 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)88 ArrayList (java.util.ArrayList)67 Date (java.util.Date)52 Reference (org.hl7.fhir.r4.model.Reference)52 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)51 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)42 Patient (org.hl7.fhir.r4.model.Patient)37 IOException (java.io.IOException)36 Observation (org.hl7.fhir.r4.model.Observation)36 Test (org.junit.Test)35 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)34 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)33 Condition (org.hl7.fhir.r4.model.Condition)32 HashMap (java.util.HashMap)31 Encounter (org.hl7.fhir.r4.model.Encounter)31