/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package gov.hhs.fha.nhinc.adaptermpimanager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hl7.v3.*; import gov.hhs.fha.nhinc.mpilib.*; import gov.hhs.fha.nhinc.adaptermpimanager.HL7Parsers.*; /** * * @author mflynn02 */ public class PatientSaver { private static Log log = LogFactory.getLog(PatientSaver.class); public static org.hl7.v3.MCCIIN000002UV01 SavePatient(org.hl7.v3.PRPAIN201301UV message) { MCCIIN000002UV01 result = new MCCIIN000002UV01(); result = PatientSaver.SaveAnnouncePatient(message, true, true, true, false); return result; } public static org.hl7.v3.MCCIIN000002UV01 RevokePatient(org.hl7.v3.PRPAIN201303UV message) { boolean AllowSearchByDemographicsForDeletePatient = true; log.info("in DeletePatient"); MCCIIN000002UV01 response = new MCCIIN000002UV01(); HL7Parser201303.PrintMessageIdFromMessage(message); PRPAMT201305UVPatient patient = HL7Parser201303.ExtractHL7PatientFromMessage(message); MCCIMT000100UV01Sender sender = message.getSender(); org.hl7.v3.MCCIMT000200UV01Acknowledgement acknowledge = new MCCIMT000200UV01Acknowledgement(); org.hl7.v3.MCCIMT000200UV01AcknowledgementDetail ackDetail = new MCCIMT000200UV01AcknowledgementDetail(); org.hl7.v3.CE ackCode = new CE(); if (patient == null) { log.info("WARNING: no patient supplied"); ackCode.setCode("There was no patient supplied in 201303 Message"); ackDetail.setCode(ackCode); } else if (sender == null || sender.getDevice() == null) { log.warn("WARNING: no sender supplied"); ackCode.setCode("There was not a valid sender supplied in 201303 Message"); } else { log.info("Found patient in message"); Patient sourcePatient = HL7Parser201303.ExtractMpiPatientFromHL7Patient(patient); Patients searchResults = MpiDataAccess.LookupPatients(sourcePatient, AllowSearchByDemographicsForDeletePatient); if (CommonChecks.isZeroSearchResult(searchResults)) { log.info("patient not found in MPI"); ackCode.setCode("The patient was not found in the MPI"); } else if (CommonChecks.isMultipleSearchResult(searchResults)) { log.info("multiple patients found in MPI [searchResults.size()=" + searchResults.size() + "]"); ackCode.setCode("Multiple patients were found in the MPI"); } else { log.info("patient found in MPI"); log.info("removing patient correlation"); if (sender.getDevice().getId() != null && sender.getDevice().getId().size() > 0 && sender.getDevice().getId().get(0) != null && sender.getDevice().getId().get(0).getRoot() != null && sender.getDevice().getId().get(0).getRoot().length() > 0) { MpiDataAccess.DeletePatient(sourcePatient, sender.getDevice().getId().get(0).getRoot()); } else { log.warn("WARNING: An invalid sender was supplied"); ackCode.setCode("There was not a valid sender supplied in 201303 Message"); } ackCode.setCode("Successfully revoked patient"); } } ackDetail.setCode(ackCode); acknowledge.getAcknowledgementDetail().add(ackDetail); response.getAcknowledgement().add(acknowledge); return response; } private static org.hl7.v3.MCCIIN000002UV01 SaveAnnouncePatient(PRPAIN201301UV message, boolean AllowSearchByDemographics, boolean CreatePatientIfDoesNotExist, boolean UpdateDemographicsIfNeeded, boolean ConfirmDemographicMatchPriorToUpdatingCorrelation) { log.info("in SaveAnnouncePatient (PRPAIN201301UV)"); MCCIIN000002UV01 result = new MCCIIN000002UV01(); org.hl7.v3.MCCIMT000200UV01Acknowledgement acknowledge = new MCCIMT000200UV01Acknowledgement(); org.hl7.v3.MCCIMT000200UV01AcknowledgementDetail ackDetail = new MCCIMT000200UV01AcknowledgementDetail(); org.hl7.v3.CE ackCode = new CE(); HL7Parser201301.PrintMessageIdFromMessage(message); PRPAMT201301UVPatient patient = HL7Parser201301.ExtractHL7PatientFromMessage(message); MCCIMT000100UV01Sender sender = message.getSender(); if (patient == null) { log.warn(" no patient supplied"); ackCode.setCode("No Patient Supplied"); } else if (sender == null) { log.warn(" no sender supplied"); ackCode.setCode("No Sender Supplied"); } else { Patient sourcePatient = HL7Parser201301.ExtractMpiPatientFromHL7Patient(patient); log.info("perform patient lookup in mpi"); log.info("source patient check 1 [" + sourcePatient.getName().getLastName() + "]"); Patients searchResults = MpiDataAccess.LookupPatients(sourcePatient, AllowSearchByDemographics); log.info("source patient check 2 [" + sourcePatient.getName().getLastName() + "]"); if (CommonChecks.isZeroSearchResult(searchResults)) { log.info("patient not found in MPI"); if (CreatePatientIfDoesNotExist) { log.info("creating patient"); MpiDataAccess.SavePatient(sourcePatient); ackCode.setCode("Patient Successfully added to the MPI"); } else { log.info("patient not found in MPI - ignore"); //result = null; } } else if (CommonChecks.isMultipleSearchResult(searchResults)) { log.info("multiple patients found in MPI [searchResults.size()=" + searchResults.size() + "]"); ackCode.setCode("Multiple patients were found in the MPI"); result = null; } else { log.info("patient found in MPI. Currently IGNORE record!"); ackCode.setCode("Patient found in MPI. Currently IGNORE record"); } } ackDetail.setCode(ackCode); acknowledge.getAcknowledgementDetail().add(ackDetail); result.getAcknowledgement().add(acknowledge); return result; } }