From 0dce215c98e2594e5e6d6ef9d4943770496a6fd5 Mon Sep 17 00:00:00 2001 From: Clement Hennequin Date: Tue, 5 Nov 2024 14:29:44 -0500 Subject: [PATCH] Iis Ack builder copied and customized from MQE to configure MSA.1 with new codes --- .../iis/kernal/logic/IisAckBuilder.java | 164 ++++++++++++++++++ .../kernal/logic/IncomingMessageHandler.java | 6 +- .../iis/kernal/model/ProcessingFlavor.java | 2 +- 3 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/immregistries/iis/kernal/logic/IisAckBuilder.java diff --git a/src/main/java/org/immregistries/iis/kernal/logic/IisAckBuilder.java b/src/main/java/org/immregistries/iis/kernal/logic/IisAckBuilder.java new file mode 100644 index 00000000..87d64120 --- /dev/null +++ b/src/main/java/org/immregistries/iis/kernal/logic/IisAckBuilder.java @@ -0,0 +1,164 @@ +package org.immregistries.iis.kernal.logic; + +import org.immregistries.mqe.hl7util.Reportable; +import org.immregistries.mqe.hl7util.SeverityLevel; +import org.immregistries.mqe.hl7util.builder.AckData; +import org.immregistries.mqe.hl7util.builder.AckResult; +import org.immregistries.mqe.hl7util.builder.HL7Util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Taken from Mqe-util AckBuilder to allow introduction of new codes + */ +public enum IisAckBuilder { + INSTANCE; + public static final String PROCESSING_ID_DEBUG = "D"; + + public String buildAckFrom(AckData ackDataIn) { + + String controlId = ackDataIn.getMessageControlId(); + String processingId = ackDataIn.getProcessingControlId(); + AckResult ackCode = AckResult.APP_ACCEPT; + String hl7ErrorCode = "0"; + if (hasErrors(ackDataIn)) { + ackCode = AckResult.APP_ERROR; + for (Reportable r : ackDataIn.getReportables()) { + if (r.getSeverity() == SeverityLevel.ERROR && r.getHl7ErrorCode() != null + && r.getHl7ErrorCode().getIdentifier() != null) { + hl7ErrorCode = r.getHl7ErrorCode().getIdentifier(); + if (hl7ErrorCode != null && hl7ErrorCode.startsWith("2")) { + ackCode = AckResult.APP_REJECT; + break; + } + } + } + } + StringBuilder ack = new StringBuilder(); + makeHeader(ack, ackDataIn, "Z23", null); + // ack.append("SFT|" + SoftwareVersion.VENDOR + "|" + + // SoftwareVersion.VERSION + "|" + SoftwareVersion.PRODUCT + "|" + + // SoftwareVersion.BINARY_ID + // + "|\r"); + ack.append("MSA|" + ackCode.getCode() + "|" + controlId + "|\r"); + for (Reportable r : ackDataIn.getReportables()) { + if (r.getSeverity() == SeverityLevel.ERROR) { + ack.append(HL7Util.makeERRSegment(r, PROCESSING_ID_DEBUG.equals(processingId))); + } + } + for (Reportable r : ackDataIn.getReportables()) { + if (r.getSeverity() == SeverityLevel.WARN) { + ack.append(HL7Util.makeERRSegment(r, PROCESSING_ID_DEBUG.equals(processingId))); + } + } + for (Reportable r : ackDataIn.getReportables()) { + if (r.getSeverity() == SeverityLevel.INFO) { + ack.append(HL7Util.makeERRSegment(r, PROCESSING_ID_DEBUG.equals(processingId))); + } + } + if (PROCESSING_ID_DEBUG.equals(processingId)) { + for (Reportable r : ackDataIn.getReportables()) { + if (r.getSeverity() == SeverityLevel.ACCEPT) { + ack.append(HL7Util.makeERRSegment(r, PROCESSING_ID_DEBUG.equals(processingId))); + } + } + } + return ack.toString(); + } + +// public static void makeERRSegment(StringBuilder ack, String severity, String hl7ErrorCode, String textMessage, Reportable reportable) +// { +// +// if (severity.equals("E") && StringUtils.isBlank(hl7ErrorCode)) +// { +// hl7ErrorCode = "102"; +// } +// ack.append("ERR||"); +// // 2 Error Location +// ack.append("|" + reportable.getHl7LocationList()); +// // 3 HL7 Error Code +// HL7Util.appendErrorCode(ack, reportable.getHl7ErrorCode()); +// ack.append("|"); +// // 4 Severity +// ack.append(severity); +// ack.append("|"); +// // 5 Application Error Code +// HL7Util.appendAppErrorCode(ack, reportable); +// ack.append("|"); +// // 6 Application Error Parameter +// ack.append("|"); +// // 7 Diagnostic Information +// ack.append("|"); +// // 8 User Message +// ack.append(HL7Util.escapeHL7Chars(reportable.getReportedMessage())); +// ack.append("|\r"); +// +// } + + private static boolean hasErrors(AckData ackDataIn) { + for (Reportable reportable : ackDataIn.getReportables()) { + if (reportable.getSeverity() == SeverityLevel.ERROR) { +// reportable.getSeverity() == SeverityLevel.WARN) { + return true; + } + } + return false; + } + + public static void makeHeader(StringBuilder ack, AckData ackDataIn, String profileId, + String responseType) { + String receivingApplication = ackDataIn.getSendingApplication(); + String receivingFacility = ackDataIn.getSendingFacility(); + String sendingApplication = ackDataIn.getReceivingApplication(); + String sendingFacility = ackDataIn.getReceivingFacility(); + if (receivingApplication == null) { + receivingApplication = ""; + } + if (receivingFacility == null) { + receivingFacility = ""; + } + if (sendingApplication == null || sendingApplication.equals("")) { + sendingApplication = "MCIR"; + } + if (sendingFacility == null || sendingFacility.equals("")) { + sendingFacility = "MCIR"; + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssZ"); + String messageDate = sdf.format(new Date()); + // MSH + ack.append("MSH|^~\\&"); + ack.append("|" + sendingApplication); // MSH-3 Sending Application + ack.append("|" + sendingFacility); // MSH-4 Sending Facility + ack.append("|" + receivingApplication); // MSH-5 Receiving Application + ack.append("|" + receivingFacility); // MSH-6 Receiving Facility + ack.append("|" + messageDate); // MSH-7 Date/Time of Message + ack.append("|"); // MSH-8 Security + if (responseType == null) { + responseType = "ACK^V04^ACK"; + } + ack.append("|" + responseType); // MSH-9 + // Message + // Type + ack.append("|" + messageDate + "." + getNextAckCount()); // MSH-10 Message + // Control ID + ack.append("|P"); // MSH-11 Processing ID + ack.append("|2.5.1"); // MSH-12 Version ID + ack.append("|"); + if (profileId != null) { + ack.append("||NE|NE|||||" + profileId + "^CDCPHINVS|"); + } + ack.append("\r"); + + } + + private static int ackCount = 1; + + public static synchronized int getNextAckCount() { + if (ackCount == Integer.MAX_VALUE) { + ackCount = 1; + } + return ackCount++; + } + +} diff --git a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandler.java b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandler.java index 91c0db6e..e4cdcfa7 100644 --- a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandler.java +++ b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandler.java @@ -32,7 +32,6 @@ import org.immregistries.iis.kernal.servlet.PopServlet; import org.immregistries.mqe.hl7util.Reportable; import org.immregistries.mqe.hl7util.SeverityLevel; -import org.immregistries.mqe.hl7util.builder.AckBuilder; import org.immregistries.mqe.hl7util.builder.AckData; import org.immregistries.mqe.hl7util.builder.HL7Util; import org.immregistries.mqe.hl7util.model.CodedWithExceptions; @@ -57,6 +56,9 @@ import java.util.stream.Collectors; public abstract class IncomingMessageHandler implements IIncomingMessageHandler { + /** + * DYNAMIC VALUE SETS for validation + */ public MqeMessageService mqeMessageService; protected final Logger logger = LoggerFactory.getLogger(IncomingMessageHandler.class); @@ -225,7 +227,7 @@ public String buildAck(HL7Reader reader, List processingExc } public String buildAckMqe(MqeMessageServiceResponse mqeMessageServiceResponse, List processingExceptionList, Set processingFlavorSet, List validatorReportables) { - AckBuilder ackBuilder = AckBuilder.INSTANCE; + IisAckBuilder ackBuilder = IisAckBuilder.INSTANCE; AckData data = new AckData(); MqeMessageHeader header = mqeMessageServiceResponse.getMessageObjects().getMessageHeader(); data.setProfileId(Z23_ACKNOWLEDGEMENT); diff --git a/src/main/java/org/immregistries/iis/kernal/model/ProcessingFlavor.java b/src/main/java/org/immregistries/iis/kernal/model/ProcessingFlavor.java index a0b883b0..50f94da7 100644 --- a/src/main/java/org/immregistries/iis/kernal/model/ProcessingFlavor.java +++ b/src/main/java/org/immregistries/iis/kernal/model/ProcessingFlavor.java @@ -62,7 +62,7 @@ public static Set getProcessingStyle(String label) { || label.indexOf("_" + key + "_") > 0) { processingFlavorSet.add(ps); } else if (label.equals(key)) { - processingFlavorSet.add(ps); +// processingFlavorSet.add(ps); } } }