From b996fed0370560825bc0cf3fbf2c1c8e3fe06023 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 17 Dec 2024 12:46:01 -0500 Subject: [PATCH] Add "realistic" test and fix handling of string-coded systemless results --- .../api/hl7/handler/OruR01Handler.java | 21 +++++++++---------- .../api/hl7/handler/OruR01HandlerTest.java | 21 +++++++++++++++++++ api/src/test/resources/lab-dataset.xml | 15 +++++++++++++ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01Handler.java b/api/src/main/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01Handler.java index 336b77e..ad30cad 100644 --- a/api/src/main/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01Handler.java +++ b/api/src/main/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01Handler.java @@ -95,7 +95,7 @@ public Message processMessage(Message message) throws ApplicationException, HL7E return response; } catch (ClassCastException ex) { - LOGGER.warn("Error casting " + message.getClass().getName() + " to ORU_R01", ex); + LOGGER.warn("Error casting {} to ORU_R01", message.getClass().getName(), ex); throw new ApplicationException(Context.getMessageSourceService().getMessage("ORUR01.error.invalidMessageType ", new Object[] { message.getClass().getName() }, null), ex); } @@ -104,7 +104,7 @@ public Message processMessage(Message message) throws ApplicationException, HL7E throw new ApplicationException(Context.getMessageSourceService().getMessage("ORUR01.error.WhileProcessing"), ex); } catch (Exception e) { - LOGGER.error("Could not process message!\n" + e.getMessage()); + LOGGER.error("Could not process message! {}", e.getMessage(), e); } return null; @@ -137,7 +137,7 @@ private Message processOruR01(ORU_R01 message) throws HL7Exception, ApplicationE ORU_R01_PATIENT_RESULT patientResult = message.getPATIENT_RESULT(); int numObr = patientResult.getORDER_OBSERVATIONReps(); - LOGGER.debug("Patient result {}", patientResult.toString()); + LOGGER.debug("Patient result {}", patientResult); LOGGER.debug("# Observation results returned {}", numObr); PV1 pv1 = patientResult.getPATIENT().getVISIT().getPV1(); LOGGER.debug("PV1 Time {}", pv1.getAdmitDateTime().getTime()); @@ -149,10 +149,8 @@ private Message processOruR01(ORU_R01 message) throws HL7Exception, ApplicationE LOGGER.debug("Alternate Visit Id - Identifier type code {}", pv1.getAlternateVisitID() .getCx5_IdentifierTypeCode().getValue()); for (int i = 0; i < numObr; i++) { - - LOGGER.debug("Processing OBR {}", i); - LOGGER.debug(" of {}", numObr); - + LOGGER.debug("Processing OBR {} of {}", i + 1, numObr); + ORU_R01_ORDER_OBSERVATION orderObs = patientResult.getORDER_OBSERVATION(i); OBR obr = orderObs.getOBR(); // OBR values @@ -271,14 +269,15 @@ protected Concept getConcept(String hl7ConceptId, String codingSystem, String ui try { conceptId = Integer.valueOf(hl7ConceptId); } catch (NumberFormatException e) { - if (hl7ConceptId.equals("D??tect??")) { + if (hl7ConceptId.equals("Détecté")) { LOGGER.info("this is the value text 2 : " + hl7ConceptId); conceptId = Integer.valueOf(DETECTED_CODED_VALUE); - } else if (hl7ConceptId.equals("Non-D??tect??")) { + } else if (hl7ConceptId.equals("Non-Détecté")) { LOGGER.info("this is the value text 3 : " + hl7ConceptId); conceptId = Integer.valueOf(NOT_DETECTED_CODED_VALUE); - } - } + } + } + return Context.getConceptService().getConcept(conceptId); } else { // the concept is not local, look it up in our mapping diff --git a/api/src/test/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01HandlerTest.java b/api/src/test/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01HandlerTest.java index 826b170..fa27f21 100644 --- a/api/src/test/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01HandlerTest.java +++ b/api/src/test/java/org/openmrs/module/labintegration/api/hl7/handler/OruR01HandlerTest.java @@ -50,4 +50,25 @@ public void processMessage_shouldParseObsAndNotReturnNull() throws HL7Exception, Message message1 = oruR01Handler.processMessage(message); assertNotNull(message); } + + @Test + public void processMessage_shouldProcessMessageToObs() throws Exception { + executeDataSet(DATASET); + + String hl7Message = "MSH|^~\\&|||||20241216090516-0500||ORU^R01|00000000|P|2.5\n" + + "PID||33118500^^^^MR^112123|33118500^^^^MR^112123||WASHINGTONN^GLENN||20000601|M||U|^4èME LA MONTAGNE^JEAN RABEL^NRO|||||||^7a732da7-f3a8-40fe-b9eb-c8a058de9497\n" + + "PV1||R|11223||||11223^OPAP^PRESTATAIRE^^^^^^^^^^L||||||||||^^^^^^^^^^^^L|||||||||||||||||||||||||||20241216||||||290fb4d0-2ae6-40bd-a058-436acea3d881^f037e97b-471e-4898-a07c-b8e169e0ddc4^^b181ab58-e4fb-4b47-bc69-f0c05dd473cd^7a732da7-f3a8-40fe-b9eb-c8a058de9497\n" + + "ORC|RE|11223-53-440|1|C8160001|||^^^202412160558-0500^^R||202412160558|HISTC||11223^OPAP^PRESTATAIRE^^^^^^^^^^L|11223\n" + + "OBR|1|11223-53-440|1|f037e97b-471e-4898-a07c-b8e169e0ddc4|||202412160558|||HISTC|N|||202412160600||11223^OPAP^PRESTATAIRE^^^^^^^^^^L||||||202412160905-0500|||F||^^^202412160558-0500^^R|||||||DIG\n" + + "OBX|1|CE|44871-2^^LN^LVH2P^ADN VIH-1, PCR-2^L|0|Détecté|||*|||F|||202412160601||DIG|||202412160905"; + hl7Message = hl7Message.replaceFirst(ORUR01_ORU_R01, ORU_R01); + hl7Message = hl7Message.replaceFirst(VERSION_251, VERSION_25); + hl7Message = hl7Message.replace("\n", Character.toString((char) 13)); + hl7Message = hl7Message.replaceAll("\\[[0-9]{4}\\]", ""); + + Message message = new PipeParser().parse(hl7Message); + OruR01Handler oruR01Handler = new OruR01Handler(); + + Message ack = oruR01Handler.processMessage(message); + } } diff --git a/api/src/test/resources/lab-dataset.xml b/api/src/test/resources/lab-dataset.xml index 9caf63b..75a5f30 100644 --- a/api/src/test/resources/lab-dataset.xml +++ b/api/src/test/resources/lab-dataset.xml @@ -67,6 +67,14 @@ concept_id="162929" uuid="278664ABBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_map_type_id="1" creator="1" date_created="2005-01-06 00:00:00"/> + + + + @@ -184,5 +192,12 @@ location_id="2" uuid="549c78dc-31da-11e8-acac-c3add5b19973"/> + +