LinuxForHealth / hl7v2-fhir-converter

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

Invalid boundary reference range for lower limit #516

Open quake1997 opened 10 months ago

quake1997 commented 10 months ago

Describe the bug Generated reference range for low boundary is incorrect

To Reproduce For Cholesterol (2093-3) value >5 should determine lower limit but it's higher:

 "referenceRange" : [
          {
            "high" : {
              "value" : 5
            },
            "text" : ">5"
          }
        ]
    @Test
    void shouldCreateBundleResourceWithCorrectLowBoundaryReferenceRange() {
        //given
        var ftv = new HL7ToFHIRConverter();
        var hl7message = "MSH|^~\\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|20220101120000||ORU^R01|MSGID123456789012345|P|2.6\r" +
                "PID|1||123456||Doe^John^A^III||19700101|M|||123 Main St^^Anytown^CA^12345^USA||(555)555-5555\r" +
                "OBR|1|123456|78901234|Lipid Panel^L|||20220101110000|||||||555-44-3333^Smith^Bob^Dr.^MD^NPI987654321\r" +
                "OBX|1|NM|2093-3^Cholesterol^L|1.1|mmol/L||>5||F|||20220101113000\r";

        //when
        var res = (Bundle) context.getParser().parseResource(ftv.convert(hl7message));

        //then
        var referenceRange = res.getEntry().stream()
                                .map(Bundle.BundleEntryComponent::getResource)
                                .filter(r -> r instanceof Observation)
                                .map(Observation.class::cast)
                                .filter(o -> o.getCode().getCoding()
                                              .stream()
                                              .map(Coding::getCode)
                                              .anyMatch("2093-3"::equals))
                                .flatMap(o -> o.getReferenceRange().stream())
                                .findFirst()
                                .orElseThrow();

        assertEquals(new BigDecimal("5"), referenceRange.getLow().getValue());
    }

Expected behavior The value 5 should be lower limit not higher