LinuxForHealth / hl7v2-fhir-converter

Converts HL7 v2 Messages to FHIR Resources
Apache License 2.0
89 stars 36 forks source link

Fix null value (my particular example was in OBX.5) #61

Closed CyloNox closed 3 years ago

CyloNox commented 3 years ago

I've updated this issue after finding where the problem in the code is, here is the line that errors out when OBX.5 has no value (being null): https://github.com/LinuxForHealth/hl7v2-fhir-converter/blob/4b281dd61782d92efe6b38f26e47257e80018f1f/src/main/java/io/github/linuxforhealth/hl7/data/Hl7DataHandlerUtil.java#L95

Here is a sample line of what I'm talking about in the HL7 where the OBX.5 has no value: "OBX|1|ST|14151-5^HCO3 BldCo-sCnc^LN|TEST|||||||F|||20210311122016|||||20210311122153||||"

A nullPointer error will trigger when that happens so I made a change in the Hl7DataHandlerUtil.java file: FROM returnvalue = local.toString(); TO returnvalue = local == null ? "" : local.toString();

I also added a unit test to check for this in DifferentObservationValueTest.java : @Test public void test_observation_ST_null_result() throws IOException {

String hl7message = baseMessage
        + "OBX|1|ST|14151-5^HCO3 BldCo-sCnc^LN|TEST|||||||F|||20210311122016|||||20210311122153||||";
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> obsResource =
        e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType())
                .map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
assertThat(obs.getValueStringType()).isNotNull();
StringType q = obs.getValueStringType();
assertThat(q.asStringValue())
        .isEqualTo(null);

}

pbhallam commented 3 years ago

Fixed

cragun47 commented 3 years ago

In Release 1.0.8