From 522970ce9f21c8a64cf0f5300b0f131e231b30ce Mon Sep 17 00:00:00 2001 From: Clement Hennequin Date: Fri, 18 Oct 2024 14:47:57 -0400 Subject: [PATCH] reformat files & minor change on R5 Handler --- .../kernal/logic/IncomingMessageHandler.java | 1415 ++++++++--------- .../logic/IncomingMessageHandlerR4.java | 437 ++--- .../logic/IncomingMessageHandlerR5.java | 439 ++--- 3 files changed, 941 insertions(+), 1350 deletions(-) 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 105055ad..41403e2f 100644 --- a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandler.java +++ b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandler.java @@ -32,11 +32,30 @@ public abstract class IncomingMessageHandler implements IIncomingMessageHandler { - protected final Logger logger = LoggerFactory.getLogger(IncomingMessageHandler.class); - @Autowired - protected RepositoryClientFactory repositoryClientFactory; - @Autowired - protected FhirRequester fhirRequester; + protected static final String PATIENT_MIDDLE_NAME_MULTI = "Multi"; + protected static final String QBP_Z34 = "Z34"; + protected static final String QBP_Z44 = "Z44"; + protected static final String RSP_Z42_MATCH_WITH_FORECAST = "Z42"; + protected static final String RSP_Z32_MATCH = "Z32"; + protected static final String RSP_Z31_MULTIPLE_MATCH = "Z31"; + protected static final String RSP_Z33_NO_MATCH = "Z33"; + protected static final String Z23_ACKNOWLEDGEMENT = "Z23"; + protected static final String QUERY_OK = "OK"; + // TODO: + // Organize logic classes, need to have access classes for every object, maybe a new Access + // package? + // Look at names of database fields, make more consistent + protected static final String QUERY_NOT_FOUND = "NF"; + protected static final String QUERY_TOO_MANY = "TM"; + protected static final String QUERY_APPLICATION_ERROR = "AE"; + protected static final Random random = new Random(); + private static Integer increment = 1; + protected final Logger logger = LoggerFactory.getLogger(IncomingMessageHandler.class); + @Autowired + protected RepositoryClientFactory repositoryClientFactory; + @Autowired + protected FhirRequester fhirRequester; + protected Session dataSession; @Autowired PatientMapper patientMapper; @Autowired @@ -45,735 +64,679 @@ public abstract class IncomingMessageHandler implements IIncomingMessageHandler ObservationMapper observationMapper; @Autowired LocationMapper locationMapper; - @Autowired PartitionCreationInterceptor partitionCreationInterceptor; - protected static final String PATIENT_MIDDLE_NAME_MULTI = "Multi"; - // TODO: - // Organize logic classes, need to have access classes for every object, maybe a new Access - // package? - // Look at names of database fields, make more consistent - - protected static final String QBP_Z34 = "Z34"; - protected static final String QBP_Z44 = "Z44"; - protected static final String RSP_Z42_MATCH_WITH_FORECAST = "Z42"; - protected static final String RSP_Z32_MATCH = "Z32"; - protected static final String RSP_Z31_MULTIPLE_MATCH = "Z31"; - protected static final String RSP_Z33_NO_MATCH = "Z33"; - protected static final String Z23_ACKNOWLEDGEMENT = "Z23"; - protected static final String QUERY_OK = "OK"; - protected static final String QUERY_NOT_FOUND = "NF"; - protected static final String QUERY_TOO_MANY = "TM"; - protected static final String QUERY_APPLICATION_ERROR = "AE"; - - protected Session dataSession; - public IncomingMessageHandler() { dataSession = PopServlet.getDataSession(); } - public void verifyNoErrors(List processingExceptionList) - throws ProcessingException { - for (ProcessingException pe : processingExceptionList) { - if (pe.isError()) { - throw pe; - } - } - } - - public boolean hasErrors(List processingExceptionList) { - for (ProcessingException pe : processingExceptionList) { - if (pe.isError()) { - return true; - } - } - return false; - } - - public void recordMessageReceived(String message, PatientMaster patient, - String messageResponse, String categoryRequest, String categoryResponse, - Tenant tenant) { - MessageReceived messageReceived = new MessageReceived(); - messageReceived.setTenant(tenant); - messageReceived.setMessageRequest(message); - if (patient != null) { - messageReceived.setPatientReportedId(patient.getPatientId()); - } - messageReceived.setMessageResponse(messageResponse); - messageReceived.setReportedDate(new Date()); - messageReceived.setCategoryRequest(categoryRequest); - messageReceived.setCategoryResponse(categoryResponse); - // TODO interact with internal logs and metadata - Transaction transaction = dataSession.beginTransaction(); - dataSession.save(messageReceived); - transaction.commit(); - } - - public void printQueryNK1(PatientMaster patientMaster, StringBuilder sb, CodeMap codeMap) { - if (patientMaster != null) { - - if (StringUtils.isNotBlank(patientMaster.getGuardianRelationship()) - && StringUtils.isNotBlank(patientMaster.getGuardianLast()) - && StringUtils.isNotBlank(patientMaster.getGuardianFirst())) { - Code code = codeMap.getCodeForCodeset(CodesetType.PERSON_RELATIONSHIP, - patientMaster.getGuardianRelationship()); - if (code != null) { - sb.append("NK1"); - sb.append("|1"); - sb.append("|").append(patientMaster.getGuardianLast()).append("^").append(patientMaster.getGuardianFirst()).append("^^^^^L"); - sb.append("|").append(code.getValue()).append("^").append(code.getLabel()).append("^HL70063"); - sb.append("\r"); - } - } - } - } - - public void printQueryPID(PatientMaster patientReported, - Set processingFlavorSet, StringBuilder sb, PatientMaster patient, - SimpleDateFormat sdf, int pidCount) { - // PID - sb.append("PID"); - // PID-1 - sb.append("|").append(pidCount); - // PID-2 - sb.append("|"); - // PID-3 - sb.append("|").append(patient.getExternalLink()).append("^^^IIS^SR"); - if (patientReported != null) { - sb.append("~").append(patientReported.getExternalLink()).append("^^^").append(patientReported.getPatientReportedAuthority()).append("^").append(patientReported.getPatientReportedType()); - } - // PID-4 - sb.append("|"); - // PID-5 - String firstName = patient.getNameFirst(); - String middleName = patient.getNameMiddle(); - String lastName = patient.getNameLast(); - String motherMaiden = null; - if (patientReported != null) { - motherMaiden = patientReported.getMotherMaidenName(); - } - String dateOfBirth = sdf.format(patient.getBirthDate()); - - // If "PHI" flavor, strip AIRA from names 10% of the time - if (processingFlavorSet.contains(ProcessingFlavor.PHI)) { - - if (random.nextInt(10) == 0) { - firstName = firstName.replace("AIRA", ""); - middleName = middleName.replace("AIRA", ""); - lastName = lastName.replace("AIRA", ""); - } - if (motherMaiden != null) { - motherMaiden = motherMaiden.replace("AIRA", ""); - } - } - - if (processingFlavorSet.contains(ProcessingFlavor.CITRUS)) { - int omission = random.nextInt(3); - if (omission == 0) { - firstName = ""; - } else if (omission == 1) { - lastName = ""; + private static int nextIncrement() { + synchronized (increment) { + if (increment < Integer.MAX_VALUE) { + increment = increment + 1; + } else { + increment = 1; + } + return increment; + } + } + + public void verifyNoErrors(List processingExceptionList) throws ProcessingException { + for (ProcessingException pe : processingExceptionList) { + if (pe.isError()) { + throw pe; + } + } + } + + public boolean hasErrors(List processingExceptionList) { + for (ProcessingException pe : processingExceptionList) { + if (pe.isError()) { + return true; + } + } + return false; + } + + public void recordMessageReceived(String message, PatientMaster patient, String messageResponse, String categoryRequest, String categoryResponse, Tenant tenant) { + MessageReceived messageReceived = new MessageReceived(); + messageReceived.setTenant(tenant); + messageReceived.setMessageRequest(message); + if (patient != null) { + messageReceived.setPatientReportedId(patient.getPatientId()); + } + messageReceived.setMessageResponse(messageResponse); + messageReceived.setReportedDate(new Date()); + messageReceived.setCategoryRequest(categoryRequest); + messageReceived.setCategoryResponse(categoryResponse); + // TODO interact with internal logs and metadata + Transaction transaction = dataSession.beginTransaction(); + dataSession.save(messageReceived); + transaction.commit(); + } + + public void printQueryNK1(PatientMaster patientMaster, StringBuilder sb, CodeMap codeMap) { + if (patientMaster != null) { + + if (StringUtils.isNotBlank(patientMaster.getGuardianRelationship()) && StringUtils.isNotBlank(patientMaster.getGuardianLast()) && StringUtils.isNotBlank(patientMaster.getGuardianFirst())) { + Code code = codeMap.getCodeForCodeset(CodesetType.PERSON_RELATIONSHIP, patientMaster.getGuardianRelationship()); + if (code != null) { + sb.append("NK1"); + sb.append("|1"); + sb.append("|").append(patientMaster.getGuardianLast()).append("^").append(patientMaster.getGuardianFirst()).append("^^^^^L"); + sb.append("|").append(code.getValue()).append("^").append(code.getLabel()).append("^HL70063"); + sb.append("\r"); + } + } + } + } + + public void printQueryPID(PatientMaster patientReported, Set processingFlavorSet, StringBuilder sb, PatientMaster patient, SimpleDateFormat sdf, int pidCount) { + // PID + sb.append("PID"); + // PID-1 + sb.append("|").append(pidCount); + // PID-2 + sb.append("|"); + // PID-3 + sb.append("|").append(patient.getExternalLink()).append("^^^IIS^SR"); + if (patientReported != null) { + sb.append("~").append(patientReported.getExternalLink()).append("^^^").append(patientReported.getPatientReportedAuthority()).append("^").append(patientReported.getPatientReportedType()); + } + // PID-4 + sb.append("|"); + // PID-5 + String firstName = patient.getNameFirst(); + String middleName = patient.getNameMiddle(); + String lastName = patient.getNameLast(); + String motherMaiden = null; + if (patientReported != null) { + motherMaiden = patientReported.getMotherMaidenName(); + } + String dateOfBirth = sdf.format(patient.getBirthDate()); + + // If "PHI" flavor, strip AIRA from names 10% of the time + if (processingFlavorSet.contains(ProcessingFlavor.PHI)) { + + if (random.nextInt(10) == 0) { + firstName = firstName.replace("AIRA", ""); + middleName = middleName.replace("AIRA", ""); + lastName = lastName.replace("AIRA", ""); + } + if (motherMaiden != null) { + motherMaiden = motherMaiden.replace("AIRA", ""); + } + } + + if (processingFlavorSet.contains(ProcessingFlavor.CITRUS)) { + int omission = random.nextInt(3); + if (omission == 0) { + firstName = ""; + } else if (omission == 1) { + lastName = ""; + } else { + dateOfBirth = ""; + } + } + + sb.append("|").append(lastName).append("^").append(firstName).append("^").append(middleName).append("^^^^L"); + + // PID-6 + sb.append("|"); + if (StringUtils.isNotBlank(motherMaiden)) { + sb.append(motherMaiden).append("^^^^^^M"); + } + // PID-7 + sb.append("|").append(dateOfBirth); + if (patientReported != null) { + // PID-8 + { + String sex = patientReported.getSex(); + if (!sex.equals("F") && !sex.equals("M") && !sex.equals("X")) { + sex = "U"; + } + sb.append("|").append(sex); + } + // PID-9 + sb.append("|"); + // PID-10 + sb.append("|"); + { + String race = patientReported.getRace(); + // if processing flavor is PUNKIN then the race should be reported, and if it is null then it must be reported as UNK + if (processingFlavorSet.contains(ProcessingFlavor.PUNKIN)) { + CodeMap codeMap = CodeMapManager.getCodeMap(); + Code raceCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_RACE, race); + if (race.equals("") || raceCode == null || CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID) { + sb.append("UNK^Unknown^CDCREC"); + } else { + sb.append(raceCode.getValue()); + sb.append("^"); + sb.append(raceCode.getLabel()); + sb.append("^CDCREC"); + } + } else if (StringUtils.isNotBlank(race)) { + if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) || processingFlavorSet.contains(ProcessingFlavor.PERSIMMON)) { + CodeMap codeMap = CodeMapManager.getCodeMap(); + Code raceCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_RACE, race); + if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) || (raceCode != null && CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID)) { + sb.append(raceCode == null ? race : raceCode.getValue()); + sb.append("^"); + if (raceCode != null) { + sb.append(raceCode.getLabel()); + } + sb.append("^CDCREC"); + } + + } + } + } + // PID-11 + sb.append("|").append(patientReported.getAddressLine1()).append("^").append(patientReported.getAddressLine2()).append("^").append(patientReported.getAddressCity()).append("^").append(patientReported.getAddressState()).append("^").append(patientReported.getAddressZip()).append("^").append(patientReported.getAddressCountry()).append("^"); + if (!processingFlavorSet.contains(ProcessingFlavor.LIME)) { + sb.append("P"); + } + // PID-12 + sb.append("|"); + // PID-13 + sb.append("|"); + String phone = patientReported.getPhone(); + if (phone.length() == 10) { + sb.append("^PRN^PH^^^").append(phone, 0, 3).append("^").append(phone, 3, 10); + } + // PID-14 + sb.append("|"); + // PID-15 + sb.append("|"); + // PID-16 + sb.append("|"); + // PID-17 + sb.append("|"); + // PID-18 + sb.append("|"); + // PID-19 + sb.append("|"); + // PID-20 + sb.append("|"); + // PID-21 + sb.append("|"); + // PID-22 + sb.append("|"); + { + String ethnicity = patientReported.getEthnicity(); + // if processing flavor is PUNKIN then the race should be reported, and if it is null then it must be reported as UNK + if (processingFlavorSet.contains(ProcessingFlavor.PUNKIN)) { + CodeMap codeMap = CodeMapManager.getCodeMap(); + Code ethnicityCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_ETHNICITY, ethnicity); + if (ethnicity.equals("") || ethnicityCode == null || CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID) { + sb.append("UNK^Unknown^CDCREC"); + } else { + sb.append(ethnicityCode.getValue()); + sb.append("^"); + sb.append(ethnicityCode.getLabel()); + sb.append("^CDCREC"); + } + } + if (StringUtils.isNotBlank(ethnicity)) { + if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) || processingFlavorSet.contains(ProcessingFlavor.PERSIMMON)) { + CodeMap codeMap = CodeMapManager.getCodeMap(); + Code ethnicityCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_ETHNICITY, ethnicity); + if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) || (ethnicityCode != null && CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID)) { + sb.append(ethnicityCode == null ? ethnicity : ethnicityCode.getValue()); + + sb.append("^"); + if (ethnicityCode != null) { + sb.append(ethnicityCode.getLabel()); + } + sb.append("^CDCREC"); + } + } + } + } + // PID-23 + sb.append("|"); + // PID-24 + sb.append("|"); + sb.append(patientReported.getBirthFlag()); + // PID-25 + sb.append("|"); + sb.append(patientReported.getBirthOrder()); + + } + sb.append("\r"); + } + + public void printORC(Tenant tenant, StringBuilder sb, VaccinationMaster vaccination, boolean originalReporter) { + Set processingFlavorSet = tenant.getProcessingFlavorSet(); + sb.append("ORC"); + // ORC-1 + sb.append("|RE"); + // ORC-2 + sb.append("|"); + if (vaccination != null) { + sb.append(vaccination.getVaccinationId()).append("^IIS"); + } + // ORC-3 + sb.append("|"); + if (vaccination == null) { + if (processingFlavorSet.contains(ProcessingFlavor.LIME)) { + sb.append("999^IIS"); + } else { + sb.append("9999^IIS"); + } } else { - dateOfBirth = ""; - } - } - - sb.append("|").append(lastName).append("^").append(firstName).append("^").append(middleName).append("^^^^L"); - - // PID-6 - sb.append("|"); - if (StringUtils.isNotBlank(motherMaiden)) { - sb.append(motherMaiden).append("^^^^^^M"); - } - // PID-7 - sb.append("|").append(dateOfBirth); - if (patientReported != null) { - // PID-8 - { - String sex = patientReported.getSex(); - if (!sex.equals("F") && !sex.equals("M") && !sex.equals("X")) { - sex = "U"; - } - sb.append("|").append(sex); - } - // PID-9 - sb.append("|"); - // PID-10 - sb.append("|"); - { - String race = patientReported.getRace(); - // if processing flavor is PUNKIN then the race should be reported, and if it is null then it must be reported as UNK - if (processingFlavorSet.contains(ProcessingFlavor.PUNKIN)) { - CodeMap codeMap = CodeMapManager.getCodeMap(); - Code raceCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_RACE, race); - if (race.equals("") || raceCode == null || CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID) { - sb.append("UNK^Unknown^CDCREC"); - } else { - sb.append(raceCode.getValue()); - sb.append("^"); - sb.append(raceCode.getLabel()); - sb.append("^CDCREC"); - } - } else if (StringUtils.isNotBlank(race)) { - if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) - || processingFlavorSet.contains(ProcessingFlavor.PERSIMMON)) { - CodeMap codeMap = CodeMapManager.getCodeMap(); - Code raceCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_RACE, race); - if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) || (raceCode != null - && CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID)) { - sb.append(raceCode == null ? race : raceCode.getValue()); - sb.append("^"); - if (raceCode != null) { - sb.append(raceCode.getLabel()); - } - sb.append("^CDCREC"); - } - - } - } - } - // PID-11 - sb.append("|").append(patientReported.getAddressLine1()).append("^").append(patientReported.getAddressLine2()).append("^").append(patientReported.getAddressCity()).append("^").append(patientReported.getAddressState()).append("^").append(patientReported.getAddressZip()).append("^").append(patientReported.getAddressCountry()).append("^"); - if (!processingFlavorSet.contains(ProcessingFlavor.LIME)) { - sb.append("P"); - } - // PID-12 - sb.append("|"); - // PID-13 - sb.append("|"); - String phone = patientReported.getPhone(); - if (phone.length() == 10) { - sb.append("^PRN^PH^^^").append(phone, 0, 3).append("^").append(phone, 3, 10); - } - // PID-14 - sb.append("|"); - // PID-15 - sb.append("|"); - // PID-16 - sb.append("|"); - // PID-17 - sb.append("|"); - // PID-18 - sb.append("|"); - // PID-19 - sb.append("|"); - // PID-20 - sb.append("|"); - // PID-21 - sb.append("|"); - // PID-22 - sb.append("|"); - { - String ethnicity = patientReported.getEthnicity(); - // if processing flavor is PUNKIN then the race should be reported, and if it is null then it must be reported as UNK - if (processingFlavorSet.contains(ProcessingFlavor.PUNKIN)) { - CodeMap codeMap = CodeMapManager.getCodeMap(); - Code ethnicityCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_ETHNICITY, ethnicity); - if (ethnicity.equals("") || ethnicityCode == null || CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID) { - sb.append("UNK^Unknown^CDCREC"); - } else { - sb.append(ethnicityCode.getValue()); - sb.append("^"); - sb.append(ethnicityCode.getLabel()); - sb.append("^CDCREC"); - } - } - if (StringUtils.isNotBlank(ethnicity)) { - if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) - || processingFlavorSet.contains(ProcessingFlavor.PERSIMMON)) { - CodeMap codeMap = CodeMapManager.getCodeMap(); - Code ethnicityCode = - codeMap.getCodeForCodeset(CodesetType.PATIENT_ETHNICITY, ethnicity); - if (processingFlavorSet.contains(ProcessingFlavor.PITAYA) || (ethnicityCode != null - && CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID)) { - sb.append(ethnicityCode == null ? ethnicity : ethnicityCode.getValue()); - - sb.append("^"); - if (ethnicityCode != null) { - sb.append(ethnicityCode.getLabel()); - } - sb.append("^CDCREC"); - } - } - } - } - // PID-23 - sb.append("|"); - // PID-24 - sb.append("|"); - sb.append(patientReported.getBirthFlag()); - // PID-25 - sb.append("|"); - sb.append(patientReported.getBirthOrder()); - - } - sb.append("\r"); - } - - public void printORC(Tenant tenant, StringBuilder sb, VaccinationMaster vaccination, - boolean originalReporter) { - Set processingFlavorSet = tenant.getProcessingFlavorSet(); - sb.append("ORC"); - // ORC-1 - sb.append("|RE"); - // ORC-2 - sb.append("|"); - if (vaccination != null) { - sb.append(vaccination.getVaccinationId()).append("^IIS"); - } - // ORC-3 - sb.append("|"); - if (vaccination == null) { - if (processingFlavorSet.contains(ProcessingFlavor.LIME)) { - sb.append("999^IIS"); - } else { - sb.append("9999^IIS"); - } - } else { - if (originalReporter) { - sb.append(vaccination.getExternalLink()).append("^").append(tenant.getOrganizationName()); - } - } - sb.append("\r"); - } - - public List doForecast(PatientMaster patient, - CodeMap codeMap, List vaccinationMasterList, Tenant tenant) { - List forecastActualList = null; - Set processingFlavorSet = tenant.getProcessingFlavorSet(); - try { - TestCase testCase = new TestCase(); - testCase.setEvalDate(new Date()); - testCase.setPatientSex(patient == null ? "F" : patient.getSex()); - testCase.setPatientDob(patient.getBirthDate()); - List testEventList = new ArrayList<>(); - for (VaccinationMaster vaccination : vaccinationMasterList) { - Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, - vaccination.getVaccineCvxCode()); - if (cvxCode == null) { - continue; - } - if ("D".equals(vaccination.getActionCode())) { - continue; - } - int cvx = 0; - try { - cvx = Integer.parseInt(vaccination.getVaccineCvxCode()); - TestEvent testEvent = new TestEvent(cvx, vaccination.getAdministeredDate()); - testEventList.add(testEvent); - vaccination.setTestEvent(testEvent); - } catch (NumberFormatException nfe) { - continue; - } - } - testCase.setTestEventList(testEventList); - Software software = new Software(); - software.setServiceUrl("https://sabbia.westus2.cloudapp.azure.com/lonestar/forecast"); - software.setService(Service.LSVF); - if (processingFlavorSet.contains(ProcessingFlavor.ICE)) { - software.setServiceUrl( - "https://sabbia.westus2.cloudapp.azure.com/opencds-decision-support-service/evaluate"); - software.setService(Service.ICE); - } - - ConnectorInterface connector = - ConnectFactory.createConnecter(software, VaccineGroup.getForecastItemList()); - connector.setLogText(false); - try { - forecastActualList = connector.queryForForecast(testCase, new SoftwareResult()); - } catch (IOException ioe) { - System.err.println("Unable to query for forecast"); - ioe.printStackTrace(); - } - } catch (Exception e) { - System.err.println("Unable to query for forecast"); - e.printStackTrace(System.err); - } - return forecastActualList; - } - - public void printObx(StringBuilder sb, int obxSetId, int obsSubId, String loinc, - String loincLabel, String value) { - sb.append("OBX"); - // OBX-1 - sb.append("|"); - sb.append(obxSetId); - // OBX-2 - sb.append("|"); - sb.append("CE"); - // OBX-3 - sb.append("|"); - sb.append(loinc).append("^").append(loincLabel).append("^LN"); - // OBX-4 - sb.append("|"); - sb.append(obsSubId); - // OBX-5 - sb.append("|"); - sb.append(value); - // OBX-6 - sb.append("|"); - // OBX-7 - sb.append("|"); - // OBX-8 - sb.append("|"); - // OBX-9 - sb.append("|"); - // OBX-10 - sb.append("|"); - // OBX-11 - sb.append("|"); - sb.append("F"); - sb.append("\r"); - } - - public void printObx(StringBuilder sb, int obxSetId, int obsSubId, - ObservationReported ob) { + if (originalReporter) { + sb.append(vaccination.getExternalLink()).append("^").append(tenant.getOrganizationName()); + } + } + sb.append("\r"); + } + + public List doForecast(PatientMaster patient, CodeMap codeMap, List vaccinationMasterList, Tenant tenant) { + List forecastActualList = null; + Set processingFlavorSet = tenant.getProcessingFlavorSet(); + try { + TestCase testCase = new TestCase(); + testCase.setEvalDate(new Date()); + testCase.setPatientSex(patient == null ? "F" : patient.getSex()); + testCase.setPatientDob(patient.getBirthDate()); + List testEventList = new ArrayList<>(); + for (VaccinationMaster vaccination : vaccinationMasterList) { + Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccination.getVaccineCvxCode()); + if (cvxCode == null) { + continue; + } + if ("D".equals(vaccination.getActionCode())) { + continue; + } + int cvx = 0; + try { + cvx = Integer.parseInt(vaccination.getVaccineCvxCode()); + TestEvent testEvent = new TestEvent(cvx, vaccination.getAdministeredDate()); + testEventList.add(testEvent); + vaccination.setTestEvent(testEvent); + } catch (NumberFormatException nfe) { + continue; + } + } + testCase.setTestEventList(testEventList); + Software software = new Software(); + software.setServiceUrl("https://sabbia.westus2.cloudapp.azure.com/lonestar/forecast"); + software.setService(Service.LSVF); + if (processingFlavorSet.contains(ProcessingFlavor.ICE)) { + software.setServiceUrl("https://sabbia.westus2.cloudapp.azure.com/opencds-decision-support-service/evaluate"); + software.setService(Service.ICE); + } + + ConnectorInterface connector = ConnectFactory.createConnecter(software, VaccineGroup.getForecastItemList()); + connector.setLogText(false); + try { + forecastActualList = connector.queryForForecast(testCase, new SoftwareResult()); + } catch (IOException ioe) { + System.err.println("Unable to query for forecast"); + ioe.printStackTrace(); + } + } catch (Exception e) { + System.err.println("Unable to query for forecast"); + e.printStackTrace(System.err); + } + return forecastActualList; + } + + public void printObx(StringBuilder sb, int obxSetId, int obsSubId, String loinc, String loincLabel, String value) { + sb.append("OBX"); + // OBX-1 + sb.append("|"); + sb.append(obxSetId); + // OBX-2 + sb.append("|"); + sb.append("CE"); + // OBX-3 + sb.append("|"); + sb.append(loinc).append("^").append(loincLabel).append("^LN"); + // OBX-4 + sb.append("|"); + sb.append(obsSubId); + // OBX-5 + sb.append("|"); + sb.append(value); + // OBX-6 + sb.append("|"); + // OBX-7 + sb.append("|"); + // OBX-8 + sb.append("|"); + // OBX-9 + sb.append("|"); + // OBX-10 + sb.append("|"); + // OBX-11 + sb.append("|"); + sb.append("F"); + sb.append("\r"); + } + + public void printObx(StringBuilder sb, int obxSetId, int obsSubId, ObservationReported ob) { // ObservationReported ob = observation.getObservationReported(); - sb.append("OBX"); - // OBX-1 - sb.append("|"); - sb.append(obxSetId); - // OBX-2 - sb.append("|"); - sb.append(ob.getValueType()); - // OBX-3 - sb.append("|"); - sb.append(ob.getIdentifierCode()).append("^").append(ob.getIdentifierLabel()).append("^").append(ob.getIdentifierTable()); - // OBX-4 - sb.append("|"); - sb.append(obsSubId); - // OBX-5 - sb.append("|"); - if (StringUtils.isBlank(ob.getValueTable())) { - sb.append(ob.getValueCode()); - } else { - sb.append(ob.getValueCode()).append("^").append(ob.getValueLabel()).append("^").append(ob.getValueTable()); - } - // OBX-6 - sb.append("|"); - if (StringUtils.isBlank(ob.getUnitsTable())) { - sb.append(ob.getUnitsCode()); - } else { - sb.append(ob.getUnitsCode()).append("^").append(ob.getUnitsLabel()).append("^").append(ob.getUnitsTable()); - } - // OBX-7 - sb.append("|"); - // OBX-8 - sb.append("|"); - // OBX-9 - sb.append("|"); - // OBX-10 - sb.append("|"); - // OBX-11 - sb.append("|"); - sb.append(ob.getResultStatus()); - // OBX-12 - sb.append("|"); - // OBX-13 - sb.append("|"); - // OBX-14 - sb.append("|"); - if (ob.getObservationDate() != null) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - sb.append(sdf.format(ob.getObservationDate())); - } - // OBX-15 - sb.append("|"); - // OBX-16 - sb.append("|"); - // OBX-17 - sb.append("|"); - if (StringUtils.isBlank(ob.getMethodTable())) { - sb.append(ob.getMethodCode()); - } else { - sb.append(ob.getMethodCode()).append("^").append(ob.getMethodLabel()).append("^").append(ob.getMethodTable()); - } - sb.append("\r"); - } - - public void printObx(StringBuilder sb, int obxSetId, int obsSubId, String loinc, - String loincLabel, String value, String valueLabel, String valueTable) { - sb.append("OBX"); - // OBX-1 - sb.append("|"); - sb.append(obxSetId); - // OBX-2 - sb.append("|"); - sb.append("CE"); - // OBX-3 - sb.append("|"); - sb.append(loinc).append("^").append(loincLabel).append("^LN"); - // OBX-4 - sb.append("|"); - sb.append(obsSubId); - // OBX-5 - sb.append("|"); - sb.append(value).append("^").append(valueLabel).append("^").append(valueTable); - // OBX-6 - sb.append("|"); - // OBX-7 - sb.append("|"); - // OBX-8 - sb.append("|"); - // OBX-9 - sb.append("|"); - // OBX-10 - sb.append("|"); - // OBX-11 - sb.append("|"); - sb.append("F"); - sb.append("\r"); - } - - - public void printObx(StringBuilder sb, int obxSetId, int obsSubId, String loinc, - String loincLabel, Date value) { - sb.append("OBX"); - // OBX-1 - sb.append("|"); - sb.append(obxSetId); - // OBX-2 - sb.append("|"); - sb.append("DT"); - // OBX-3 - sb.append("|"); - sb.append(loinc).append("^").append(loincLabel).append("^LN"); - // OBX-4 - sb.append("|"); - sb.append(obsSubId); - // OBX-5 - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - sb.append("|"); - if (value != null) { - sb.append(sdf.format(value)); - } - // OBX-6 - sb.append("|"); - // OBX-7 - sb.append("|"); - // OBX-8 - sb.append("|"); - // OBX-9 - sb.append("|"); - // OBX-10 - sb.append("|"); - // OBX-11 - sb.append("|"); - sb.append("F"); - sb.append("\r"); - } - - public String printCode(String value, CodesetType codesetType, String tableName, - CodeMap codeMap) { - if (value != null) { - Code code = codeMap.getCodeForCodeset(codesetType, value); - if (code != null) { - if (tableName == null) { - return code.getValue(); - } - return code.getValue() + "^" + code.getLabel() + "^" + tableName; - } - } - return ""; - } - - public String buildAck(HL7Reader reader, List processingExceptionList, Set processingFlavorSet) { - StringBuilder sb = new StringBuilder(); - { - String messageType = "ACK^V04^ACK"; - String profileId = Z23_ACKNOWLEDGEMENT; - createMSH(messageType, profileId, reader, sb, processingFlavorSet); - } - - // if processing flavor contains MEDLAR then all the non E errors have to removed from the processing list - if (processingFlavorSet.contains(ProcessingFlavor.MEDLAR)) { - List tempProcessingExceptionList = new ArrayList(); - for (ProcessingException pe : processingExceptionList) { - if (pe.isError()) { - tempProcessingExceptionList.add(pe); - } - } - processingExceptionList = tempProcessingExceptionList; - } - - String sendersUniqueId = ""; - reader.resetPostion(); - if (reader.advanceToSegment("MSH")) { - sendersUniqueId = reader.getValue(10); - } else { - sendersUniqueId = "MSH NOT FOUND"; - } - if (sendersUniqueId.isBlank()) { - sendersUniqueId = "MSH-10 NOT VALUED"; - } - String overallStatus = "AA"; - for (ProcessingException pe : processingExceptionList) { - if (pe.isError() || pe.isWarning()) { - overallStatus = "AE"; - break; - } - } - - sb.append("MSA|").append(overallStatus).append("|").append(sendersUniqueId).append("\r"); - for (ProcessingException pe : processingExceptionList) { - printERRSegment(pe, sb); - } - return sb.toString(); - } - - public void printERRSegment(ProcessingException e, StringBuilder sb) { - sb.append("ERR|"); - sb.append("|"); // 2 - if (StringUtils.isNotBlank(e.getSegmentId())) { - sb.append(e.getSegmentId()).append("^").append(e.getSegmentRepeat()); - if (e.getFieldPosition() > 0) { - sb.append("^").append(e.getFieldPosition()); - } - } - sb.append("|101^Required field missing^HL70357"); // 3 - sb.append("|"); // 4 - if (e.isError()) { - sb.append("E"); - } else if (e.isWarning()) { - sb.append("W"); - } else if (e.isInformation()) { - sb.append("I"); - } - sb.append("|"); // 5 - sb.append("|"); // 6 - sb.append("|"); // 7 - sb.append("|").append(e.getMessage()); // 8 - sb.append("|\r"); - } - - public void createMSH(String messageType, String profileId, HL7Reader reader, StringBuilder sb, - Set processingFlavorSet) { - String sendingApp = ""; - String sendingFac = ""; - String receivingApp = ""; - StringBuilder receivingFac = new StringBuilder("IIS Sandbox"); - if (processingFlavorSet != null) { - for (ProcessingFlavor processingFlavor : ProcessingFlavor.values()) { - if (processingFlavorSet.contains(processingFlavor)) { - receivingFac.append(" ").append(processingFlavor.getKey()); - } - } - } - receivingFac.append(" v" + SoftwareVersion.VERSION); - - reader.resetPostion(); - if (reader.advanceToSegment("MSH")) { - sendingApp = reader.getValue(3); - sendingFac = reader.getValue(4); - receivingApp = reader.getValue(5); - } - - - String sendingDateString; - { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmssZ"); - sendingDateString = simpleDateFormat.format(new Date()); - } - String uniqueId; - { - uniqueId = "" + System.currentTimeMillis() + nextIncrement(); - } - String production = reader.getValue(11); - // build MSH - sb.append("MSH|^~\\&|"); - sb.append(receivingApp).append("|"); - sb.append(receivingFac).append("|"); - sb.append(sendingApp).append("|"); - sb.append(sendingFac).append("|"); - sb.append(sendingDateString).append("|"); - sb.append("|"); - if (processingFlavorSet != null && processingFlavorSet.contains(ProcessingFlavor.MELON)) { - int pos = messageType.indexOf("^"); - if (pos > 0) { - messageType = messageType.substring(0, pos); - if (System.currentTimeMillis() % 2 == 0) { - messageType += "^ZZZ"; - } - } - } - sb.append(messageType).append("|"); - sb.append(uniqueId).append("|"); - sb.append(production).append("|"); - sb.append("2.5.1|"); - sb.append("|"); - sb.append("|"); - sb.append("NE|"); - sb.append("NE|"); - sb.append("|"); - sb.append("|"); - sb.append("|"); - sb.append("|"); - sb.append(profileId).append("^CDCPHINVS\r"); - } - - private static Integer increment = 1; - - private static int nextIncrement() { - synchronized (increment) { - if (increment < Integer.MAX_VALUE) { - increment = increment + 1; - } else { - increment = 1; - } - return increment; - } - } - - public Date parseDateWarn(String dateString, String errorMessage, String segmentId, - int segmentRepeat, int fieldPosition, boolean strict, - List processingExceptionList) { - try { - return parseDateInternal(dateString, strict); - } catch (ParseException e) { - if (errorMessage != null) { - ProcessingException pe = new ProcessingException(errorMessage + ": " + e.getMessage(), - segmentId, segmentRepeat, fieldPosition).setWarning(); - processingExceptionList.add(pe); - } - } - return null; - } - - public Date parseDateError(String dateString, String errorMessage, String segmentId, - int segmentRepeat, int fieldPosition, boolean strict) throws ProcessingException { - try { - Date date = parseDateInternal(dateString, strict); - if (date == null) { - if (errorMessage != null) { - throw new ProcessingException(errorMessage + ": No date was specified", segmentId, - segmentRepeat, fieldPosition); - } - } - return date; - } catch (ParseException e) { - if (errorMessage != null) { - throw new ProcessingException(errorMessage + ": " + e.getMessage(), segmentId, - segmentRepeat, fieldPosition); - } - } - return null; - } - - public Date parseDateInternal(String dateString, boolean strict) throws ParseException { - if (dateString.length() == 0) { - return null; - } - Date date; - if (dateString.length() > 8) { - dateString = dateString.substring(0, 8); - } - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); - simpleDateFormat.setLenient(!strict); - date = simpleDateFormat.parse(dateString); - return date; - } - - protected static final Random random = new Random(); + sb.append("OBX"); + // OBX-1 + sb.append("|"); + sb.append(obxSetId); + // OBX-2 + sb.append("|"); + sb.append(ob.getValueType()); + // OBX-3 + sb.append("|"); + sb.append(ob.getIdentifierCode()).append("^").append(ob.getIdentifierLabel()).append("^").append(ob.getIdentifierTable()); + // OBX-4 + sb.append("|"); + sb.append(obsSubId); + // OBX-5 + sb.append("|"); + if (StringUtils.isBlank(ob.getValueTable())) { + sb.append(ob.getValueCode()); + } else { + sb.append(ob.getValueCode()).append("^").append(ob.getValueLabel()).append("^").append(ob.getValueTable()); + } + // OBX-6 + sb.append("|"); + if (StringUtils.isBlank(ob.getUnitsTable())) { + sb.append(ob.getUnitsCode()); + } else { + sb.append(ob.getUnitsCode()).append("^").append(ob.getUnitsLabel()).append("^").append(ob.getUnitsTable()); + } + // OBX-7 + sb.append("|"); + // OBX-8 + sb.append("|"); + // OBX-9 + sb.append("|"); + // OBX-10 + sb.append("|"); + // OBX-11 + sb.append("|"); + sb.append(ob.getResultStatus()); + // OBX-12 + sb.append("|"); + // OBX-13 + sb.append("|"); + // OBX-14 + sb.append("|"); + if (ob.getObservationDate() != null) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + sb.append(sdf.format(ob.getObservationDate())); + } + // OBX-15 + sb.append("|"); + // OBX-16 + sb.append("|"); + // OBX-17 + sb.append("|"); + if (StringUtils.isBlank(ob.getMethodTable())) { + sb.append(ob.getMethodCode()); + } else { + sb.append(ob.getMethodCode()).append("^").append(ob.getMethodLabel()).append("^").append(ob.getMethodTable()); + } + sb.append("\r"); + } + + public void printObx(StringBuilder sb, int obxSetId, int obsSubId, String loinc, String loincLabel, String value, String valueLabel, String valueTable) { + sb.append("OBX"); + // OBX-1 + sb.append("|"); + sb.append(obxSetId); + // OBX-2 + sb.append("|"); + sb.append("CE"); + // OBX-3 + sb.append("|"); + sb.append(loinc).append("^").append(loincLabel).append("^LN"); + // OBX-4 + sb.append("|"); + sb.append(obsSubId); + // OBX-5 + sb.append("|"); + sb.append(value).append("^").append(valueLabel).append("^").append(valueTable); + // OBX-6 + sb.append("|"); + // OBX-7 + sb.append("|"); + // OBX-8 + sb.append("|"); + // OBX-9 + sb.append("|"); + // OBX-10 + sb.append("|"); + // OBX-11 + sb.append("|"); + sb.append("F"); + sb.append("\r"); + } + + public void printObx(StringBuilder sb, int obxSetId, int obsSubId, String loinc, String loincLabel, Date value) { + sb.append("OBX"); + // OBX-1 + sb.append("|"); + sb.append(obxSetId); + // OBX-2 + sb.append("|"); + sb.append("DT"); + // OBX-3 + sb.append("|"); + sb.append(loinc).append("^").append(loincLabel).append("^LN"); + // OBX-4 + sb.append("|"); + sb.append(obsSubId); + // OBX-5 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + sb.append("|"); + if (value != null) { + sb.append(sdf.format(value)); + } + // OBX-6 + sb.append("|"); + // OBX-7 + sb.append("|"); + // OBX-8 + sb.append("|"); + // OBX-9 + sb.append("|"); + // OBX-10 + sb.append("|"); + // OBX-11 + sb.append("|"); + sb.append("F"); + sb.append("\r"); + } + + public String printCode(String value, CodesetType codesetType, String tableName, CodeMap codeMap) { + if (value != null) { + Code code = codeMap.getCodeForCodeset(codesetType, value); + if (code != null) { + if (tableName == null) { + return code.getValue(); + } + return code.getValue() + "^" + code.getLabel() + "^" + tableName; + } + } + return ""; + } + + public String buildAck(HL7Reader reader, List processingExceptionList, Set processingFlavorSet) { + StringBuilder sb = new StringBuilder(); + { + String messageType = "ACK^V04^ACK"; + String profileId = Z23_ACKNOWLEDGEMENT; + createMSH(messageType, profileId, reader, sb, processingFlavorSet); + } + + // if processing flavor contains MEDLAR then all the non E errors have to removed from the processing list + if (processingFlavorSet.contains(ProcessingFlavor.MEDLAR)) { + List tempProcessingExceptionList = new ArrayList(); + for (ProcessingException pe : processingExceptionList) { + if (pe.isError()) { + tempProcessingExceptionList.add(pe); + } + } + processingExceptionList = tempProcessingExceptionList; + } + + String sendersUniqueId = ""; + reader.resetPostion(); + if (reader.advanceToSegment("MSH")) { + sendersUniqueId = reader.getValue(10); + } else { + sendersUniqueId = "MSH NOT FOUND"; + } + if (sendersUniqueId.isBlank()) { + sendersUniqueId = "MSH-10 NOT VALUED"; + } + String overallStatus = "AA"; + for (ProcessingException pe : processingExceptionList) { + if (pe.isError() || pe.isWarning()) { + overallStatus = "AE"; + break; + } + } + + sb.append("MSA|").append(overallStatus).append("|").append(sendersUniqueId).append("\r"); + for (ProcessingException pe : processingExceptionList) { + printERRSegment(pe, sb); + } + return sb.toString(); + } + + public void printERRSegment(ProcessingException e, StringBuilder sb) { + sb.append("ERR|"); + sb.append("|"); // 2 + if (StringUtils.isNotBlank(e.getSegmentId())) { + sb.append(e.getSegmentId()).append("^").append(e.getSegmentRepeat()); + if (e.getFieldPosition() > 0) { + sb.append("^").append(e.getFieldPosition()); + } + } + sb.append("|101^Required field missing^HL70357"); // 3 + sb.append("|"); // 4 + if (e.isError()) { + sb.append("E"); + } else if (e.isWarning()) { + sb.append("W"); + } else if (e.isInformation()) { + sb.append("I"); + } + sb.append("|"); // 5 + sb.append("|"); // 6 + sb.append("|"); // 7 + sb.append("|").append(e.getMessage()); // 8 + sb.append("|\r"); + } + + public void createMSH(String messageType, String profileId, HL7Reader reader, StringBuilder sb, Set processingFlavorSet) { + String sendingApp = ""; + String sendingFac = ""; + String receivingApp = ""; + StringBuilder receivingFac = new StringBuilder("IIS Sandbox"); + if (processingFlavorSet != null) { + for (ProcessingFlavor processingFlavor : ProcessingFlavor.values()) { + if (processingFlavorSet.contains(processingFlavor)) { + receivingFac.append(" ").append(processingFlavor.getKey()); + } + } + } + receivingFac.append(" v" + SoftwareVersion.VERSION); + + reader.resetPostion(); + if (reader.advanceToSegment("MSH")) { + sendingApp = reader.getValue(3); + sendingFac = reader.getValue(4); + receivingApp = reader.getValue(5); + } + + + String sendingDateString; + { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmssZ"); + sendingDateString = simpleDateFormat.format(new Date()); + } + String uniqueId; + { + uniqueId = String.valueOf(System.currentTimeMillis()) + nextIncrement(); + } + String production = reader.getValue(11); + // build MSH + sb.append("MSH|^~\\&|"); + sb.append(receivingApp).append("|"); + sb.append(receivingFac).append("|"); + sb.append(sendingApp).append("|"); + sb.append(sendingFac).append("|"); + sb.append(sendingDateString).append("|"); + sb.append("|"); + if (processingFlavorSet != null && processingFlavorSet.contains(ProcessingFlavor.MELON)) { + int pos = messageType.indexOf("^"); + if (pos > 0) { + messageType = messageType.substring(0, pos); + if (System.currentTimeMillis() % 2 == 0) { + messageType += "^ZZZ"; + } + } + } + sb.append(messageType).append("|"); + sb.append(uniqueId).append("|"); + sb.append(production).append("|"); + sb.append("2.5.1|"); + sb.append("|"); + sb.append("|"); + sb.append("NE|"); + sb.append("NE|"); + sb.append("|"); + sb.append("|"); + sb.append("|"); + sb.append("|"); + sb.append(profileId).append("^CDCPHINVS\r"); + } + + public Date parseDateWarn(String dateString, String errorMessage, String segmentId, int segmentRepeat, int fieldPosition, boolean strict, List processingExceptionList) { + try { + return parseDateInternal(dateString, strict); + } catch (ParseException e) { + if (errorMessage != null) { + ProcessingException pe = new ProcessingException(errorMessage + ": " + e.getMessage(), segmentId, segmentRepeat, fieldPosition).setWarning(); + processingExceptionList.add(pe); + } + } + return null; + } + + public Date parseDateError(String dateString, String errorMessage, String segmentId, int segmentRepeat, int fieldPosition, boolean strict) throws ProcessingException { + try { + Date date = parseDateInternal(dateString, strict); + if (date == null) { + if (errorMessage != null) { + throw new ProcessingException(errorMessage + ": No date was specified", segmentId, segmentRepeat, fieldPosition); + } + } + return date; + } catch (ParseException e) { + if (errorMessage != null) { + throw new ProcessingException(errorMessage + ": " + e.getMessage(), segmentId, segmentRepeat, fieldPosition); + } + } + return null; + } + + public Date parseDateInternal(String dateString, boolean strict) throws ParseException { + if (dateString.length() == 0) { + return null; + } + Date date; + if (dateString.length() > 8) { + dateString = dateString.substring(0, 8); + } + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); + simpleDateFormat.setLenient(!strict); + date = simpleDateFormat.parse(dateString); + return date; + } } diff --git a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR4.java b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR4.java index ed3f3c5a..b20e00be 100644 --- a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR4.java +++ b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR4.java @@ -49,18 +49,15 @@ public String process(String message, Tenant tenant, String sendingFacilityName) if (processingFlavorSet.contains(ProcessingFlavor.SOURSOP)) { if (!facilityId.equals(tenant.getOrganizationName())) { - throw new ProcessingException("Not allowed to submit for facility indicated in MSH-4", - "MSH", 1, 4); + throw new ProcessingException("Not allowed to submit for facility indicated in MSH-4", "MSH", 1, 4); } } Organization sendingOrganization = null; - if (StringUtils.isNotBlank(sendingFacilityName) && !sendingFacilityName.equals("null")){ - sendingOrganization = (Organization) fhirRequester.searchOrganization( - new SearchParameterMap(Organization.SP_NAME, new StringParam(sendingFacilityName))); + if (StringUtils.isNotBlank(sendingFacilityName) && !sendingFacilityName.equals("null")) { + sendingOrganization = (Organization) fhirRequester.searchOrganization(new SearchParameterMap(Organization.SP_NAME, new StringParam(sendingFacilityName))); // Organization.NAME.matches().value(sendingFacilityName)); if (sendingOrganization == null) { - sendingOrganization = (Organization) fhirRequester.saveOrganization(new Organization() - .setName(sendingFacilityName)); + sendingOrganization = (Organization) fhirRequester.saveOrganization(new Organization().setName(sendingFacilityName)); } } @@ -85,16 +82,14 @@ public String process(String message, Tenant tenant, String sendingFacilityName) List processingExceptionList = new ArrayList<>(); processingExceptionList.add(pe); responseMessage = buildAck(reader, processingExceptionList, processingFlavorSet); - recordMessageReceived(message, null, responseMessage, "Unknown", "NAck", - tenant); + recordMessageReceived(message, null, responseMessage, "Unknown", "NAck", tenant); break; } } catch (Exception e) { e.printStackTrace(System.err); List processingExceptionList = new ArrayList<>(); - processingExceptionList.add(new ProcessingException( - "Internal error prevented processing: " + e.getMessage(), null, 0, 0)); + processingExceptionList.add(new ProcessingException("Internal error prevented processing: " + e.getMessage(), null, 0, 0)); responseMessage = buildAck(reader, processingExceptionList, processingFlavorSet); } return responseMessage; @@ -124,8 +119,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived String patientNameMiddle = reader.getValue(4, 3); boolean strictDate = false; - Date patientBirthDate = parseDateWarn(reader.getValue(6), "Invalid patient birth date", "QPD", - 1, 6, strictDate, processingExceptionList); + Date patientBirthDate = parseDateWarn(reader.getValue(6), "Invalid patient birth date", "QPD", 1, 6, strictDate, processingExceptionList); String patientSex = reader.getValue(7); if (patientNameLast.equals("")) { @@ -152,10 +146,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived Set processingFlavorSet = tenant.getProcessingFlavorSet(); Date cutoff = null; - if (processingFlavorSet.contains(ProcessingFlavor.SNAIL) - || processingFlavorSet.contains(ProcessingFlavor.SNAIL30) - || processingFlavorSet.contains(ProcessingFlavor.SNAIL60) - || processingFlavorSet.contains(ProcessingFlavor.SNAIL90)) { + if (processingFlavorSet.contains(ProcessingFlavor.SNAIL) || processingFlavorSet.contains(ProcessingFlavor.SNAIL30) || processingFlavorSet.contains(ProcessingFlavor.SNAIL60) || processingFlavorSet.contains(ProcessingFlavor.SNAIL90)) { Calendar calendar = Calendar.getInstance(); int seconds = -30; if (processingFlavorSet.contains(ProcessingFlavor.SNAIL30)) { @@ -187,9 +178,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived } List multipleMatches = new ArrayList<>(); PatientMaster singleMatch = null; - Bundle matches = repositoryClientFactory.getFhirClient().operation().onType(Patient.class).named("match") - .withParameter(Parameters.class, "resource", ((PatientMapperR4) patientMapper).getFhirResource(patientMasterForMatchQuery)) - .returnResourceType(Bundle.class).execute(); + Bundle matches = repositoryClientFactory.getFhirClient().operation().onType(Patient.class).named("match").withParameter(Parameters.class, "resource", ((PatientMapperR4) patientMapper).getFhirResource(patientMasterForMatchQuery)).returnResourceType(Bundle.class).execute(); for (Bundle.BundleEntryComponent entry : matches.getEntry()) { if (entry.getResource() instanceof Patient) { Patient patient = (Patient) entry.getResource(); @@ -216,8 +205,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived } - return buildRSP(reader, messageReceived, singleMatch, tenant, - multipleMatches, processingExceptionList); + return buildRSP(reader, messageReceived, singleMatch, tenant, multipleMatches, processingExceptionList); } @SuppressWarnings("unchecked") @@ -228,8 +216,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi CodeMap codeMap = CodeMapManager.getCodeMap(); boolean strictDate = !processingFlavorSet.contains(ProcessingFlavor.CANTALOUPE); - PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, - processingFlavorSet, codeMap, strictDate, null, managingOrganization); + PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, processingFlavorSet, codeMap, strictDate, null, managingOrganization); int orcCount = 0; @@ -249,28 +236,21 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi rxaCount++; vaccineCode = reader.getValue(5, 1); if (vaccineCode.equals("")) { - throw new ProcessingException("Vaccine code is not indicated in RXA-5.1", "RXA", - rxaCount, 5); + throw new ProcessingException("Vaccine code is not indicated in RXA-5.1", "RXA", rxaCount, 5); } if (vaccineCode.equals("998")) { - obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, - strictDate, obxCount, null, null); + obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, null, null); continue; } if (vaccinationReportedExternalLink.equals("")) { - throw new ProcessingException("Vaccination order id was not found, unable to process", - "ORC", orcCount, 3); + throw new ProcessingException("Vaccination order id was not found, unable to process", "ORC", orcCount, 3); } - administrationDate = parseDateError(reader.getValue(3, 1), - "Could not read administered date in RXA-5", "RXA", rxaCount, 3, strictDate); + administrationDate = parseDateError(reader.getValue(3, 1), "Could not read administered date in RXA-5", "RXA", rxaCount, 3, strictDate); if (administrationDate.after(new Date())) { - throw new ProcessingException( - "Vaccination is indicated as occuring in the future, unable to accept future vaccination events", - "RXA", rxaCount, 3); + throw new ProcessingException("Vaccination is indicated as occuring in the future, unable to accept future vaccination events", "RXA", rxaCount, 3); } - vaccinationReported = fhirRequester.searchVaccinationReported( - new SearchParameterMap(Immunization.SP_IDENTIFIER, new TokenParam().setValue(vaccinationReportedExternalLink))); + vaccinationReported = fhirRequester.searchVaccinationReported(new SearchParameterMap(Immunization.SP_IDENTIFIER, new TokenParam().setValue(vaccinationReportedExternalLink))); // Immunization.IDENTIFIER.exactly().code(vaccinationReportedExternalLink)); if (vaccinationReported != null) { // vaccinationMaster = vaccinationReported.getVaccination(); @@ -291,8 +271,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi String vaccineCodeType = reader.getValue(5, 3); if (vaccineCodeType.equals("NDC")) { vaccineNdcCode = vaccineCode; - } else if (vaccineCodeType.equals("CPT") || vaccineCodeType.equals("C4") - || vaccineCodeType.equals("C5")) { + } else if (vaccineCodeType.equals("CPT") || vaccineCodeType.equals("C4") || vaccineCodeType.equals("C5")) { vaccineCptCode = vaccineCode; } else { vaccineCvxCode = vaccineCode; @@ -305,8 +284,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi if (vaccineNdcCode.equals("")) { vaccineNdcCode = altVaccineCode; } - } else if (altVaccineCodeType.equals("CPT") || altVaccineCodeType.equals("C4") - || altVaccineCodeType.equals("C5")) { + } else if (altVaccineCodeType.equals("CPT") || altVaccineCodeType.equals("C4") || altVaccineCodeType.equals("C5")) { if (vaccineCptCode.equals("")) { vaccineCptCode = altVaccineCode; } @@ -319,29 +297,21 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } { - Code ndcCode = - codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, vaccineNdcCode); + Code ndcCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, vaccineNdcCode); if (ndcCode != null) { - if (ndcCode.getCodeStatus() != null && ndcCode.getCodeStatus().getDeprecated() != null - && ndcCode.getCodeStatus().getDeprecated().getNewCodeValue() != null - && !ndcCode.getCodeStatus().getDeprecated().getNewCodeValue().equals("")) { + if (ndcCode.getCodeStatus() != null && ndcCode.getCodeStatus().getDeprecated() != null && ndcCode.getCodeStatus().getDeprecated().getNewCodeValue() != null && !ndcCode.getCodeStatus().getDeprecated().getNewCodeValue().equals("")) { vaccineNdcCode = ndcCode.getCodeStatus().getDeprecated().getNewCodeValue(); } Code cvxCode = codeMap.getRelatedCode(ndcCode, CodesetType.VACCINATION_CVX_CODE); if (cvxCode == null) { - ProcessingException pe = - new ProcessingException("Unrecognized NDC " + vaccineNdcCode, "RXA", rxaCount, - 5).setWarning(); + ProcessingException pe = new ProcessingException("Unrecognized NDC " + vaccineNdcCode, "RXA", rxaCount, 5).setWarning(); processingExceptionList.add(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); + 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); } @@ -349,41 +319,31 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } } { - Code cptCode = - codeMap.getCodeForCodeset(CodesetType.VACCINATION_CPT_CODE, vaccineCptCode); + Code cptCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CPT_CODE, vaccineCptCode); if (cptCode != null) { Code cvxCode = codeMap.getRelatedCode(cptCode, CodesetType.VACCINATION_CVX_CODE); if (cvxCode == null) { - ProcessingException pe = - new ProcessingException("Unrecognized CPT " + cptCode, "RXA", rxaCount, 5) - .setWarning(); + ProcessingException pe = new ProcessingException("Unrecognized CPT " + cptCode, "RXA", rxaCount, 5).setWarning(); processingExceptionList.add(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(); + 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); } } } } if (vaccineCvxCode.equals("")) { - throw new ProcessingException( - "Unable to find a recognized vaccine administration code (CVX, NDC, or CPT)", "RXA", - rxaCount, 5); + throw new ProcessingException("Unable to find a recognized vaccine administration code (CVX, NDC, or CPT)", "RXA", rxaCount, 5); } else { - Code cvxCode = - codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccineCvxCode); + Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccineCvxCode); if (cvxCode != null) { vaccineCvxCode = cvxCode.getValue(); } else { - throw new ProcessingException("Unrecognized CVX vaccine '" + vaccineCvxCode + "'", - "RXA", rxaCount, 5); + throw new ProcessingException("Unrecognized CVX vaccine '" + vaccineCvxCode + "'", "RXA", rxaCount, 5); } } @@ -392,15 +352,12 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi { String administeredAtLocation = reader.getValue(11, 4); if (StringUtils.isNotEmpty(administeredAtLocation)) { - OrgLocation orgLocation = fhirRequester.searchOrgLocation( - new SearchParameterMap(Location.SP_IDENTIFIER, new TokenParam().setValue(administeredAtLocation))); + OrgLocation orgLocation = fhirRequester.searchOrgLocation(new SearchParameterMap(Location.SP_IDENTIFIER, new TokenParam().setValue(administeredAtLocation))); // Location.IDENTIFIER.exactly().code(administeredAtLocation)); if (orgLocation == null) { if (processingFlavorSet.contains(ProcessingFlavor.PEAR)) { - throw new ProcessingException( - "Unrecognized administered at location, unable to accept immunization report", - "RXA", rxaCount, 11); + throw new ProcessingException("Unrecognized administered at location, unable to accept immunization report", "RXA", rxaCount, 11); } orgLocation = new OrgLocation(); orgLocation.setOrgFacilityCode(administeredAtLocation); @@ -421,8 +378,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi { String administeringProvider = reader.getValue(10); if (StringUtils.isNotEmpty(administeringProvider)) { - ModelPerson modelPerson = fhirRequester.searchPractitioner( - new SearchParameterMap(Practitioner.SP_IDENTIFIER, new TokenParam().setValue(administeringProvider))); + ModelPerson modelPerson = fhirRequester.searchPractitioner(new SearchParameterMap(Practitioner.SP_IDENTIFIER, new TokenParam().setValue(administeringProvider))); // Practitioner.IDENTIFIER.exactly().code(administeringProvider)); if (modelPerson == null) { modelPerson = new ModelPerson(); @@ -451,18 +407,14 @@ 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( - parseDateWarn(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)); if (!vaccinationReported.getRefusalReasonCode().equals("")) { - Code refusalCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_REFUSAL, - vaccinationReported.getRefusalReasonCode()); + Code refusalCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_REFUSAL, vaccinationReported.getRefusalReasonCode()); if (refusalCode == null) { - ProcessingException pe = - new ProcessingException("Unrecognized refusal reason", "RXA", rxaCount, 18); + ProcessingException pe = new ProcessingException("Unrecognized refusal reason", "RXA", rxaCount, 18); pe.setWarning(); processingExceptionList.add(pe); } @@ -474,22 +426,13 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi vaccinationReported.setBodySite(reader.getValue(2)); } else if (processingFlavorSet.contains(ProcessingFlavor.SPRUCE)) { if (vaccinationReported.getInformationSource().equals("00")) { - throw new ProcessingException("RXR segment is required for administered vaccinations", - "RXA", rxaCount, 0); + throw new ProcessingException("RXR segment is required for administered vaccinations", "RXA", rxaCount, 0); } } - if (vaccinationReported.getAdministeredDate() - .before(patientReported.getBirthDate()) - && !processingFlavorSet.contains(ProcessingFlavor.CLEMENTINE)) { - throw new ProcessingException( - "Vaccination is reported as having been administered before the patient was born", - "RXA", rxaCount, 3); + if (vaccinationReported.getAdministeredDate().before(patientReported.getBirthDate()) && !processingFlavorSet.contains(ProcessingFlavor.CLEMENTINE)) { + throw new ProcessingException("Vaccination is reported as having been administered before the patient was born", "RXA", rxaCount, 3); } - if (!vaccinationReported.getVaccineCvxCode().equals("998") - && !vaccinationReported.getVaccineCvxCode().equals("999") - && (vaccinationReported.getCompletionStatus().equals("CP") - || vaccinationReported.getCompletionStatus().equals("PA") - || vaccinationReported.getCompletionStatus().equals(""))) { + if (!vaccinationReported.getVaccineCvxCode().equals("998") && !vaccinationReported.getVaccineCvxCode().equals("999") && (vaccinationReported.getCompletionStatus().equals("CP") || vaccinationReported.getCompletionStatus().equals("PA") || vaccinationReported.getCompletionStatus().equals(""))) { vaccinationCount++; } @@ -506,12 +449,9 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi if (indicator.equals("64994-7")) { String fundingEligibility = reader.getValue(5); if (!fundingEligibility.equals("")) { - Code fundingEligibilityCode = codeMap - .getCodeForCodeset(CodesetType.FINANCIAL_STATUS_CODE, fundingEligibility); + 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(); + ProcessingException pe = new ProcessingException("Funding eligibility '" + fundingEligibility + "' was not recognized", "OBX", tempObxCount, 5).setWarning(); processingExceptionList.add(pe); } else { vaccinationReported.setFundingEligibility(fundingEligibilityCode.getValue()); @@ -520,12 +460,9 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } else if (indicator.equals("30963-3")) { String fundingSource = reader.getValue(5); if (!fundingSource.equals("")) { - Code fundingSourceCode = codeMap - .getCodeForCodeset(CodesetType.VACCINATION_FUNDING_SOURCE, fundingSource); + 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(); + ProcessingException pe = new ProcessingException("Funding source '" + fundingSource + "' was not recognized", "OBX", tempObxCount, 5).setWarning(); processingExceptionList.add(pe); } else { vaccinationReported.setFundingSource(fundingSourceCode.getValue()); @@ -538,23 +475,16 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi reader.gotoSegmentPosition(segmentPosition); vaccinationReported = fhirRequester.saveVaccinationReported(vaccinationReported); reader.gotoSegmentPosition(segmentPosition); - obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, - strictDate, obxCount, vaccinationReported, null); + obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, vaccinationReported, null); } else { - throw new ProcessingException("RXA segment was not found after ORC segment", "ORC", - orcCount, 0); + throw new ProcessingException("RXA segment was not found after ORC segment", "ORC", orcCount, 0); } } if (processingFlavorSet.contains(ProcessingFlavor.CRANBERRY) && vaccinationCount == 0) { - throw new ProcessingException( - "Patient vaccination history cannot be accepted without at least one administered or historical vaccination specified", - "", 0, 0); + throw new ProcessingException("Patient vaccination history cannot be accepted without at least one administered or historical vaccination specified", "", 0, 0); } - if (processingFlavorSet.contains(ProcessingFlavor.BILBERRY) - && (vaccinationCount == 0 && refusalCount == 0)) { - throw new ProcessingException( - "Patient vaccination history cannot be accepted without at least one administered, historical, or refused vaccination specified", - "", 0, 0); + if (processingFlavorSet.contains(ProcessingFlavor.BILBERRY) && (vaccinationCount == 0 && refusalCount == 0)) { + throw new ProcessingException("Patient vaccination history cannot be accepted without at least one administered, historical, or refused vaccination specified", "", 0, 0); } String ack = buildAck(reader, processingExceptionList, processingFlavorSet); recordMessageReceived(message, patientReported, ack, "Update", "Ack", tenant); @@ -571,10 +501,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } @SuppressWarnings("unchecked") - public PatientReported processPatient(Tenant tenant, HL7Reader reader, - List processingExceptionList, Set processingFlavorSet, - CodeMap codeMap, boolean strictDate, PatientReported patientReported, Organization managingOrganization) - throws ProcessingException { + public PatientReported processPatient(Tenant tenant, HL7Reader reader, List processingExceptionList, Set processingFlavorSet, CodeMap codeMap, boolean strictDate, PatientReported patientReported, Organization managingOrganization) throws ProcessingException { String patientReportedExternalLink = ""; String patientReportedAuthority = ""; String patientReportedType = "MR"; @@ -584,29 +511,22 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, if (patientReportedExternalLink.equals("")) { patientReportedAuthority = ""; patientReportedType = "PT"; - patientReportedExternalLink = - reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); + patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5); if (patientReportedExternalLink.equals("")) { patientReportedAuthority = ""; patientReportedType = "PI"; - patientReportedExternalLink = - reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); - patientReportedAuthority = - reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5); + patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); + patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5); if (patientReportedExternalLink.equals("")) { - throw new ProcessingException( - "MRN was not found, required for accepting vaccination report", "PID", 1, 3); + throw new ProcessingException("MRN was not found, required for accepting vaccination report", "PID", 1, 3); } } } } else { - throw new ProcessingException( - "No PID segment found, required for accepting vaccination report", "", 0, 0); + throw new ProcessingException("No PID segment found, required for accepting vaccination report", "", 0, 0); } - patientReported = fhirRequester.searchPatientReported( - new SearchParameterMap("identifier",new TokenParam().setValue(patientReportedExternalLink)) - ); + patientReported = fhirRequester.searchPatientReported(new SearchParameterMap("identifier", new TokenParam().setValue(patientReportedExternalLink))); if (patientReported == null) { patientReported = new PatientReported(); @@ -626,8 +546,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String telUseCode = reader.getValue(13, 2); if (patientPhone.length() > 0) { if (!telUseCode.equals("PRN")) { - ProcessingException pe = new ProcessingException( - "Patient phone telecommunication type must be PRN ", "PID", 1, 13); + ProcessingException pe = new ProcessingException("Patient phone telecommunication type must be PRN ", "PID", 1, 13); if (!processingFlavorSet.contains(ProcessingFlavor.QUINZE)) { pe.setWarning(); } @@ -650,15 +569,12 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } } if (invalidCharFound) { - ProcessingException pe = new ProcessingException( - "Patient phone number has unexpected character: " + invalidChar, "PID", 1, 13); + ProcessingException pe = new ProcessingException("Patient phone number has unexpected character: " + invalidChar, "PID", 1, 13); pe.setWarning(); processingExceptionList.add(pe); } - if (countNums != 10 || patientPhone.startsWith("555") || patientPhone.startsWith("0") - || patientPhone.startsWith("1")) { - ProcessingException pe = new ProcessingException( - "Patient phone number does not appear to be valid", "PID", 1, 13); + if (countNums != 10 || patientPhone.startsWith("555") || patientPhone.startsWith("0") || patientPhone.startsWith("1")) { + ProcessingException pe = new ProcessingException("Patient phone number does not appear to be valid", "PID", 1, 13); pe.setWarning(); processingExceptionList.add(pe); } @@ -669,14 +585,10 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } if (patientNameLast.equals("")) { - throw new ProcessingException( - "Patient last name was not found, required for accepting patient and vaccination history", - "PID", 1, 5); + throw new ProcessingException("Patient last name was not found, required for accepting patient and vaccination history", "PID", 1, 5); } if (patientNameFirst.equals("")) { - throw new ProcessingException( - "Patient first name was not found, required for accepting patient and vaccination history", - "PID", 1, 5); + throw new ProcessingException("Patient first name was not found, required for accepting patient and vaccination history", "PID", 1, 5); } @@ -694,12 +606,9 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, addressFrag = zip + ":" + addressFragPrep; } Date patientBirthDate; - patientBirthDate = parseDateError(reader.getValue(7), "Bad format for date of birth", "PID", - 1, 7, strictDate); + patientBirthDate = parseDateError(reader.getValue(7), "Bad format for date of birth", "PID", 1, 7, strictDate); if (patientBirthDate.after(new Date())) { - throw new ProcessingException( - "Patient is indicated as being born in the future, unable to record patients who are not yet born", - "PID", 1, 7); + throw new ProcessingException("Patient is indicated as being born in the future, unable to record patients who are not yet born", "PID", 1, 7); } patientReported.setExternalLink(patientReportedExternalLink); patientReported.setPatientReportedType(patientReportedType); @@ -725,8 +634,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, patientReported.setEthnicity(reader.getValue(22)); patientReported.setBirthFlag(reader.getValue(24)); patientReported.setBirthOrder(reader.getValue(25)); - patientReported.setDeathDate(parseDateWarn(reader.getValue(29), - "Invalid patient death date", "PID", 1, 29, strictDate, processingExceptionList)); + patientReported.setDeathDate(parseDateWarn(reader.getValue(29), "Invalid patient death date", "PID", 1, 29, strictDate, processingExceptionList)); patientReported.setDeathFlag(reader.getValue(30)); patientReported.setEmail(reader.getValueBySearchingRepeats(13, 4, "NET", 2)); patientReported.setPhone(patientPhone); @@ -735,9 +643,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, { String patientSex = patientReported.getSex(); if (!ValidValues.verifyValidValue(patientSex, ValidValues.SEX)) { - ProcessingException pe = - new ProcessingException("Patient sex '" + patientSex + "' is not recognized", "PID", - 1, 8).setWarning(); + ProcessingException pe = new ProcessingException("Patient sex '" + patientSex + "' is not recognized", "PID", 1, 8).setWarning(); if (processingFlavorSet.contains(ProcessingFlavor.ELDERBERRIES)) { pe.setWarning(); } @@ -747,23 +653,19 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String patientAddressCountry = patientReported.getAddressCountry(); if (!patientAddressCountry.equals("")) { - if (!ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_2DIGIT) - && !ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_3DIGIT)) { - ProcessingException pe = new ProcessingException("Patient address country '" - + patientAddressCountry + "' is not recognized and cannot be accepted", "PID", 1, 11); + if (!ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_2DIGIT) && !ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_3DIGIT)) { + ProcessingException pe = new ProcessingException("Patient address country '" + patientAddressCountry + "' is not recognized and cannot be accepted", "PID", 1, 11); if (processingFlavorSet.contains(ProcessingFlavor.GUAVA)) { pe.setWarning(); } processingExceptionList.add(pe); } } - if (patientAddressCountry.equals("") || patientAddressCountry.equals("US") - || patientAddressCountry.equals("USA")) { + if (patientAddressCountry.equals("") || patientAddressCountry.equals("US") || patientAddressCountry.equals("USA")) { String patientAddressState = patientReported.getAddressState(); if (!patientAddressState.equals("")) { if (!ValidValues.verifyValidValue(patientAddressState, ValidValues.STATE)) { - ProcessingException pe = new ProcessingException("Patient address state '" - + patientAddressState + "' is not recognized and cannot be accepted", "PID", 1, 11); + ProcessingException pe = new ProcessingException("Patient address state '" + patientAddressState + "' is not recognized and cannot be accepted", "PID", 1, 11); if (processingFlavorSet.contains(ProcessingFlavor.GUAVA)) { pe.setWarning(); } @@ -777,10 +679,8 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String race = patientReported.getRace(); if (!race.equals("")) { Code raceCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_RACE, race); - if (raceCode == null - || CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID) { - ProcessingException pe = new ProcessingException( - "Invalid race '" + race + "', message cannot be accepted", "PID", 1, 10); + if (raceCode == null || CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID) { + ProcessingException pe = new ProcessingException("Invalid race '" + race + "', message cannot be accepted", "PID", 1, 10); if (!processingFlavorSet.contains(ProcessingFlavor.FIG)) { pe.setWarning(); } @@ -793,10 +693,8 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String ethnicity = patientReported.getEthnicity(); if (!ethnicity.equals("")) { Code ethnicityCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_ETHNICITY, ethnicity); - if (ethnicityCode == null - || CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID) { - ProcessingException pe = new ProcessingException( - "Invalid ethnicity '" + ethnicity + "', message cannot be accepted", "PID", 1, 10); + if (ethnicityCode == null || CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID) { + ProcessingException pe = new ProcessingException("Invalid ethnicity '" + ethnicity + "', message cannot be accepted", "PID", 1, 10); if (!processingFlavorSet.contains(ProcessingFlavor.FIG)) { pe.setWarning(); } @@ -806,12 +704,8 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } if (processingFlavorSet.contains(ProcessingFlavor.BLACKBERRY)) { - if (patientReported.getAddressLine1().equals("") - || patientReported.getAddressCity().equals("") - || patientReported.getAddressState().equals("") - || patientReported.getAddressZip().equals("")) { - throw new ProcessingException("Patient address is required but it was not sent", "PID", 1, - 11); + if (patientReported.getAddressLine1().equals("") || patientReported.getAddressCity().equals("") || patientReported.getAddressState().equals("") || patientReported.getAddressZip().equals("")) { + throw new ProcessingException("Patient address is required but it was not sent", "PID", 1, 11); } } @@ -822,8 +716,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, if (birthFlag.equals("") || birthFlag.equals("N")) { // The only acceptable value here is now blank or 1 if (!birthOrder.equals("1") && !birthOrder.equals("")) { - ProcessingException pe = new ProcessingException("Birth order was specified as " - + birthOrder + " but not indicated as multiple birth", "PID", 1, 25); + ProcessingException pe = new ProcessingException("Birth order was specified as " + birthOrder + " but not indicated as multiple birth", "PID", 1, 25); if (processingFlavorSet.contains(ProcessingFlavor.PLANTAIN)) { pe.setWarning(); } @@ -831,22 +724,18 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } } else if (birthFlag.equals("Y")) { if (birthOrder.equals("")) { - ProcessingException pe = new ProcessingException( - "Multiple birth but birth order was not specified", "PID", 1, 24); + ProcessingException pe = new ProcessingException("Multiple birth but birth order was not specified", "PID", 1, 24); pe.setWarning(); processingExceptionList.add(pe); } else if (!ValidValues.verifyValidValue(birthOrder, ValidValues.BIRTH_ORDER)) { - ProcessingException pe = - new ProcessingException("Birth order was specified as " + birthOrder - + " but not an expected value, must be between 1 and 9", "PID", 1, 25); + ProcessingException pe = new ProcessingException("Birth order was specified as " + birthOrder + " but not an expected value, must be between 1 and 9", "PID", 1, 25); if (processingFlavorSet.contains(ProcessingFlavor.PLANTAIN)) { pe.setWarning(); } processingExceptionList.add(pe); } } else { - ProcessingException pe = new ProcessingException( - "Multiple birth indicator " + birthFlag + " is not recognized", "PID", 1, 24); + ProcessingException pe = new ProcessingException("Multiple birth indicator " + birthFlag + " is not recognized", "PID", 1, 24); if (processingFlavorSet.contains(ProcessingFlavor.PLANTAIN)) { pe.setWarning(); } @@ -859,14 +748,10 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, if (reader.advanceToSegment("PD1")) { patientReported.setPublicityIndicator(reader.getValue(11)); patientReported.setProtectionIndicator(reader.getValue(12)); - patientReported.setProtectionIndicatorDate(parseDateWarn(reader.getValue(13), - "Invalid protection indicator date", "PD1", 1, 13, strictDate, processingExceptionList)); + patientReported.setProtectionIndicatorDate(parseDateWarn(reader.getValue(13), "Invalid protection indicator date", "PD1", 1, 13, strictDate, processingExceptionList)); patientReported.setRegistryStatusIndicator(reader.getValue(16)); - patientReported.setRegistryStatusIndicatorDate( - parseDateWarn(reader.getValue(17), "Invalid registry status indicator date", "PD1", 1, 17, - strictDate, processingExceptionList)); - patientReported.setPublicityIndicatorDate(parseDateWarn(reader.getValue(18), - "Invalid publicity indicator date", "PD1", 1, 18, strictDate, processingExceptionList)); + patientReported.setRegistryStatusIndicatorDate(parseDateWarn(reader.getValue(17), "Invalid registry status indicator date", "PD1", 1, 17, strictDate, processingExceptionList)); + patientReported.setPublicityIndicatorDate(parseDateWarn(reader.getValue(18), "Invalid publicity indicator date", "PD1", 1, 18, strictDate, processingExceptionList)); } reader.resetPostion(); { @@ -879,32 +764,21 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, patientReported.setGuardianRelationship(guardianRelationship); repeatCount++; if (patientReported.getGuardianLast().equals("")) { - ProcessingException pe = - new ProcessingException("Next-of-kin last name is empty", "NK1", repeatCount, 2) - .setWarning(); + ProcessingException pe = new ProcessingException("Next-of-kin last name is empty", "NK1", repeatCount, 2).setWarning(); processingExceptionList.add(pe); } if (patientReported.getGuardianFirst().equals("")) { - ProcessingException pe = - new ProcessingException("Next-of-kin first name is empty", "NK1", repeatCount, 2) - .setWarning(); + ProcessingException pe = new ProcessingException("Next-of-kin first name is empty", "NK1", repeatCount, 2).setWarning(); processingExceptionList.add(pe); } if (guardianRelationship.equals("")) { - ProcessingException pe = - new ProcessingException("Next-of-kin relationship is empty", "NK1", repeatCount, 3) - .setWarning(); + ProcessingException pe = new ProcessingException("Next-of-kin relationship is empty", "NK1", repeatCount, 3).setWarning(); processingExceptionList.add(pe); } - if (guardianRelationship.equals("MTH") || guardianRelationship.equals("FTH") - || guardianRelationship.equals("GRD")) { + if (guardianRelationship.equals("MTH") || guardianRelationship.equals("FTH") || guardianRelationship.equals("GRD")) { break; } else { - ProcessingException pe = new ProcessingException((guardianRelationship.equals("") - ? "Next-of-kin relationship not specified so is not recognized as guardian and will be ignored" - : ("Next-of-kin relationship '" + guardianRelationship - + "' is not a recognized guardian and will be ignored")), - "NK1", repeatCount, 3).setWarning(); + ProcessingException pe = new ProcessingException((guardianRelationship.equals("") ? "Next-of-kin relationship not specified so is not recognized as guardian and will be ignored" : ("Next-of-kin relationship '" + guardianRelationship + "' is not a recognized guardian and will be ignored")), "NK1", repeatCount, 3).setWarning(); processingExceptionList.add(pe); } } @@ -935,19 +809,16 @@ public String processORU(Tenant tenant, HL7Reader reader, String message, Organi CodeMap codeMap = CodeMapManager.getCodeMap(); boolean strictDate = !processingFlavorSet.contains(ProcessingFlavor.CANTALOUPE); - PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, - processingFlavorSet, codeMap, strictDate, null, managingOrganization); + PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, processingFlavorSet, codeMap, strictDate, null, managingOrganization); int orcCount = 0; int obxCount = 0; while (reader.advanceToSegment("ORC")) { orcCount++; if (reader.advanceToSegment("OBR", "ORC")) { - obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, - strictDate, obxCount, null, null); + obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, null, null); } else { - throw new ProcessingException("OBR segment was not found after ORC segment", "ORC", - orcCount, 0); + throw new ProcessingException("OBR segment was not found after ORC segment", "ORC", orcCount, 0); } } String ack = buildAck(reader, processingExceptionList, processingFlavorSet); @@ -963,41 +834,30 @@ public String processORU(Tenant tenant, HL7Reader reader, String message, Organi } } - public int readAndCreateObservations(HL7Reader reader, - List processingExceptionList, PatientReported patientReported, - boolean strictDate, int obxCount, VaccinationReported vaccinationReported, - VaccinationMaster vaccination) { + public int readAndCreateObservations(HL7Reader reader, List processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination) { while (reader.advanceToSegment("OBX", "ORC")) { obxCount++; String identifierCode = reader.getValue(3); String valueCode = reader.getValue(5); - ObservationReported observationReported = - readObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, - vaccinationReported, vaccination, identifierCode, valueCode); + ObservationReported observationReported = readObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, vaccinationReported, vaccination, identifierCode, valueCode); if (observationReported.getIdentifierCode().equals("30945-0")) // contraindication! { CodeMap codeMap = CodeMapManager.getCodeMap(); - Code contraCode = codeMap.getCodeForCodeset(CodesetType.CONTRAINDICATION_OR_PRECAUTION, - observationReported.getValueCode()); + Code contraCode = codeMap.getCodeForCodeset(CodesetType.CONTRAINDICATION_OR_PRECAUTION, observationReported.getValueCode()); if (contraCode == null) { - ProcessingException pe = new ProcessingException( - "Unrecognized contraindication or precaution", "OBX", obxCount, 5); + ProcessingException pe = new ProcessingException("Unrecognized contraindication or precaution", "OBX", obxCount, 5); pe.setWarning(); processingExceptionList.add(pe); } if (observationReported.getObservationDate() != null) { Date today = new Date(); if (observationReported.getObservationDate().after(today)) { - ProcessingException pe = new ProcessingException( - "Contraindication or precaution observed in the future", "OBX", obxCount, 5); + ProcessingException pe = new ProcessingException("Contraindication or precaution observed in the future", "OBX", obxCount, 5); pe.setWarning(); processingExceptionList.add(pe); } - if (patientReported.getBirthDate() != null && observationReported - .getObservationDate().before(patientReported.getBirthDate())) { - ProcessingException pe = new ProcessingException( - "Contraindication or precaution observed before patient was born", "OBX", obxCount, - 14); + if (patientReported.getBirthDate() != null && observationReported.getObservationDate().before(patientReported.getBirthDate())) { + ProcessingException pe = new ProcessingException("Contraindication or precaution observed before patient was born", "OBX", obxCount, 14); pe.setWarning(); processingExceptionList.add(pe); } @@ -1015,22 +875,15 @@ public int readAndCreateObservations(HL7Reader reader, } @SuppressWarnings("unchecked") - public ObservationReported readObservations(HL7Reader reader, - List processingExceptionList, PatientReported patientReported, - boolean strictDate, int obxCount, VaccinationReported vaccinationReported, - VaccinationMaster vaccination, String identifierCode, String valueCode) { + public ObservationReported readObservations(HL7Reader reader, List processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination, String identifierCode, String valueCode) { // ObservationMaster observationMaster = null; ObservationReported observationReported = null; if (vaccination == null) { - observationReported = fhirRequester.searchObservationReported( - new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam().setMissing(true)) - .add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); + observationReported = fhirRequester.searchObservationReported(new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam().setMissing(true)).add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); // Observation.PART_OF.isMissing(true), // Observation.SUBJECT.hasId(patientReported.getPatientId())); } else { - observationReported = fhirRequester.searchObservationReported( - new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam(vaccination.getVaccinationId())) - .add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); + observationReported = fhirRequester.searchObservationReported(new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam(vaccination.getVaccinationId())).add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); // Observation.PART_OF.hasId(vaccination.getVaccinationId()), // Observation.SUBJECT.hasId(patientReported.getPatientId())); } @@ -1062,9 +915,7 @@ public ObservationReported readObservations(HL7Reader reader, observationReported.setUnitsLabel(reader.getValue(6, 2)); observationReported.setUnitsTable(reader.getValue(6, 3)); observationReported.setResultStatus(reader.getValue(11)); - observationReported.setObservationDate( - parseDateWarn(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)); @@ -1072,9 +923,7 @@ public ObservationReported readObservations(HL7Reader reader, } @SuppressWarnings("unchecked") - public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster patientMaster, - Tenant tenant, List patientReportedPossibleList, - List processingExceptionList) { + public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster patientMaster, Tenant tenant, List patientReportedPossibleList, List processingExceptionList) { IGenericClient fhirClient = repositoryClientFactory.getFhirClient(); reader.resetPostion(); reader.advanceToSegment("MSH"); @@ -1148,8 +997,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p categoryResponse = "Match"; } } else { - processingExceptionList.add(new ProcessingException( - "Unrecognized profile id '" + profileIdSubmitted + "'", "MSH", 1, 21)); + processingExceptionList.add(new ProcessingException("Unrecognized profile id '" + profileIdSubmitted + "'", "MSH", 1, 21)); } createMSH(messageType, profileId, reader, sb, processingFlavorSet); } @@ -1203,8 +1051,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p if (profileId.equals(RSP_Z32_MATCH)) { printQueryNK1(patientMaster, sb, codeMap); } - List vaccinationMasterList = - getVaccinationMasterList(patientMaster); + List vaccinationMasterList = getVaccinationMasterList(patientMaster); if (processingFlavorSet.contains(ProcessingFlavor.LEMON)) { for (Iterator it = vaccinationMasterList.iterator(); it.hasNext(); ) { @@ -1219,19 +1066,16 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } List forecastActualList = null; if (sendBackForecast) { - forecastActualList = - doForecast(patientMaster, codeMap, vaccinationMasterList, tenant); + forecastActualList = doForecast(patientMaster, codeMap, vaccinationMasterList, tenant); } int obxSetId = 0; int obsSubId = 0; for (VaccinationMaster vaccination : vaccinationMasterList) { - Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, - vaccination.getVaccineCvxCode()); + Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccination.getVaccineCvxCode()); if (cvxCode == null) { continue; } - boolean originalReporter = - vaccination.getPatientReported().getTenant().equals(tenant); + boolean originalReporter = vaccination.getPatientReported().getTenant().equals(tenant); if ("D".equals(vaccination.getActionCode())) { continue; } @@ -1252,8 +1096,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p // RXA-5 sb.append("|").append(cvxCode.getValue()).append("^").append(cvxCode.getLabel()).append("^CVX"); if (!vaccination.getVaccineNdcCode().equals("")) { - Code ndcCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, - vaccination.getVaccineNdcCode()); + Code ndcCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, vaccination.getVaccineNdcCode()); if (ndcCode != null) { sb.append("~").append(ndcCode.getValue()).append("^").append(ndcCode.getLabel()).append("^NDC"); } @@ -1285,8 +1128,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p { Code informationCode = null; if (vaccination.getInformationSource() != null) { - informationCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_INFORMATION_SOURCE, - vaccination.getInformationSource()); + informationCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_INFORMATION_SOURCE, vaccination.getInformationSource()); } if (informationCode != null) { sb.append(informationCode.getValue()).append("^").append(informationCode.getLabel()).append("^NIP001"); @@ -1296,9 +1138,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p sb.append("|"); // RXA-11 sb.append("|"); - if (vaccination.getOrgLocation() == null - || vaccination.getOrgLocation().getOrgFacilityCode() == null - || "".equals(vaccination.getOrgLocation().getOrgFacilityCode())) { + if (vaccination.getOrgLocation() == null || vaccination.getOrgLocation().getOrgFacilityCode() == null || "".equals(vaccination.getOrgLocation().getOrgFacilityCode())) { } else { sb.append("^^^"); sb.append(vaccination.getOrgLocation().getOrgFacilityCode()); @@ -1321,12 +1161,10 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } // RXA-17 sb.append("|"); - sb.append(printCode(vaccination.getVaccineMvxCode(), - CodesetType.VACCINATION_MANUFACTURER_CODE, "MVX", codeMap)); + sb.append(printCode(vaccination.getVaccineMvxCode(), CodesetType.VACCINATION_MANUFACTURER_CODE, "MVX", codeMap)); // RXA-18 sb.append("|"); - sb.append(printCode(vaccination.getRefusalReasonCode(), - CodesetType.VACCINATION_REFUSAL, "NIP002", codeMap)); + sb.append(printCode(vaccination.getRefusalReasonCode(), CodesetType.VACCINATION_REFUSAL, "NIP002", codeMap)); // RXA-19 sb.append("|"); // RXA-20 @@ -1342,17 +1180,14 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p // RXA-21 sb.append("|A"); sb.append("\r"); - if (vaccination.getBodyRoute() != null - && !vaccination.getBodyRoute().equals("")) { + if (vaccination.getBodyRoute() != null && !vaccination.getBodyRoute().equals("")) { sb.append("RXR"); // RXR-1 sb.append("|"); - sb.append(printCode(vaccination.getBodyRoute(), CodesetType.BODY_ROUTE, "NCIT", - codeMap)); + sb.append(printCode(vaccination.getBodyRoute(), CodesetType.BODY_ROUTE, "NCIT", codeMap)); // RXR-2 sb.append("|"); - sb.append(printCode(vaccination.getBodySite(), CodesetType.BODY_SITE, "HL70163", - codeMap)); + sb.append(printCode(vaccination.getBodySite(), CodesetType.BODY_SITE, "HL70163", codeMap)); sb.append("\r"); } TestEvent testEvent = vaccination.getTestEvent(); @@ -1385,17 +1220,13 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } } try { - Bundle bundle = fhirClient.search().forResource(Observation.class) - .where(Observation.PART_OF.hasId(patientMaster.getPatientId())) - .and(Observation.PART_OF.hasId(vaccination.getVaccinationId())) - .returnBundle(Bundle.class).execute(); + Bundle bundle = fhirClient.search().forResource(Observation.class).where(Observation.PART_OF.hasId(patientMaster.getPatientId())).and(Observation.PART_OF.hasId(vaccination.getVaccinationId())).returnBundle(Bundle.class).execute(); if (bundle.hasEntry()) { obsSubId++; for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { // ObservationMaster observationMaster = // ObservationMapper.getMaster((Observation) entry.getResource()); - ObservationReported observationReported = - observationMapper.getReported((Observation) entry.getResource()); + ObservationReported observationReported = observationMapper.getReported(entry.getResource()); obxSetId++; printObx(sb, obxSetId, obsSubId, observationReported); } @@ -1404,16 +1235,13 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } } try { - Bundle bundle = fhirClient.search().forResource(Observation.class) - .where(Observation.PART_OF.hasId(patientMaster.getPatientId())) - .returnBundle(Bundle.class).execute(); + Bundle bundle = fhirClient.search().forResource(Observation.class).where(Observation.PART_OF.hasId(patientMaster.getPatientId())).returnBundle(Bundle.class).execute(); if (bundle.hasEntry()) { printORC(tenant, sb, null, false); obsSubId++; for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { obxSetId++; - ObservationReported observationReported = - observationMapper.getReported((Observation) entry.getResource()); + ObservationReported observationReported = observationMapper.getReported(entry.getResource()); printObx(sb, obxSetId, obsSubId, observationReported); } } @@ -1517,8 +1345,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } String messageResponse = sb.toString(); - recordMessageReceived(messageRecieved, patientMaster, messageResponse, "Query", - categoryResponse, tenant); + recordMessageReceived(messageRecieved, patientMaster, messageResponse, "Query", categoryResponse, tenant); return messageResponse; } @@ -1530,11 +1357,7 @@ public List getVaccinationMasterList(PatientMaster patient) { vaccinationMasterList = new ArrayList<>(); Map map = new HashMap<>(); try { - Bundle bundle = fhirClient.search().forResource(Immunization.class) - .where(Immunization.PATIENT.hasId(patient.getPatientId())) - .withTag(GOLDEN_SYSTEM_TAG, GOLDEN_RECORD) - .sort().ascending(Immunization.IDENTIFIER) - .returnBundle(Bundle.class).execute(); + Bundle bundle = fhirClient.search().forResource(Immunization.class).where(Immunization.PATIENT.hasId(patient.getPatientId())).withTag(GOLDEN_SYSTEM_TAG, GOLDEN_RECORD).sort().ascending(Immunization.IDENTIFIER).returnBundle(Bundle.class).execute(); for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { Immunization immunization = (Immunization) entry.getResource(); if (immunization.getOccurrenceDateTimeType() != null) { @@ -1561,17 +1384,11 @@ public List getVaccinationMasterList(PatientMaster patient) { private Organization processSendingOrganization(HL7Reader reader) { String organizationName = reader.getValue(4, 1); - Organization sendingOrganization = (Organization) fhirRequester.searchOrganization( - new SearchParameterMap(Organization.SP_IDENTIFIER, - new TokenParam().setSystem(reader.getValue(4, 10)).setValue(reader.getValue(4, 2)))); + Organization sendingOrganization = (Organization) fhirRequester.searchOrganization(new SearchParameterMap(Organization.SP_IDENTIFIER, new TokenParam().setSystem(reader.getValue(4, 10)).setValue(reader.getValue(4, 2)))); // Organization.IDENTIFIER.exactly() // .systemAndIdentifier(reader.getValue(4, 10), reader.getValue(4, 2))); if (sendingOrganization == null && StringUtils.isNotBlank(organizationName)) { - sendingOrganization = new Organization() - .setName(organizationName) - .addIdentifier(new Identifier() - .setSystem(reader.getValue(4, 2)) - .setValue(reader.getValue(4, 10))); + sendingOrganization = new Organization().setName(organizationName).addIdentifier(new Identifier().setSystem(reader.getValue(4, 2)).setValue(reader.getValue(4, 10))); sendingOrganization = (Organization) fhirRequester.saveOrganization(sendingOrganization); } return sendingOrganization; @@ -1587,17 +1404,13 @@ public Organization processManagingOrganization(HL7Reader reader) { managingIdentifier = reader.getValue(22, 3); } if (managingIdentifier != null) { - managingOrganization = (Organization) fhirRequester.searchOrganization( - new SearchParameterMap(Organization.SP_IDENTIFIER, - new TokenParam().setSystem(reader.getValue(22, 7)).setValue(managingIdentifier))); + managingOrganization = (Organization) fhirRequester.searchOrganization(new SearchParameterMap(Organization.SP_IDENTIFIER, new TokenParam().setSystem(reader.getValue(22, 7)).setValue(managingIdentifier))); // Organization.IDENTIFIER.exactly() // .systemAndIdentifier(reader.getValue(22, 7), managingIdentifier)); if (managingOrganization == null) { managingOrganization = new Organization(); managingOrganization.setName(organizationName); - managingOrganization.addIdentifier() - .setValue(managingIdentifier) - .setSystem(reader.getValue(22, 7)); + managingOrganization.addIdentifier().setValue(managingIdentifier).setSystem(reader.getValue(22, 7)); } } if (managingOrganization != null) { diff --git a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR5.java b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR5.java index e3ce51e5..727913ad 100644 --- a/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR5.java +++ b/src/main/java/org/immregistries/iis/kernal/logic/IncomingMessageHandlerR5.java @@ -42,25 +42,22 @@ public String process(String message, Tenant tenant, String sendingFacilityName) String messageType = reader.getValue(9); String responseMessage; partitionCreationInterceptor.getOrCreatePartitionId(tenant.getOrganizationName()); - Set processingFlavorSet = tenant.getProcessingFlavorSet(); - + Set processingFlavorSet = null; try { + processingFlavorSet = tenant.getProcessingFlavorSet(); String facilityId = reader.getValue(4); if (processingFlavorSet.contains(ProcessingFlavor.SOURSOP)) { if (!facilityId.equals(tenant.getOrganizationName())) { - throw new ProcessingException("Not allowed to submit for facility indicated in MSH-4", - "MSH", 1, 4); + throw new ProcessingException("Not allowed to submit for facility indicated in MSH-4", "MSH", 1, 4); } } Organization sendingOrganization = null; - if (StringUtils.isNotBlank(sendingFacilityName) && !sendingFacilityName.equals("null")){ - sendingOrganization = (Organization) fhirRequester.searchOrganization( - new SearchParameterMap(Organization.SP_NAME, new StringParam(sendingFacilityName))); + if (StringUtils.isNotBlank(sendingFacilityName) && !sendingFacilityName.equals("null")) { + sendingOrganization = (Organization) fhirRequester.searchOrganization(new SearchParameterMap(Organization.SP_NAME, new StringParam(sendingFacilityName))); // Organization.NAME.matches().value(sendingFacilityName)); if (sendingOrganization == null) { - sendingOrganization = (Organization) fhirRequester.saveOrganization(new Organization() - .setName(sendingFacilityName)); + sendingOrganization = (Organization) fhirRequester.saveOrganization(new Organization().setName(sendingFacilityName)); } } @@ -86,16 +83,14 @@ public String process(String message, Tenant tenant, String sendingFacilityName) List processingExceptionList = new ArrayList<>(); processingExceptionList.add(pe); responseMessage = buildAck(reader, processingExceptionList, processingFlavorSet); - recordMessageReceived(message, null, responseMessage, "Unknown", "NAck", - tenant); + recordMessageReceived(message, null, responseMessage, "Unknown", "NAck", tenant); break; } } catch (Exception e) { e.printStackTrace(System.err); List processingExceptionList = new ArrayList<>(); - processingExceptionList.add(new ProcessingException( - "Internal error prevented processing: " + e.getMessage(), null, 0, 0)); + processingExceptionList.add(new ProcessingException("Internal error prevented processing: " + e.getMessage(), null, 0, 0)); responseMessage = buildAck(reader, processingExceptionList, processingFlavorSet); } return responseMessage; @@ -125,8 +120,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived String patientNameMiddle = reader.getValue(4, 3); boolean strictDate = false; - Date patientBirthDate = parseDateWarn(reader.getValue(6), "Invalid patient birth date", "QPD", - 1, 6, strictDate, processingExceptionList); + Date patientBirthDate = parseDateWarn(reader.getValue(6), "Invalid patient birth date", "QPD", 1, 6, strictDate, processingExceptionList); String patientSex = reader.getValue(7); if (patientNameLast.equals("")) { @@ -153,10 +147,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived Set processingFlavorSet = tenant.getProcessingFlavorSet(); Date cutoff = null; - if (processingFlavorSet.contains(ProcessingFlavor.SNAIL) - || processingFlavorSet.contains(ProcessingFlavor.SNAIL30) - || processingFlavorSet.contains(ProcessingFlavor.SNAIL60) - || processingFlavorSet.contains(ProcessingFlavor.SNAIL90)) { + if (processingFlavorSet.contains(ProcessingFlavor.SNAIL) || processingFlavorSet.contains(ProcessingFlavor.SNAIL30) || processingFlavorSet.contains(ProcessingFlavor.SNAIL60) || processingFlavorSet.contains(ProcessingFlavor.SNAIL90)) { Calendar calendar = Calendar.getInstance(); int seconds = -30; if (processingFlavorSet.contains(ProcessingFlavor.SNAIL30)) { @@ -188,9 +179,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived } List multipleMatches = new ArrayList<>(); PatientMaster singleMatch = null; - Bundle matches = repositoryClientFactory.getFhirClient().operation().onType(Patient.class).named("match") - .withParameter(Parameters.class, "resource", ((PatientMapperR5) patientMapper).getFhirResource(patientMasterForMatchQuery)) - .returnResourceType(Bundle.class).execute(); + Bundle matches = repositoryClientFactory.getFhirClient().operation().onType(Patient.class).named("match").withParameter(Parameters.class, "resource", ((PatientMapperR5) patientMapper).getFhirResource(patientMasterForMatchQuery)).returnResourceType(Bundle.class).execute(); for (Bundle.BundleEntryComponent entry : matches.getEntry()) { if (entry.getResource() instanceof Patient) { Patient patient = (Patient) entry.getResource(); @@ -217,8 +206,7 @@ public String processQBP(Tenant tenant, HL7Reader reader, String messageReceived } - return buildRSP(reader, messageReceived, singleMatch, tenant, - multipleMatches, processingExceptionList); + return buildRSP(reader, messageReceived, singleMatch, tenant, multipleMatches, processingExceptionList); } @SuppressWarnings("unchecked") @@ -229,8 +217,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi CodeMap codeMap = CodeMapManager.getCodeMap(); boolean strictDate = !processingFlavorSet.contains(ProcessingFlavor.CANTALOUPE); - PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, - processingFlavorSet, codeMap, strictDate, null, managingOrganization); + PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, processingFlavorSet, codeMap, strictDate, null, managingOrganization); int orcCount = 0; @@ -250,28 +237,21 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi rxaCount++; vaccineCode = reader.getValue(5, 1); if (vaccineCode.equals("")) { - throw new ProcessingException("Vaccine code is not indicated in RXA-5.1", "RXA", - rxaCount, 5); + throw new ProcessingException("Vaccine code is not indicated in RXA-5.1", "RXA", rxaCount, 5); } if (vaccineCode.equals("998")) { - obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, - strictDate, obxCount, null, null); + obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, null, null); continue; } if (vaccinationReportedExternalLink.equals("")) { - throw new ProcessingException("Vaccination order id was not found, unable to process", - "ORC", orcCount, 3); + throw new ProcessingException("Vaccination order id was not found, unable to process", "ORC", orcCount, 3); } - administrationDate = parseDateError(reader.getValue(3, 1), - "Could not read administered date in RXA-5", "RXA", rxaCount, 3, strictDate); + administrationDate = parseDateError(reader.getValue(3, 1), "Could not read administered date in RXA-5", "RXA", rxaCount, 3, strictDate); if (administrationDate.after(new Date())) { - throw new ProcessingException( - "Vaccination is indicated as occuring in the future, unable to accept future vaccination events", - "RXA", rxaCount, 3); + throw new ProcessingException("Vaccination is indicated as occuring in the future, unable to accept future vaccination events", "RXA", rxaCount, 3); } - vaccinationReported = fhirRequester.searchVaccinationReported( - new SearchParameterMap(Immunization.SP_IDENTIFIER, new TokenParam().setValue(vaccinationReportedExternalLink))); + vaccinationReported = fhirRequester.searchVaccinationReported(new SearchParameterMap(Immunization.SP_IDENTIFIER, new TokenParam().setValue(vaccinationReportedExternalLink))); // Immunization.IDENTIFIER.exactly().code(vaccinationReportedExternalLink)); if (vaccinationReported != null) { // vaccinationMaster = vaccinationReported.getVaccination(); @@ -292,8 +272,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi String vaccineCodeType = reader.getValue(5, 3); if (vaccineCodeType.equals("NDC")) { vaccineNdcCode = vaccineCode; - } else if (vaccineCodeType.equals("CPT") || vaccineCodeType.equals("C4") - || vaccineCodeType.equals("C5")) { + } else if (vaccineCodeType.equals("CPT") || vaccineCodeType.equals("C4") || vaccineCodeType.equals("C5")) { vaccineCptCode = vaccineCode; } else { vaccineCvxCode = vaccineCode; @@ -306,8 +285,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi if (vaccineNdcCode.equals("")) { vaccineNdcCode = altVaccineCode; } - } else if (altVaccineCodeType.equals("CPT") || altVaccineCodeType.equals("C4") - || altVaccineCodeType.equals("C5")) { + } else if (altVaccineCodeType.equals("CPT") || altVaccineCodeType.equals("C4") || altVaccineCodeType.equals("C5")) { if (vaccineCptCode.equals("")) { vaccineCptCode = altVaccineCode; } @@ -320,29 +298,21 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } { - Code ndcCode = - codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, vaccineNdcCode); + Code ndcCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, vaccineNdcCode); if (ndcCode != null) { - if (ndcCode.getCodeStatus() != null && ndcCode.getCodeStatus().getDeprecated() != null - && ndcCode.getCodeStatus().getDeprecated().getNewCodeValue() != null - && !ndcCode.getCodeStatus().getDeprecated().getNewCodeValue().equals("")) { + if (ndcCode.getCodeStatus() != null && ndcCode.getCodeStatus().getDeprecated() != null && ndcCode.getCodeStatus().getDeprecated().getNewCodeValue() != null && !ndcCode.getCodeStatus().getDeprecated().getNewCodeValue().equals("")) { vaccineNdcCode = ndcCode.getCodeStatus().getDeprecated().getNewCodeValue(); } Code cvxCode = codeMap.getRelatedCode(ndcCode, CodesetType.VACCINATION_CVX_CODE); if (cvxCode == null) { - ProcessingException pe = - new ProcessingException("Unrecognized NDC " + vaccineNdcCode, "RXA", rxaCount, - 5).setWarning(); + ProcessingException pe = new ProcessingException("Unrecognized NDC " + vaccineNdcCode, "RXA", rxaCount, 5).setWarning(); processingExceptionList.add(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); + 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); } @@ -350,41 +320,31 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } } { - Code cptCode = - codeMap.getCodeForCodeset(CodesetType.VACCINATION_CPT_CODE, vaccineCptCode); + Code cptCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CPT_CODE, vaccineCptCode); if (cptCode != null) { Code cvxCode = codeMap.getRelatedCode(cptCode, CodesetType.VACCINATION_CVX_CODE); if (cvxCode == null) { - ProcessingException pe = - new ProcessingException("Unrecognized CPT " + cptCode, "RXA", rxaCount, 5) - .setWarning(); + ProcessingException pe = new ProcessingException("Unrecognized CPT " + cptCode, "RXA", rxaCount, 5).setWarning(); processingExceptionList.add(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(); + 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); } } } } if (vaccineCvxCode.equals("")) { - throw new ProcessingException( - "Unable to find a recognized vaccine administration code (CVX, NDC, or CPT)", "RXA", - rxaCount, 5); + throw new ProcessingException("Unable to find a recognized vaccine administration code (CVX, NDC, or CPT)", "RXA", rxaCount, 5); } else { - Code cvxCode = - codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccineCvxCode); + Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccineCvxCode); if (cvxCode != null) { vaccineCvxCode = cvxCode.getValue(); } else { - throw new ProcessingException("Unrecognized CVX vaccine '" + vaccineCvxCode + "'", - "RXA", rxaCount, 5); + throw new ProcessingException("Unrecognized CVX vaccine '" + vaccineCvxCode + "'", "RXA", rxaCount, 5); } } @@ -393,15 +353,12 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi { String administeredAtLocation = reader.getValue(11, 4); if (StringUtils.isNotEmpty(administeredAtLocation)) { - OrgLocation orgLocation = fhirRequester.searchOrgLocation( - new SearchParameterMap(Location.SP_IDENTIFIER, new TokenParam().setValue(administeredAtLocation))); + OrgLocation orgLocation = fhirRequester.searchOrgLocation(new SearchParameterMap(Location.SP_IDENTIFIER, new TokenParam().setValue(administeredAtLocation))); // Location.IDENTIFIER.exactly().code(administeredAtLocation)); if (orgLocation == null) { if (processingFlavorSet.contains(ProcessingFlavor.PEAR)) { - throw new ProcessingException( - "Unrecognized administered at location, unable to accept immunization report", - "RXA", rxaCount, 11); + throw new ProcessingException("Unrecognized administered at location, unable to accept immunization report", "RXA", rxaCount, 11); } orgLocation = new OrgLocation(); orgLocation.setOrgFacilityCode(administeredAtLocation); @@ -422,8 +379,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi { String administeringProvider = reader.getValue(10); if (StringUtils.isNotEmpty(administeringProvider)) { - ModelPerson modelPerson = fhirRequester.searchPractitioner( - new SearchParameterMap(Practitioner.SP_IDENTIFIER, new TokenParam().setValue(administeringProvider))); + ModelPerson modelPerson = fhirRequester.searchPractitioner(new SearchParameterMap(Practitioner.SP_IDENTIFIER, new TokenParam().setValue(administeringProvider))); // Practitioner.IDENTIFIER.exactly().code(administeringProvider)); if (modelPerson == null) { modelPerson = new ModelPerson(); @@ -452,18 +408,14 @@ 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( - parseDateWarn(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)); if (!vaccinationReported.getRefusalReasonCode().equals("")) { - Code refusalCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_REFUSAL, - vaccinationReported.getRefusalReasonCode()); + Code refusalCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_REFUSAL, vaccinationReported.getRefusalReasonCode()); if (refusalCode == null) { - ProcessingException pe = - new ProcessingException("Unrecognized refusal reason", "RXA", rxaCount, 18); + ProcessingException pe = new ProcessingException("Unrecognized refusal reason", "RXA", rxaCount, 18); pe.setWarning(); processingExceptionList.add(pe); } @@ -475,22 +427,13 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi vaccinationReported.setBodySite(reader.getValue(2)); } else if (processingFlavorSet.contains(ProcessingFlavor.SPRUCE)) { if (vaccinationReported.getInformationSource().equals("00")) { - throw new ProcessingException("RXR segment is required for administered vaccinations", - "RXA", rxaCount, 0); + throw new ProcessingException("RXR segment is required for administered vaccinations", "RXA", rxaCount, 0); } } - if (vaccinationReported.getAdministeredDate() - .before(patientReported.getBirthDate()) - && !processingFlavorSet.contains(ProcessingFlavor.CLEMENTINE)) { - throw new ProcessingException( - "Vaccination is reported as having been administered before the patient was born", - "RXA", rxaCount, 3); + if (vaccinationReported.getAdministeredDate().before(patientReported.getBirthDate()) && !processingFlavorSet.contains(ProcessingFlavor.CLEMENTINE)) { + throw new ProcessingException("Vaccination is reported as having been administered before the patient was born", "RXA", rxaCount, 3); } - if (!vaccinationReported.getVaccineCvxCode().equals("998") - && !vaccinationReported.getVaccineCvxCode().equals("999") - && (vaccinationReported.getCompletionStatus().equals("CP") - || vaccinationReported.getCompletionStatus().equals("PA") - || vaccinationReported.getCompletionStatus().equals(""))) { + if (!vaccinationReported.getVaccineCvxCode().equals("998") && !vaccinationReported.getVaccineCvxCode().equals("999") && (vaccinationReported.getCompletionStatus().equals("CP") || vaccinationReported.getCompletionStatus().equals("PA") || vaccinationReported.getCompletionStatus().equals(""))) { vaccinationCount++; } @@ -507,12 +450,9 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi if (indicator.equals("64994-7")) { String fundingEligibility = reader.getValue(5); if (!fundingEligibility.equals("")) { - Code fundingEligibilityCode = codeMap - .getCodeForCodeset(CodesetType.FINANCIAL_STATUS_CODE, fundingEligibility); + 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(); + ProcessingException pe = new ProcessingException("Funding eligibility '" + fundingEligibility + "' was not recognized", "OBX", tempObxCount, 5).setWarning(); processingExceptionList.add(pe); } else { vaccinationReported.setFundingEligibility(fundingEligibilityCode.getValue()); @@ -521,12 +461,9 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } else if (indicator.equals("30963-3")) { String fundingSource = reader.getValue(5); if (!fundingSource.equals("")) { - Code fundingSourceCode = codeMap - .getCodeForCodeset(CodesetType.VACCINATION_FUNDING_SOURCE, fundingSource); + 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(); + ProcessingException pe = new ProcessingException("Funding source '" + fundingSource + "' was not recognized", "OBX", tempObxCount, 5).setWarning(); processingExceptionList.add(pe); } else { vaccinationReported.setFundingSource(fundingSourceCode.getValue()); @@ -539,23 +476,16 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi reader.gotoSegmentPosition(segmentPosition); vaccinationReported = fhirRequester.saveVaccinationReported(vaccinationReported); reader.gotoSegmentPosition(segmentPosition); - obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, - strictDate, obxCount, vaccinationReported, null); + obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, vaccinationReported, null); } else { - throw new ProcessingException("RXA segment was not found after ORC segment", "ORC", - orcCount, 0); + throw new ProcessingException("RXA segment was not found after ORC segment", "ORC", orcCount, 0); } } if (processingFlavorSet.contains(ProcessingFlavor.CRANBERRY) && vaccinationCount == 0) { - throw new ProcessingException( - "Patient vaccination history cannot be accepted without at least one administered or historical vaccination specified", - "", 0, 0); + throw new ProcessingException("Patient vaccination history cannot be accepted without at least one administered or historical vaccination specified", "", 0, 0); } - if (processingFlavorSet.contains(ProcessingFlavor.BILBERRY) - && (vaccinationCount == 0 && refusalCount == 0)) { - throw new ProcessingException( - "Patient vaccination history cannot be accepted without at least one administered, historical, or refused vaccination specified", - "", 0, 0); + if (processingFlavorSet.contains(ProcessingFlavor.BILBERRY) && (vaccinationCount == 0 && refusalCount == 0)) { + throw new ProcessingException("Patient vaccination history cannot be accepted without at least one administered, historical, or refused vaccination specified", "", 0, 0); } String ack = buildAck(reader, processingExceptionList, processingFlavorSet); recordMessageReceived(message, patientReported, ack, "Update", "Ack", tenant); @@ -572,10 +502,7 @@ public String processVXU(Tenant tenant, HL7Reader reader, String message, Organi } @SuppressWarnings("unchecked") - public PatientReported processPatient(Tenant tenant, HL7Reader reader, - List processingExceptionList, Set processingFlavorSet, - CodeMap codeMap, boolean strictDate, PatientReported patientReported, Organization managingOrganization) - throws ProcessingException { + public PatientReported processPatient(Tenant tenant, HL7Reader reader, List processingExceptionList, Set processingFlavorSet, CodeMap codeMap, boolean strictDate, PatientReported patientReported, Organization managingOrganization) throws ProcessingException { String patientReportedExternalLink = ""; String patientReportedAuthority = ""; String patientReportedType = "MR"; @@ -585,25 +512,20 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, if (patientReportedExternalLink.equals("")) { patientReportedAuthority = ""; patientReportedType = "PT"; - patientReportedExternalLink = - reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); + patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5); if (patientReportedExternalLink.equals("")) { patientReportedAuthority = ""; patientReportedType = "PI"; - patientReportedExternalLink = - reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); - patientReportedAuthority = - reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5); + patientReportedExternalLink = reader.getValueBySearchingRepeats(3, 1, patientReportedType, 5); + patientReportedAuthority = reader.getValueBySearchingRepeats(3, 4, patientReportedType, 5); if (patientReportedExternalLink.equals("")) { - throw new ProcessingException( - "MRN was not found, required for accepting vaccination report", "PID", 1, 3); + throw new ProcessingException("MRN was not found, required for accepting vaccination report", "PID", 1, 3); } } } } else { - throw new ProcessingException( - "No PID segment found, required for accepting vaccination report", "", 0, 0); + throw new ProcessingException("No PID segment found, required for accepting vaccination report", "", 0, 0); } // patientReported = fhirRequester.searchPatientReported( // new SearchParameterMap("identifier",new TokenParam().setValue(patientReportedExternalLink)) @@ -627,8 +549,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String telUseCode = reader.getValue(13, 2); if (patientPhone.length() > 0) { if (!telUseCode.equals("PRN")) { - ProcessingException pe = new ProcessingException( - "Patient phone telecommunication type must be PRN ", "PID", 1, 13); + ProcessingException pe = new ProcessingException("Patient phone telecommunication type must be PRN ", "PID", 1, 13); if (!processingFlavorSet.contains(ProcessingFlavor.QUINZE)) { pe.setWarning(); } @@ -651,15 +572,12 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } } if (invalidCharFound) { - ProcessingException pe = new ProcessingException( - "Patient phone number has unexpected character: " + invalidChar, "PID", 1, 13); + ProcessingException pe = new ProcessingException("Patient phone number has unexpected character: " + invalidChar, "PID", 1, 13); pe.setWarning(); processingExceptionList.add(pe); } - if (countNums != 10 || patientPhone.startsWith("555") || patientPhone.startsWith("0") - || patientPhone.startsWith("1")) { - ProcessingException pe = new ProcessingException( - "Patient phone number does not appear to be valid", "PID", 1, 13); + if (countNums != 10 || patientPhone.startsWith("555") || patientPhone.startsWith("0") || patientPhone.startsWith("1")) { + ProcessingException pe = new ProcessingException("Patient phone number does not appear to be valid", "PID", 1, 13); pe.setWarning(); processingExceptionList.add(pe); } @@ -670,14 +588,10 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } if (patientNameLast.equals("")) { - throw new ProcessingException( - "Patient last name was not found, required for accepting patient and vaccination history", - "PID", 1, 5); + throw new ProcessingException("Patient last name was not found, required for accepting patient and vaccination history", "PID", 1, 5); } if (patientNameFirst.equals("")) { - throw new ProcessingException( - "Patient first name was not found, required for accepting patient and vaccination history", - "PID", 1, 5); + throw new ProcessingException("Patient first name was not found, required for accepting patient and vaccination history", "PID", 1, 5); } @@ -695,12 +609,9 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, addressFrag = zip + ":" + addressFragPrep; } Date patientBirthDate; - patientBirthDate = parseDateError(reader.getValue(7), "Bad format for date of birth", "PID", - 1, 7, strictDate); + patientBirthDate = parseDateError(reader.getValue(7), "Bad format for date of birth", "PID", 1, 7, strictDate); if (patientBirthDate.after(new Date())) { - throw new ProcessingException( - "Patient is indicated as being born in the future, unable to record patients who are not yet born", - "PID", 1, 7); + throw new ProcessingException("Patient is indicated as being born in the future, unable to record patients who are not yet born", "PID", 1, 7); } patientReported.setExternalLink(patientReportedExternalLink); patientReported.setPatientReportedType(patientReportedType); @@ -726,8 +637,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, patientReported.setEthnicity(reader.getValue(22)); patientReported.setBirthFlag(reader.getValue(24)); patientReported.setBirthOrder(reader.getValue(25)); - patientReported.setDeathDate(parseDateWarn(reader.getValue(29), - "Invalid patient death date", "PID", 1, 29, strictDate, processingExceptionList)); + patientReported.setDeathDate(parseDateWarn(reader.getValue(29), "Invalid patient death date", "PID", 1, 29, strictDate, processingExceptionList)); patientReported.setDeathFlag(reader.getValue(30)); patientReported.setEmail(reader.getValueBySearchingRepeats(13, 4, "NET", 2)); patientReported.setPhone(patientPhone); @@ -736,9 +646,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, { String patientSex = patientReported.getSex(); if (!ValidValues.verifyValidValue(patientSex, ValidValues.SEX)) { - ProcessingException pe = - new ProcessingException("Patient sex '" + patientSex + "' is not recognized", "PID", - 1, 8).setWarning(); + ProcessingException pe = new ProcessingException("Patient sex '" + patientSex + "' is not recognized", "PID", 1, 8).setWarning(); if (processingFlavorSet.contains(ProcessingFlavor.ELDERBERRIES)) { pe.setWarning(); } @@ -748,23 +656,19 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String patientAddressCountry = patientReported.getAddressCountry(); if (!patientAddressCountry.equals("")) { - if (!ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_2DIGIT) - && !ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_3DIGIT)) { - ProcessingException pe = new ProcessingException("Patient address country '" - + patientAddressCountry + "' is not recognized and cannot be accepted", "PID", 1, 11); + if (!ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_2DIGIT) && !ValidValues.verifyValidValue(patientAddressCountry, ValidValues.COUNTRY_3DIGIT)) { + ProcessingException pe = new ProcessingException("Patient address country '" + patientAddressCountry + "' is not recognized and cannot be accepted", "PID", 1, 11); if (processingFlavorSet.contains(ProcessingFlavor.GUAVA)) { pe.setWarning(); } processingExceptionList.add(pe); } } - if (patientAddressCountry.equals("") || patientAddressCountry.equals("US") - || patientAddressCountry.equals("USA")) { + if (patientAddressCountry.equals("") || patientAddressCountry.equals("US") || patientAddressCountry.equals("USA")) { String patientAddressState = patientReported.getAddressState(); if (!patientAddressState.equals("")) { if (!ValidValues.verifyValidValue(patientAddressState, ValidValues.STATE)) { - ProcessingException pe = new ProcessingException("Patient address state '" - + patientAddressState + "' is not recognized and cannot be accepted", "PID", 1, 11); + ProcessingException pe = new ProcessingException("Patient address state '" + patientAddressState + "' is not recognized and cannot be accepted", "PID", 1, 11); if (processingFlavorSet.contains(ProcessingFlavor.GUAVA)) { pe.setWarning(); } @@ -778,10 +682,8 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String race = patientReported.getRace(); if (!race.equals("")) { Code raceCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_RACE, race); - if (raceCode == null - || CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID) { - ProcessingException pe = new ProcessingException( - "Invalid race '" + race + "', message cannot be accepted", "PID", 1, 10); + if (raceCode == null || CodeStatusValue.getBy(raceCode.getCodeStatus()) != CodeStatusValue.VALID) { + ProcessingException pe = new ProcessingException("Invalid race '" + race + "', message cannot be accepted", "PID", 1, 10); if (!processingFlavorSet.contains(ProcessingFlavor.FIG)) { pe.setWarning(); } @@ -794,10 +696,8 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, String ethnicity = patientReported.getEthnicity(); if (!ethnicity.equals("")) { Code ethnicityCode = codeMap.getCodeForCodeset(CodesetType.PATIENT_ETHNICITY, ethnicity); - if (ethnicityCode == null - || CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID) { - ProcessingException pe = new ProcessingException( - "Invalid ethnicity '" + ethnicity + "', message cannot be accepted", "PID", 1, 10); + if (ethnicityCode == null || CodeStatusValue.getBy(ethnicityCode.getCodeStatus()) != CodeStatusValue.VALID) { + ProcessingException pe = new ProcessingException("Invalid ethnicity '" + ethnicity + "', message cannot be accepted", "PID", 1, 10); if (!processingFlavorSet.contains(ProcessingFlavor.FIG)) { pe.setWarning(); } @@ -807,12 +707,8 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } if (processingFlavorSet.contains(ProcessingFlavor.BLACKBERRY)) { - if (patientReported.getAddressLine1().equals("") - || patientReported.getAddressCity().equals("") - || patientReported.getAddressState().equals("") - || patientReported.getAddressZip().equals("")) { - throw new ProcessingException("Patient address is required but it was not sent", "PID", 1, - 11); + if (patientReported.getAddressLine1().equals("") || patientReported.getAddressCity().equals("") || patientReported.getAddressState().equals("") || patientReported.getAddressZip().equals("")) { + throw new ProcessingException("Patient address is required but it was not sent", "PID", 1, 11); } } @@ -823,8 +719,7 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, if (birthFlag.equals("") || birthFlag.equals("N")) { // The only acceptable value here is now blank or 1 if (!birthOrder.equals("1") && !birthOrder.equals("")) { - ProcessingException pe = new ProcessingException("Birth order was specified as " - + birthOrder + " but not indicated as multiple birth", "PID", 1, 25); + ProcessingException pe = new ProcessingException("Birth order was specified as " + birthOrder + " but not indicated as multiple birth", "PID", 1, 25); if (processingFlavorSet.contains(ProcessingFlavor.PLANTAIN)) { pe.setWarning(); } @@ -832,22 +727,18 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, } } else if (birthFlag.equals("Y")) { if (birthOrder.equals("")) { - ProcessingException pe = new ProcessingException( - "Multiple birth but birth order was not specified", "PID", 1, 24); + ProcessingException pe = new ProcessingException("Multiple birth but birth order was not specified", "PID", 1, 24); pe.setWarning(); processingExceptionList.add(pe); } else if (!ValidValues.verifyValidValue(birthOrder, ValidValues.BIRTH_ORDER)) { - ProcessingException pe = - new ProcessingException("Birth order was specified as " + birthOrder - + " but not an expected value, must be between 1 and 9", "PID", 1, 25); + ProcessingException pe = new ProcessingException("Birth order was specified as " + birthOrder + " but not an expected value, must be between 1 and 9", "PID", 1, 25); if (processingFlavorSet.contains(ProcessingFlavor.PLANTAIN)) { pe.setWarning(); } processingExceptionList.add(pe); } } else { - ProcessingException pe = new ProcessingException( - "Multiple birth indicator " + birthFlag + " is not recognized", "PID", 1, 24); + ProcessingException pe = new ProcessingException("Multiple birth indicator " + birthFlag + " is not recognized", "PID", 1, 24); if (processingFlavorSet.contains(ProcessingFlavor.PLANTAIN)) { pe.setWarning(); } @@ -860,14 +751,10 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, if (reader.advanceToSegment("PD1")) { patientReported.setPublicityIndicator(reader.getValue(11)); patientReported.setProtectionIndicator(reader.getValue(12)); - patientReported.setProtectionIndicatorDate(parseDateWarn(reader.getValue(13), - "Invalid protection indicator date", "PD1", 1, 13, strictDate, processingExceptionList)); + patientReported.setProtectionIndicatorDate(parseDateWarn(reader.getValue(13), "Invalid protection indicator date", "PD1", 1, 13, strictDate, processingExceptionList)); patientReported.setRegistryStatusIndicator(reader.getValue(16)); - patientReported.setRegistryStatusIndicatorDate( - parseDateWarn(reader.getValue(17), "Invalid registry status indicator date", "PD1", 1, 17, - strictDate, processingExceptionList)); - patientReported.setPublicityIndicatorDate(parseDateWarn(reader.getValue(18), - "Invalid publicity indicator date", "PD1", 1, 18, strictDate, processingExceptionList)); + patientReported.setRegistryStatusIndicatorDate(parseDateWarn(reader.getValue(17), "Invalid registry status indicator date", "PD1", 1, 17, strictDate, processingExceptionList)); + patientReported.setPublicityIndicatorDate(parseDateWarn(reader.getValue(18), "Invalid publicity indicator date", "PD1", 1, 18, strictDate, processingExceptionList)); } reader.resetPostion(); { @@ -880,32 +767,21 @@ public PatientReported processPatient(Tenant tenant, HL7Reader reader, patientReported.setGuardianRelationship(guardianRelationship); repeatCount++; if (patientReported.getGuardianLast().equals("")) { - ProcessingException pe = - new ProcessingException("Next-of-kin last name is empty", "NK1", repeatCount, 2) - .setWarning(); + ProcessingException pe = new ProcessingException("Next-of-kin last name is empty", "NK1", repeatCount, 2).setWarning(); processingExceptionList.add(pe); } if (patientReported.getGuardianFirst().equals("")) { - ProcessingException pe = - new ProcessingException("Next-of-kin first name is empty", "NK1", repeatCount, 2) - .setWarning(); + ProcessingException pe = new ProcessingException("Next-of-kin first name is empty", "NK1", repeatCount, 2).setWarning(); processingExceptionList.add(pe); } if (guardianRelationship.equals("")) { - ProcessingException pe = - new ProcessingException("Next-of-kin relationship is empty", "NK1", repeatCount, 3) - .setWarning(); + ProcessingException pe = new ProcessingException("Next-of-kin relationship is empty", "NK1", repeatCount, 3).setWarning(); processingExceptionList.add(pe); } - if (guardianRelationship.equals("MTH") || guardianRelationship.equals("FTH") - || guardianRelationship.equals("GRD")) { + if (guardianRelationship.equals("MTH") || guardianRelationship.equals("FTH") || guardianRelationship.equals("GRD")) { break; } else { - ProcessingException pe = new ProcessingException((guardianRelationship.equals("") - ? "Next-of-kin relationship not specified so is not recognized as guardian and will be ignored" - : ("Next-of-kin relationship '" + guardianRelationship - + "' is not a recognized guardian and will be ignored")), - "NK1", repeatCount, 3).setWarning(); + ProcessingException pe = new ProcessingException((guardianRelationship.equals("") ? "Next-of-kin relationship not specified so is not recognized as guardian and will be ignored" : ("Next-of-kin relationship '" + guardianRelationship + "' is not a recognized guardian and will be ignored")), "NK1", repeatCount, 3).setWarning(); processingExceptionList.add(pe); } } @@ -938,19 +814,16 @@ public String processORU(Tenant tenant, HL7Reader reader, String message, Organi CodeMap codeMap = CodeMapManager.getCodeMap(); boolean strictDate = !processingFlavorSet.contains(ProcessingFlavor.CANTALOUPE); - PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, - processingFlavorSet, codeMap, strictDate, null, managingOrganization); + PatientReported patientReported = processPatient(tenant, reader, processingExceptionList, processingFlavorSet, codeMap, strictDate, null, managingOrganization); int orcCount = 0; int obxCount = 0; while (reader.advanceToSegment("ORC")) { orcCount++; if (reader.advanceToSegment("OBR", "ORC")) { - obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, - strictDate, obxCount, null, null); + obxCount = readAndCreateObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, null, null); } else { - throw new ProcessingException("OBR segment was not found after ORC segment", "ORC", - orcCount, 0); + throw new ProcessingException("OBR segment was not found after ORC segment", "ORC", orcCount, 0); } } String ack = buildAck(reader, processingExceptionList, processingFlavorSet); @@ -966,41 +839,30 @@ public String processORU(Tenant tenant, HL7Reader reader, String message, Organi } } - public int readAndCreateObservations(HL7Reader reader, - List processingExceptionList, PatientReported patientReported, - boolean strictDate, int obxCount, VaccinationReported vaccinationReported, - VaccinationMaster vaccination) { + public int readAndCreateObservations(HL7Reader reader, List processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination) { while (reader.advanceToSegment("OBX", "ORC")) { obxCount++; String identifierCode = reader.getValue(3); String valueCode = reader.getValue(5); - ObservationReported observationReported = - readObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, - vaccinationReported, vaccination, identifierCode, valueCode); + ObservationReported observationReported = readObservations(reader, processingExceptionList, patientReported, strictDate, obxCount, vaccinationReported, vaccination, identifierCode, valueCode); if (observationReported.getIdentifierCode().equals("30945-0")) // contraindication! { CodeMap codeMap = CodeMapManager.getCodeMap(); - Code contraCode = codeMap.getCodeForCodeset(CodesetType.CONTRAINDICATION_OR_PRECAUTION, - observationReported.getValueCode()); + Code contraCode = codeMap.getCodeForCodeset(CodesetType.CONTRAINDICATION_OR_PRECAUTION, observationReported.getValueCode()); if (contraCode == null) { - ProcessingException pe = new ProcessingException( - "Unrecognized contraindication or precaution", "OBX", obxCount, 5); + ProcessingException pe = new ProcessingException("Unrecognized contraindication or precaution", "OBX", obxCount, 5); pe.setWarning(); processingExceptionList.add(pe); } if (observationReported.getObservationDate() != null) { Date today = new Date(); if (observationReported.getObservationDate().after(today)) { - ProcessingException pe = new ProcessingException( - "Contraindication or precaution observed in the future", "OBX", obxCount, 5); + ProcessingException pe = new ProcessingException("Contraindication or precaution observed in the future", "OBX", obxCount, 5); pe.setWarning(); processingExceptionList.add(pe); } - if (patientReported.getBirthDate() != null && observationReported - .getObservationDate().before(patientReported.getBirthDate())) { - ProcessingException pe = new ProcessingException( - "Contraindication or precaution observed before patient was born", "OBX", obxCount, - 14); + if (patientReported.getBirthDate() != null && observationReported.getObservationDate().before(patientReported.getBirthDate())) { + ProcessingException pe = new ProcessingException("Contraindication or precaution observed before patient was born", "OBX", obxCount, 14); pe.setWarning(); processingExceptionList.add(pe); } @@ -1018,22 +880,15 @@ public int readAndCreateObservations(HL7Reader reader, } @SuppressWarnings("unchecked") - public ObservationReported readObservations(HL7Reader reader, - List processingExceptionList, PatientReported patientReported, - boolean strictDate, int obxCount, VaccinationReported vaccinationReported, - VaccinationMaster vaccination, String identifierCode, String valueCode) { + public ObservationReported readObservations(HL7Reader reader, List processingExceptionList, PatientReported patientReported, boolean strictDate, int obxCount, VaccinationReported vaccinationReported, VaccinationMaster vaccination, String identifierCode, String valueCode) { // ObservationMaster observationMaster = null; ObservationReported observationReported = null; if (vaccination == null) { - observationReported = fhirRequester.searchObservationReported( - new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam().setMissing(true)) - .add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); + observationReported = fhirRequester.searchObservationReported(new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam().setMissing(true)).add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); // Observation.PART_OF.isMissing(true), // Observation.SUBJECT.hasId(patientReported.getPatientId())); } else { - observationReported = fhirRequester.searchObservationReported( - new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam(vaccination.getVaccinationId())) - .add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); + observationReported = fhirRequester.searchObservationReported(new SearchParameterMap(Observation.SP_PART_OF, new ReferenceParam(vaccination.getVaccinationId())).add(Observation.SP_SUBJECT, new ReferenceParam(patientReported.getPatientId()))); // Observation.PART_OF.hasId(vaccination.getVaccinationId()), // Observation.SUBJECT.hasId(patientReported.getPatientId())); } @@ -1065,9 +920,7 @@ public ObservationReported readObservations(HL7Reader reader, observationReported.setUnitsLabel(reader.getValue(6, 2)); observationReported.setUnitsTable(reader.getValue(6, 3)); observationReported.setResultStatus(reader.getValue(11)); - observationReported.setObservationDate( - parseDateWarn(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)); @@ -1075,10 +928,8 @@ public ObservationReported readObservations(HL7Reader reader, } @SuppressWarnings("unchecked") - public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster patientMaster, - Tenant tenant, List patientReportedPossibleList, - List processingExceptionList) { - IGenericClient fhirClient = repositoryClientFactory.getFhirClient(); + public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster patientMaster, Tenant tenant, List patientReportedPossibleList, List processingExceptionList) { + IGenericClient fhirClient = repositoryClientFactory.getFhirClient(); reader.resetPostion(); reader.advanceToSegment("MSH"); @@ -1151,8 +1002,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p categoryResponse = "Match"; } } else { - processingExceptionList.add(new ProcessingException( - "Unrecognized profile id '" + profileIdSubmitted + "'", "MSH", 1, 21)); + processingExceptionList.add(new ProcessingException("Unrecognized profile id '" + profileIdSubmitted + "'", "MSH", 1, 21)); } createMSH(messageType, profileId, reader, sb, processingFlavorSet); } @@ -1206,8 +1056,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p if (profileId.equals(RSP_Z32_MATCH)) { printQueryNK1(patientMaster, sb, codeMap); } - List vaccinationMasterList = - getVaccinationMasterList(patientMaster); + List vaccinationMasterList = getVaccinationMasterList(patientMaster); if (processingFlavorSet.contains(ProcessingFlavor.LEMON)) { for (Iterator it = vaccinationMasterList.iterator(); it.hasNext(); ) { @@ -1222,19 +1071,16 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } List forecastActualList = null; if (sendBackForecast) { - forecastActualList = - doForecast(patientMaster, codeMap, vaccinationMasterList, tenant); + forecastActualList = doForecast(patientMaster, codeMap, vaccinationMasterList, tenant); } int obxSetId = 0; int obsSubId = 0; for (VaccinationMaster vaccination : vaccinationMasterList) { - Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, - vaccination.getVaccineCvxCode()); + Code cvxCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_CVX_CODE, vaccination.getVaccineCvxCode()); if (cvxCode == null) { continue; } - boolean originalReporter = - vaccination.getPatientReported().getTenant().equals(tenant); + boolean originalReporter = vaccination.getPatientReported().getTenant().equals(tenant); if ("D".equals(vaccination.getActionCode())) { continue; } @@ -1255,8 +1101,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p // RXA-5 sb.append("|").append(cvxCode.getValue()).append("^").append(cvxCode.getLabel()).append("^CVX"); if (!vaccination.getVaccineNdcCode().equals("")) { - Code ndcCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, - vaccination.getVaccineNdcCode()); + Code ndcCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_NDC_CODE, vaccination.getVaccineNdcCode()); if (ndcCode != null) { sb.append("~").append(ndcCode.getValue()).append("^").append(ndcCode.getLabel()).append("^NDC"); } @@ -1288,8 +1133,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p { Code informationCode = null; if (vaccination.getInformationSource() != null) { - informationCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_INFORMATION_SOURCE, - vaccination.getInformationSource()); + informationCode = codeMap.getCodeForCodeset(CodesetType.VACCINATION_INFORMATION_SOURCE, vaccination.getInformationSource()); } if (informationCode != null) { sb.append(informationCode.getValue()).append("^").append(informationCode.getLabel()).append("^NIP001"); @@ -1299,9 +1143,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p sb.append("|"); // RXA-11 sb.append("|"); - if (vaccination.getOrgLocation() == null - || vaccination.getOrgLocation().getOrgFacilityCode() == null - || "".equals(vaccination.getOrgLocation().getOrgFacilityCode())) { + if (vaccination.getOrgLocation() == null || vaccination.getOrgLocation().getOrgFacilityCode() == null || "".equals(vaccination.getOrgLocation().getOrgFacilityCode())) { } else { sb.append("^^^"); sb.append(vaccination.getOrgLocation().getOrgFacilityCode()); @@ -1324,12 +1166,10 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } // RXA-17 sb.append("|"); - sb.append(printCode(vaccination.getVaccineMvxCode(), - CodesetType.VACCINATION_MANUFACTURER_CODE, "MVX", codeMap)); + sb.append(printCode(vaccination.getVaccineMvxCode(), CodesetType.VACCINATION_MANUFACTURER_CODE, "MVX", codeMap)); // RXA-18 sb.append("|"); - sb.append(printCode(vaccination.getRefusalReasonCode(), - CodesetType.VACCINATION_REFUSAL, "NIP002", codeMap)); + sb.append(printCode(vaccination.getRefusalReasonCode(), CodesetType.VACCINATION_REFUSAL, "NIP002", codeMap)); // RXA-19 sb.append("|"); // RXA-20 @@ -1345,17 +1185,14 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p // RXA-21 sb.append("|A"); sb.append("\r"); - if (vaccination.getBodyRoute() != null - && !vaccination.getBodyRoute().equals("")) { + if (vaccination.getBodyRoute() != null && !vaccination.getBodyRoute().equals("")) { sb.append("RXR"); // RXR-1 sb.append("|"); - sb.append(printCode(vaccination.getBodyRoute(), CodesetType.BODY_ROUTE, "NCIT", - codeMap)); + sb.append(printCode(vaccination.getBodyRoute(), CodesetType.BODY_ROUTE, "NCIT", codeMap)); // RXR-2 sb.append("|"); - sb.append(printCode(vaccination.getBodySite(), CodesetType.BODY_SITE, "HL70163", - codeMap)); + sb.append(printCode(vaccination.getBodySite(), CodesetType.BODY_SITE, "HL70163", codeMap)); sb.append("\r"); } TestEvent testEvent = vaccination.getTestEvent(); @@ -1388,17 +1225,13 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } } try { - Bundle bundle = fhirClient.search().forResource(Observation.class) - .where(Observation.PART_OF.hasId(patientMaster.getPatientId())) - .and(Observation.PART_OF.hasId(vaccination.getVaccinationId())) - .returnBundle(Bundle.class).execute(); + Bundle bundle = fhirClient.search().forResource(Observation.class).where(Observation.PART_OF.hasId(patientMaster.getPatientId())).and(Observation.PART_OF.hasId(vaccination.getVaccinationId())).returnBundle(Bundle.class).execute(); if (bundle.hasEntry()) { obsSubId++; for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { // ObservationMaster observationMaster = // ObservationMapper.getMaster((Observation) entry.getResource()); - ObservationReported observationReported = - observationMapper.getReported((Observation) entry.getResource()); + ObservationReported observationReported = observationMapper.getReported(entry.getResource()); obxSetId++; printObx(sb, obxSetId, obsSubId, observationReported); } @@ -1407,16 +1240,13 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } } try { - Bundle bundle = fhirClient.search().forResource(Observation.class) - .where(Observation.PART_OF.hasId(patientMaster.getPatientId())) - .returnBundle(Bundle.class).execute(); + Bundle bundle = fhirClient.search().forResource(Observation.class).where(Observation.PART_OF.hasId(patientMaster.getPatientId())).returnBundle(Bundle.class).execute(); if (bundle.hasEntry()) { printORC(tenant, sb, null, false); obsSubId++; for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { obxSetId++; - ObservationReported observationReported = - observationMapper.getReported((Observation) entry.getResource()); + ObservationReported observationReported = observationMapper.getReported(entry.getResource()); printObx(sb, obxSetId, obsSubId, observationReported); } } @@ -1520,8 +1350,7 @@ public String buildRSP(HL7Reader reader, String messageRecieved, PatientMaster p } String messageResponse = sb.toString(); - recordMessageReceived(messageRecieved, patientMaster, messageResponse, "Query", - categoryResponse, tenant); + recordMessageReceived(messageRecieved, patientMaster, messageResponse, "Query", categoryResponse, tenant); return messageResponse; } @@ -1533,11 +1362,7 @@ public List getVaccinationMasterList(PatientMaster patient) { vaccinationMasterList = new ArrayList<>(); Map map = new HashMap<>(); try { - Bundle bundle = fhirClient.search().forResource(Immunization.class) - .where(Immunization.PATIENT.hasId(patient.getPatientId())) - .withTag(GOLDEN_SYSTEM_TAG, GOLDEN_RECORD) - .sort().ascending(Immunization.IDENTIFIER) - .returnBundle(Bundle.class).execute(); + Bundle bundle = fhirClient.search().forResource(Immunization.class).where(Immunization.PATIENT.hasId(patient.getPatientId())).withTag(GOLDEN_SYSTEM_TAG, GOLDEN_RECORD).sort().ascending(Immunization.IDENTIFIER).returnBundle(Bundle.class).execute(); for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { Immunization immunization = (Immunization) entry.getResource(); if (immunization.getOccurrenceDateTimeType() != null) { @@ -1564,17 +1389,11 @@ public List getVaccinationMasterList(PatientMaster patient) { private Organization processSendingOrganization(HL7Reader reader) { String organizationName = reader.getValue(4, 1); - Organization sendingOrganization = (Organization) fhirRequester.searchOrganization( - new SearchParameterMap(Organization.SP_IDENTIFIER, - new TokenParam().setSystem(reader.getValue(4, 10)).setValue(reader.getValue(4, 2)))); + Organization sendingOrganization = (Organization) fhirRequester.searchOrganization(new SearchParameterMap(Organization.SP_IDENTIFIER, new TokenParam().setSystem(reader.getValue(4, 10)).setValue(reader.getValue(4, 2)))); // Organization.IDENTIFIER.exactly() // .systemAndIdentifier(reader.getValue(4, 10), reader.getValue(4, 2))); if (sendingOrganization == null && StringUtils.isNotBlank(organizationName)) { - sendingOrganization = new Organization() - .setName(organizationName) - .addIdentifier(new Identifier() - .setSystem(reader.getValue(4, 2)) - .setValue(reader.getValue(4, 10))); + sendingOrganization = new Organization().setName(organizationName).addIdentifier(new Identifier().setSystem(reader.getValue(4, 2)).setValue(reader.getValue(4, 10))); sendingOrganization = (Organization) fhirRequester.saveOrganization(sendingOrganization); } return sendingOrganization; @@ -1590,17 +1409,13 @@ public Organization processManagingOrganization(HL7Reader reader) { managingIdentifier = reader.getValue(22, 3); } if (managingIdentifier != null) { - managingOrganization = (Organization) fhirRequester.searchOrganization( - new SearchParameterMap(Organization.SP_IDENTIFIER, - new TokenParam().setSystem(reader.getValue(22, 7)).setValue(managingIdentifier))); + managingOrganization = (Organization) fhirRequester.searchOrganization(new SearchParameterMap(Organization.SP_IDENTIFIER, new TokenParam().setSystem(reader.getValue(22, 7)).setValue(managingIdentifier))); // Organization.IDENTIFIER.exactly() // .systemAndIdentifier(reader.getValue(22, 7), managingIdentifier)); if (managingOrganization == null) { managingOrganization = new Organization(); managingOrganization.setName(organizationName); - managingOrganization.addIdentifier() - .setValue(managingIdentifier) - .setSystem(reader.getValue(22, 7)); + managingOrganization.addIdentifier().setValue(managingIdentifier).setSystem(reader.getValue(22, 7)); } } if (managingOrganization != null) {