Skip to content

Commit

Permalink
Infrastrucutre progress for ERR-5 code
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbeor committed Nov 20, 2024
1 parent 285dd37 commit 490d0b0
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,15 @@ public RelatedPerson searchRelatedPerson(SearchParameterMap searchParameterMap)
return relatedPerson;
}

public PatientReported savePatientReported(PatientReported patientReported) {
public MethodOutcome savePatientReportedMethodOutcome(PatientReported patientReported) {
Patient patient = patientMapper.getFhirResource(patientReported);
MethodOutcome outcome = save(patient,
return save(patient,
Patient.IDENTIFIER.exactly().systemAndIdentifier(patientReported.getPatientReportedAuthority(), patientReported.getExternalLink()));
}

public PatientReported savePatientReported(PatientReported patientReported) {
MethodOutcome outcome = savePatientReportedMethodOutcome(patientReported);
logger.info("created {} resource {}", outcome.getCreated(), outcome.getResource());
if (!outcome.getResource().isEmpty()) {
patientReported.setPatientId(outcome.getResource().getIdElement().getIdPart());
return patientMapper.getReportedWithMaster((Patient) outcome.getResource());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.immregistries.iis.kernal.logic;

import org.immregistries.iis.kernal.logic.ack.IisReportable;
import org.immregistries.iis.kernal.model.PatientMaster;
import org.immregistries.iis.kernal.model.ProcessingFlavor;
import org.immregistries.iis.kernal.model.Tenant;
Expand All @@ -23,8 +24,6 @@ public interface IIncomingMessageHandler {
String Z23_ACKNOWLEDGEMENT = "Z23";
String VXU_Z22 = "Z22";
String ADVANCED_ACK = "ADVANCED_ACK";
// String Z22_ADVANCED_VXU = VXU_Z22 + "~" + ADVANCED_ACK;
// String Z23_ADVANCED_ACKNOWLEDGEMENT = "Z23^CDCPHINVS" + "~" + ADVANCED_ACK;
String QUERY_OK = "OK";
// TODO:
// Organize logic classes, need to have access classes for every object, maybe a new Access
Expand All @@ -39,6 +38,6 @@ public interface IIncomingMessageHandler {

List<VaccinationMaster> getVaccinationMasterList(PatientMaster patient);

String buildAck(HL7Reader reader, List<ProcessingException> processingExceptionList, Set<ProcessingFlavor> processingFlavorSetå);
String buildAck(HL7Reader reader, List<IisReportable> processingExceptionList, Set<ProcessingFlavor> processingFlavorSetå);

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ public String process(String message, Tenant tenant, String sendingFacilityName)
break;
default:
ProcessingException pe = new ProcessingException("Unsupported message", "", 0, 0);
List<ProcessingException> processingExceptionList = List.of(pe);
List<IisReportable> processingExceptionList = List.of(new IisReportable(pe));
responseMessage = buildAck(reader, processingExceptionList, processingFlavorSet);
recordMessageReceived(message, null, responseMessage, "Unknown", "NAck", tenant);
break;
}

} catch (Exception e) {
e.printStackTrace(System.err);
List<ProcessingException> processingExceptionList = new ArrayList<>();
processingExceptionList.add(new ProcessingException("Internal error prevented processing: " + e.getMessage(), null, 0, 0));
List<IisReportable> processingExceptionList = new ArrayList<>();
processingExceptionList.add(new IisReportable(new ProcessingException("Internal error prevented processing: " + e.getMessage(), null, 0, 0)));
responseMessage = buildAck(reader, processingExceptionList, processingFlavorSet);
}
return responseMessage;
}

@SuppressWarnings("unchecked")
public String processVXU(Tenant tenant, HL7Reader reader, String message, Organization managingOrganization) throws Exception {
List<ProcessingException> processingExceptionList = new ArrayList<>();
List<IisReportable> processingExceptionList = new ArrayList<>();
Set<ProcessingFlavor> processingFlavorSet = tenant.getProcessingFlavorSet();
MqeMessageServiceResponse mqeMessageServiceResponse = mqeMessageService.processMessage(message);
List<IisReportable> nistReportables = nistValidation(message, "VXU");
Expand Down Expand Up @@ -191,15 +191,15 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
Code cvxCode = codeMap.getRelatedCode(ndcCode, CodesetType.VACCINATION_CVX_CODE);
if (cvxCode == null) {
ProcessingException pe = new ProcessingException("Unrecognized NDC " + vaccineNdcCode, "RXA", rxaCount, 5).setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
} else {
if (vaccineCvxCode.equals("")) {
vaccineCvxCode = cvxCode.getValue();
} else if (!vaccineCvxCode.equals(cvxCode.getValue())) {
// NDC doesn't map to the CVX code that was submitted!
ProcessingException pe = new ProcessingException("NDC " + vaccineNdcCode + " maps to " + cvxCode.getValue() + " but CVX " + vaccineCvxCode + " was also reported, preferring CVX code", "RXA", rxaCount, 5);
pe.setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
}
}
}
Expand All @@ -210,14 +210,14 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
Code cvxCode = codeMap.getRelatedCode(cptCode, CodesetType.VACCINATION_CVX_CODE);
if (cvxCode == null) {
ProcessingException pe = new ProcessingException("Unrecognized CPT " + cptCode, "RXA", rxaCount, 5).setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
} else {
if (vaccineCvxCode.equals("")) {
vaccineCvxCode = cvxCode.getValue();
} else if (!vaccineCvxCode.equals(cvxCode.getValue())) {
// CPT doesn't map to the CVX code that was submitted!
ProcessingException pe = new ProcessingException("CPT " + vaccineCptCode + " maps to " + cvxCode.getValue() + " but CVX " + vaccineCvxCode + " was also reported, preferring CVX code", "RXA", rxaCount, 5).setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
}
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
vaccinationReported.setAdministeredAmount(reader.getValue(6));
vaccinationReported.setInformationSource(reader.getValue(9));
vaccinationReported.setLotnumber(reader.getValue(15));
vaccinationReported.setExpirationDate(parseDateWarnOld(reader.getValue(16), "Invalid vaccination expiration date", "RXA", rxaCount, 16, strictDate, processingExceptionList));
vaccinationReported.setExpirationDate(parseDateWarn(reader.getValue(16), "Invalid vaccination expiration date", "RXA", rxaCount, 16, strictDate, processingExceptionList));
vaccinationReported.setVaccineMvxCode(reader.getValue(17));
vaccinationReported.setRefusalReasonCode(reader.getValue(18));
vaccinationReported.setCompletionStatus(reader.getValue(20));
Expand All @@ -306,7 +306,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
if (refusalCode == null) {
ProcessingException pe = new ProcessingException("Unrecognized refusal reason", "RXA", rxaCount, 18);
pe.setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
}
}
vaccinationReported.setActionCode(reader.getValue(21));
Expand Down Expand Up @@ -346,7 +346,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
Code fundingEligibilityCode = codeMap.getCodeForCodeset(CodesetType.FINANCIAL_STATUS_CODE, fundingEligibility);
if (fundingEligibilityCode == null) {
ProcessingException pe = new ProcessingException("Funding eligibility '" + fundingEligibility + "' was not recognized", "OBX", tempObxCount, 5).setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
} else {
vaccinationReported.setFundingEligibility(fundingEligibilityCode.getValue());
}
Expand All @@ -357,7 +357,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
Code fundingSourceCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_FUNDING_SOURCE, fundingSource);
if (fundingSourceCode == null) {
ProcessingException pe = new ProcessingException("Funding source '" + fundingSource + "' was not recognized", "OBX", tempObxCount, 5).setWarning();
processingExceptionList.add(pe);
processingExceptionList.add(new IisReportable(pe));
} else {
vaccinationReported.setFundingSource(fundingSourceCode.getValue());
}
Expand All @@ -383,7 +383,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
return ack;
} catch (ProcessingException e) {
if (!processingExceptionList.contains(e)) {
processingExceptionList.add(e);
processingExceptionList.add(new IisReportable(e));
}
String ack = buildAckMqe(reader, mqeMessageServiceResponse, processingExceptionList, processingFlavorSet, nistReportables);
recordMessageReceived(message, null, ack, "Update", "Exception", tenant);
Expand All @@ -393,24 +393,24 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi
}

@SuppressWarnings("unchecked")
public PatientReported processPatient(Tenant tenant, HL7Reader reader, List<ProcessingException> processingExceptionList, Set<ProcessingFlavor> processingFlavorSet, CodeMap codeMap, boolean strictDate, PatientReported patientReported, Organization managingOrganization) throws ProcessingException {
public PatientReported processPatient(Tenant tenant, HL7Reader reader, List<IisReportable> processingExceptionList, Set<ProcessingFlavor> processingFlavorSet, CodeMap codeMap, boolean strictDate, PatientReported patientReported, Organization managingOrganization) throws ProcessingException {
String patientReportedExternalLink = "";
String patientReportedAuthority = "";
String patientReportedType = "MR";
if (reader.advanceToSegment("PID")) {
patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5);
patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5);
if (patientReportedExternalLink.equals("")) {
if (StringUtils.isBlank(patientReportedExternalLink)) {
patientReportedAuthority = "";
patientReportedType = "PT";
patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5);
patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5);
if (patientReportedExternalLink.equals("")) {
if (StringUtils.isBlank(patientReportedExternalLink)) {
patientReportedAuthority = "";
patientReportedType = "PI";
patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5);
patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5);
if (patientReportedExternalLink.equals("")) {
if (StringUtils.isBlank(patientReportedExternalLink)) {
throw new ProcessingException("MRN was not found, required for accepting vaccination report", "PID", 1, 3);
}
}
Expand All @@ -435,7 +435,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, List<Proc
}

public String processORU(Tenant tenant, HL7Reader reader, String message, Organization managingOrganization) {
List<ProcessingException> processingExceptionList = new ArrayList<>();
List<IisReportable> processingExceptionList = new ArrayList<>();
Set<ProcessingFlavor> processingFlavorSet = tenant.getProcessingFlavorSet();
try {
CodeMap codeMap = CodeMapManager.getCodeMap();
Expand All @@ -458,7 +458,7 @@ public String processORU(Tenant tenant, HL7Reader reader, String message, Organi
return ack;
} catch (ProcessingException e) {
if (!processingExceptionList.contains(e)) {
processingExceptionList.add(e);
processingExceptionList.add(new IisReportable(e));
}
String ack = buildAck(reader, processingExceptionList, processingFlavorSet);
recordMessageReceived(message, null, ack, "Update", "Exception", tenant);
Expand All @@ -467,7 +467,7 @@ public String processORU(Tenant tenant, HL7Reader reader, String message, Organi
}

@SuppressWarnings("unchecked")
public ObservationReported readObservations(HL7Reader reader, List<ProcessingException> processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination, String identifierCode, String valueCode) {
public ObservationReported readObservations(HL7Reader reader, List<IisReportable> processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination, String identifierCode, String valueCode) {
// ObservationMaster observationMaster = null;
ObservationReported observationReported = null;
if (vaccination == null) {
Expand Down Expand Up @@ -507,7 +507,7 @@ public ObservationReported readObservations(HL7Reader reader, List<ProcessingExc
observationReported.setUnitsLabel(reader.getValue(6, 2));
observationReported.setUnitsTable(reader.getValue(6, 3));
observationReported.setResultStatus(reader.getValue(11));
observationReported.setObservationDate(parseDateWarnOld(reader.getValue(14), "Unparsable date/time of observation", "OBX", obxCount, 14, strictDate, processingExceptionList));
observationReported.setObservationDate(parseDateWarn(reader.getValue(14), "Unparsable date/time of observation", "OBX", obxCount, 14, strictDate, processingExceptionList));
observationReported.setMethodCode(reader.getValue(17, 1));
observationReported.setMethodLabel(reader.getValue(17, 2));
observationReported.setMethodTable(reader.getValue(17, 3));
Expand Down
Loading

0 comments on commit 490d0b0

Please sign in to comment.