Skip to content

Commit

Permalink
Ack support for configurability by integrating and overriding MQEUtil ok
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbeor committed Nov 15, 2024
1 parent 08546ae commit 9578cdb
Show file tree
Hide file tree
Showing 9 changed files with 644 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
import org.immregistries.iis.kernal.SoftwareVersion;
import org.immregistries.iis.kernal.fhir.interceptors.PartitionCreationInterceptor;
import org.immregistries.iis.kernal.fhir.security.ServletHelper;
import org.immregistries.iis.kernal.logic.ack.*;
import org.immregistries.iis.kernal.mapping.Interfaces.ImmunizationMapper;
import org.immregistries.iis.kernal.mapping.Interfaces.LocationMapper;
import org.immregistries.iis.kernal.mapping.Interfaces.ObservationMapper;
import org.immregistries.iis.kernal.mapping.Interfaces.PatientMapper;
import org.immregistries.iis.kernal.model.*;
import org.immregistries.iis.kernal.servlet.PopServlet;
import org.immregistries.mqe.hl7util.Reportable;
import org.immregistries.mqe.hl7util.ReportableSource;
import org.immregistries.mqe.hl7util.SeverityLevel;
import org.immregistries.mqe.hl7util.builder.AckData;
import org.immregistries.mqe.hl7util.builder.HL7Util;
import org.immregistries.mqe.hl7util.model.CodedWithExceptions;
import org.immregistries.mqe.hl7util.model.Hl7Location;
import org.immregistries.mqe.validator.MqeMessageService;
Expand Down Expand Up @@ -226,23 +225,23 @@ public String buildAck(HL7Reader reader, List<ProcessingException> processingExc

sb.append("MSA|").append(overallStatus).append("|").append(sendersUniqueId).append("\r");
for (ProcessingException pe : processingExceptionList) {
sb.append(HL7Util.makeERRSegment(new ProcessingExceptionReportable(pe), false));
sb.append(IisHL7Util.makeERRSegment(new IisReportable(pe), false));
}
return sb.toString();
}

public String buildAckMqe(MqeMessageServiceResponse mqeMessageServiceResponse, List<ProcessingException> processingExceptionList, Set<ProcessingFlavor> processingFlavorSet, List<Reportable> validatorReportables) {
public String buildAckMqe(MqeMessageServiceResponse mqeMessageServiceResponse, List<ProcessingException> processingExceptionList, Set<ProcessingFlavor> processingFlavorSet, List<IisReportable> validatorReportables) {
IisAckBuilder ackBuilder = IisAckBuilder.INSTANCE;
AckData data = new AckData();
IisAckData data = new IisAckData();
MqeMessageHeader header = mqeMessageServiceResponse.getMessageObjects().getMessageHeader();
data.setProfileId(Z23_ACKNOWLEDGEMENT);

List<ValidationRuleResult> resultList = mqeMessageServiceResponse.getValidationResults();
List<Reportable> reportables = new ArrayList<>(validatorReportables);
reportables.addAll(processingExceptionList.stream().map(ProcessingExceptionReportable::new).collect(Collectors.toList()));
List<IisReportable> reportables = new ArrayList<>(validatorReportables);
reportables.addAll(processingExceptionList.stream().map(IisReportable::new).collect(Collectors.toList()));
/* This code needs to get put somewhere better. */
for (ValidationRuleResult result : resultList) {
reportables.addAll(result.getValidationDetections());
reportables.addAll(result.getValidationDetections().stream().map(IisReportable::new).collect(Collectors.toList()));
}
// if processing flavor contains MEDLAR then all the non E errors have to removed from the processing list
if (processingFlavorSet != null && processingFlavorSet.contains(ProcessingFlavor.MEDLAR)) {
Expand Down Expand Up @@ -518,7 +517,7 @@ public String buildRSP(HL7Reader reader, String messageReceived, PatientMaster p
sb.append("MSA|AA|").append(sendersUniqueId).append("\r");
}
if (processingExceptionList.size() > 0) {
sb.append(HL7Util.makeERRSegment(new ProcessingExceptionReportable(processingExceptionList.get(processingExceptionList.size() - 1)), false));
sb.append(IisHL7Util.makeERRSegment(new IisReportable(processingExceptionList.get(processingExceptionList.size() - 1)), false));
}
}
String profileName = "Request a Complete Immunization History";
Expand Down Expand Up @@ -904,9 +903,9 @@ public int readAndCreateObservations(HL7Reader reader, List<ProcessingException>
public abstract ObservationReported readObservations(HL7Reader reader, List<ProcessingException> processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination, String identifierCode, String valueCode);


public List<Reportable> nistValidation(String message) throws Exception {
public List<IisReportable> nistValidation(String message) throws Exception {
String id = "aa72383a-7b48-46e5-a74a-82e019591fe7";
List<Reportable> reportableList = new ArrayList();
List<IisReportable> reportableList = new ArrayList();
Report report = syncHL7Validator.check(message, id);
logger.info(report.toText());
logger.info(report.toJson());
Expand All @@ -921,7 +920,9 @@ public List<Reportable> nistValidation(String message) throws Exception {
}

if (severityLevel != SeverityLevel.ACCEPT) {
NISTReportable reportable = new NISTReportable();
IisReportable reportable = new IisReportable();
reportable.setSource(ReportableSource.NIST);
reportable.setSeverity(IisReportableSeverity.WARN);
reportableList.add(reportable);
reportable.setReportedMessage(assertion.getDescription());
// reportable.setSeverity(severityLevel);
Expand All @@ -944,7 +945,7 @@ public List<Reportable> nistValidation(String message) throws Exception {
return reportableList;
}

public void readErrorLocation(NISTReportable reportable, String path) {
public void readErrorLocation(IisReportable reportable, String path) {
if (path != null && path.length() >= 3) {
String segmentid = path.substring(0, 3);
if (path.length() > 3) {
Expand All @@ -953,7 +954,7 @@ public void readErrorLocation(NISTReportable reportable, String path) {
path = "";
}

Hl7Location errorLocation = NISTReportable.readErrorLocation(path, segmentid);
Hl7Location errorLocation = IisReportable.readErrorLocation(path, segmentid);
if (errorLocation != null) {
reportable.getHl7LocationList().add(errorLocation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.immregistries.codebase.client.generated.Code;
import org.immregistries.codebase.client.reference.CodesetType;
import org.immregistries.iis.kernal.fhir.annotations.OnR4Condition;
import org.immregistries.iis.kernal.logic.ack.IisReportable;
import org.immregistries.iis.kernal.model.*;
import org.immregistries.mqe.hl7util.Reportable;
import org.immregistries.mqe.validator.MqeMessageServiceResponse;
import org.immregistries.smm.tester.manager.HL7Reader;
import org.springframework.context.annotation.Conditional;
Expand Down Expand Up @@ -93,7 +93,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
List<ProcessingException> processingExceptionList = new ArrayList<>();
Set<ProcessingFlavor> processingFlavorSet = tenant.getProcessingFlavorSet();
MqeMessageServiceResponse mqeMessageServiceResponse = mqeMessageService.processMessage(message);
List<Reportable> nistReportables = nistValidation(message);
List<IisReportable> nistReportables = nistValidation(message);

try {
CodeMap codeMap = CodeMapManager.getCodeMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.immregistries.codebase.client.generated.Code;
import org.immregistries.codebase.client.reference.CodesetType;
import org.immregistries.iis.kernal.fhir.annotations.OnR5Condition;
import org.immregistries.iis.kernal.logic.ack.IisReportable;
import org.immregistries.iis.kernal.model.*;
import org.immregistries.mqe.hl7util.Reportable;
import org.immregistries.mqe.validator.MqeMessageServiceResponse;
import org.immregistries.mqe.validator.engine.ValidationRuleResult;
import org.immregistries.smm.tester.manager.HL7Reader;
Expand Down Expand Up @@ -95,7 +95,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
List<ProcessingException> processingExceptionList = new ArrayList<>();
Set<ProcessingFlavor> processingFlavorSet = tenant.getProcessingFlavorSet();
MqeMessageServiceResponse mqeMessageServiceResponse = mqeMessageService.processMessage(message);
List<Reportable> nistReportables = nistValidation(message);
List<IisReportable> nistReportables = nistValidation(message);

try {
CodeMap codeMap = CodeMapManager.getCodeMap();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.immregistries.iis.kernal.logic;
package org.immregistries.iis.kernal.logic.ack;

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;
Expand All @@ -16,16 +12,16 @@ public enum IisAckBuilder {
INSTANCE;
public static final String PROCESSING_ID_DEBUG = "D";

public String buildAckFrom(AckData ackDataIn) {
public String buildAckFrom(IisAckData ackDataIn) {

String controlId = ackDataIn.getMessageControlId();
String processingId = ackDataIn.getProcessingControlId();
String ackCode = AckResult.APP_ACCEPT.getCode();
String ackCode;
String hl7ErrorCode = "0";
if (hasErrors(ackDataIn)) {
if (hasErrorSeverityType(ackDataIn, IisReportableSeverity.ERROR.getCode())) {
ackCode = AckResult.APP_ERROR.getCode();
for (Reportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == SeverityLevel.ERROR && r.getHl7ErrorCode() != null
for (IisReportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == IisReportableSeverity.ERROR && r.getHl7ErrorCode() != null
&& r.getHl7ErrorCode().getIdentifier() != null) {
hl7ErrorCode = r.getHl7ErrorCode().getIdentifier();
if (hl7ErrorCode != null && hl7ErrorCode.startsWith("2")) {
Expand All @@ -34,6 +30,12 @@ public String buildAckFrom(AckData ackDataIn) {
}
}
}
} else if (hasErrorSeverityType(ackDataIn, IisReportableSeverity.WARN.getCode())) {
ackCode = "AW";
} else if (hasErrorSeverityType(ackDataIn, "N")) {
ackCode = "AN";
} else {
ackCode = AckResult.APP_ACCEPT.getCode();
}
StringBuilder ack = new StringBuilder();
makeHeader(ack, ackDataIn, "Z23", null);
Expand All @@ -42,25 +44,25 @@ public String buildAckFrom(AckData ackDataIn) {
// SoftwareVersion.BINARY_ID
// + "|\r");
ack.append("MSA|" + ackCode + "|" + controlId + "|\r");
for (Reportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == SeverityLevel.ERROR) {
ack.append(HL7Util.makeERRSegment(r, PROCESSING_ID_DEBUG.equals(processingId)));
for (IisReportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == IisReportableSeverity.ERROR) {
ack.append(IisHL7Util.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 (IisReportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == IisReportableSeverity.WARN) {
ack.append(IisHL7Util.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)));
for (IisReportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == IisReportableSeverity.INFO) {
ack.append(IisHL7Util.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)));
for (IisReportable r : ackDataIn.getReportables()) {
if (r.getSeverity() == IisReportableSeverity.ACCEPT) {
ack.append(IisHL7Util.makeERRSegment(r, PROCESSING_ID_DEBUG.equals(processingId)));
}
}
}
Expand All @@ -78,35 +80,34 @@ public String buildAckFrom(AckData ackDataIn) {
// // 2 Error Location
// ack.append("|" + reportable.getHl7LocationList());
// // 3 HL7 Error Code
// HL7Util.appendErrorCode(ack, reportable.getHl7ErrorCode());
// IisHL7Util.appendErrorCode(ack, reportable.getHl7ErrorCode());
// ack.append("|");
// // 4 Severity
// ack.append(severity);
// ack.append("|");
// // 5 Application Error Code
// HL7Util.appendAppErrorCode(ack, reportable);
// IisHL7Util.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(IisHL7Util.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) {
private static boolean hasErrorSeverityType(IisAckData ackDataIn, String severityCode) {
for (IisReportable reportable : ackDataIn.getReportables()) {
if (reportable.getSeverity().getCode().equals(severityCode)) {
return true;
}
}
return false;
}

public static void makeHeader(StringBuilder ack, AckData ackDataIn, String profileId,
public static void makeHeader(StringBuilder ack, IisAckData ackDataIn, String profileId,
String responseType) {
String receivingApplication = ackDataIn.getSendingApplication();
String receivingFacility = ackDataIn.getSendingFacility();
Expand Down
Loading

0 comments on commit 9578cdb

Please sign in to comment.