1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 |
|
---|
6 | package gov.hhs.fha.nhinc.adaptermpimanager;
|
---|
7 |
|
---|
8 | import org.apache.commons.logging.Log;
|
---|
9 | import org.apache.commons.logging.LogFactory;
|
---|
10 | import org.hl7.v3.*;
|
---|
11 | import gov.hhs.fha.nhinc.mpilib.*;
|
---|
12 | import gov.hhs.fha.nhinc.adaptermpimanager.HL7Parsers.*;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | *
|
---|
16 | * @author mflynn02
|
---|
17 | */
|
---|
18 | public class PatientSaver {
|
---|
19 | private static Log log = LogFactory.getLog(PatientSaver.class);
|
---|
20 |
|
---|
21 | public static org.hl7.v3.MCCIIN000002UV01 SavePatient(org.hl7.v3.PRPAIN201301UV message) {
|
---|
22 | MCCIIN000002UV01 result = new MCCIIN000002UV01();
|
---|
23 | result = PatientSaver.SaveAnnouncePatient(message, true, true, true, false);
|
---|
24 |
|
---|
25 | return result;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public static org.hl7.v3.MCCIIN000002UV01 RevokePatient(org.hl7.v3.PRPAIN201303UV message) {
|
---|
29 | boolean AllowSearchByDemographicsForDeletePatient = true;
|
---|
30 | log.info("in DeletePatient");
|
---|
31 | MCCIIN000002UV01 response = new MCCIIN000002UV01();
|
---|
32 | HL7Parser201303.PrintMessageIdFromMessage(message);
|
---|
33 | PRPAMT201305UVPatient patient = HL7Parser201303.ExtractHL7PatientFromMessage(message);
|
---|
34 | MCCIMT000100UV01Sender sender = message.getSender();
|
---|
35 | org.hl7.v3.MCCIMT000200UV01Acknowledgement acknowledge = new MCCIMT000200UV01Acknowledgement();
|
---|
36 | org.hl7.v3.MCCIMT000200UV01AcknowledgementDetail ackDetail = new MCCIMT000200UV01AcknowledgementDetail();
|
---|
37 | org.hl7.v3.CE ackCode = new CE();
|
---|
38 | if (patient == null) {
|
---|
39 | log.info("WARNING: no patient supplied");
|
---|
40 | ackCode.setCode("There was no patient supplied in 201303 Message");
|
---|
41 | ackDetail.setCode(ackCode);
|
---|
42 | } else if (sender == null ||
|
---|
43 | sender.getDevice() == null) {
|
---|
44 | log.warn("WARNING: no sender supplied");
|
---|
45 | ackCode.setCode("There was not a valid sender supplied in 201303 Message");
|
---|
46 | } else {
|
---|
47 | log.info("Found patient in message");
|
---|
48 | Patient sourcePatient = HL7Parser201303.ExtractMpiPatientFromHL7Patient(patient);
|
---|
49 | Patients searchResults = MpiDataAccess.LookupPatients(sourcePatient, AllowSearchByDemographicsForDeletePatient);
|
---|
50 |
|
---|
51 | if (CommonChecks.isZeroSearchResult(searchResults)) {
|
---|
52 | log.info("patient not found in MPI");
|
---|
53 | ackCode.setCode("The patient was not found in the MPI");
|
---|
54 | } else if (CommonChecks.isMultipleSearchResult(searchResults)) {
|
---|
55 | log.info("multiple patients found in MPI [searchResults.size()=" + searchResults.size() + "]");
|
---|
56 | ackCode.setCode("Multiple patients were found in the MPI");
|
---|
57 | } else {
|
---|
58 | log.info("patient found in MPI");
|
---|
59 |
|
---|
60 | log.info("removing patient correlation");
|
---|
61 | if (sender.getDevice().getId() != null &&
|
---|
62 | sender.getDevice().getId().size() > 0 &&
|
---|
63 | sender.getDevice().getId().get(0) != null &&
|
---|
64 | sender.getDevice().getId().get(0).getRoot() != null &&
|
---|
65 | sender.getDevice().getId().get(0).getRoot().length() > 0) {
|
---|
66 | MpiDataAccess.DeletePatient(sourcePatient, sender.getDevice().getId().get(0).getRoot());
|
---|
67 | } else {
|
---|
68 | log.warn("WARNING: An invalid sender was supplied");
|
---|
69 | ackCode.setCode("There was not a valid sender supplied in 201303 Message");
|
---|
70 | }
|
---|
71 |
|
---|
72 | ackCode.setCode("Successfully revoked patient");
|
---|
73 | }
|
---|
74 | }
|
---|
75 | ackDetail.setCode(ackCode);
|
---|
76 | acknowledge.getAcknowledgementDetail().add(ackDetail);
|
---|
77 | response.getAcknowledgement().add(acknowledge);
|
---|
78 | return response;
|
---|
79 | }
|
---|
80 |
|
---|
81 | private static org.hl7.v3.MCCIIN000002UV01 SaveAnnouncePatient(PRPAIN201301UV message, boolean AllowSearchByDemographics, boolean CreatePatientIfDoesNotExist, boolean UpdateDemographicsIfNeeded, boolean ConfirmDemographicMatchPriorToUpdatingCorrelation) {
|
---|
82 | log.info("in SaveAnnouncePatient (PRPAIN201301UV)");
|
---|
83 | MCCIIN000002UV01 result = new MCCIIN000002UV01();
|
---|
84 |
|
---|
85 | org.hl7.v3.MCCIMT000200UV01Acknowledgement acknowledge = new MCCIMT000200UV01Acknowledgement();
|
---|
86 | org.hl7.v3.MCCIMT000200UV01AcknowledgementDetail ackDetail = new MCCIMT000200UV01AcknowledgementDetail();
|
---|
87 | org.hl7.v3.CE ackCode = new CE();
|
---|
88 |
|
---|
89 | HL7Parser201301.PrintMessageIdFromMessage(message);
|
---|
90 |
|
---|
91 | PRPAMT201301UVPatient patient = HL7Parser201301.ExtractHL7PatientFromMessage(message);
|
---|
92 | MCCIMT000100UV01Sender sender = message.getSender();
|
---|
93 |
|
---|
94 | if (patient == null) {
|
---|
95 | log.warn(" no patient supplied");
|
---|
96 | ackCode.setCode("No Patient Supplied");
|
---|
97 | } else if (sender == null) {
|
---|
98 | log.warn(" no sender supplied");
|
---|
99 | ackCode.setCode("No Sender Supplied");
|
---|
100 | } else {
|
---|
101 | Patient sourcePatient = HL7Parser201301.ExtractMpiPatientFromHL7Patient(patient);
|
---|
102 | log.info("perform patient lookup in mpi");
|
---|
103 |
|
---|
104 | log.info("source patient check 1 [" + sourcePatient.getName().getLastName() + "]");
|
---|
105 | Patients searchResults = MpiDataAccess.LookupPatients(sourcePatient, AllowSearchByDemographics);
|
---|
106 | log.info("source patient check 2 [" + sourcePatient.getName().getLastName() + "]");
|
---|
107 |
|
---|
108 | if (CommonChecks.isZeroSearchResult(searchResults)) {
|
---|
109 | log.info("patient not found in MPI");
|
---|
110 | if (CreatePatientIfDoesNotExist) {
|
---|
111 | log.info("creating patient");
|
---|
112 | MpiDataAccess.SavePatient(sourcePatient);
|
---|
113 | ackCode.setCode("Patient Successfully added to the MPI");
|
---|
114 | } else {
|
---|
115 | log.info("patient not found in MPI - ignore");
|
---|
116 | //result = null;
|
---|
117 | }
|
---|
118 | } else if (CommonChecks.isMultipleSearchResult(searchResults)) {
|
---|
119 | log.info("multiple patients found in MPI [searchResults.size()=" + searchResults.size() + "]");
|
---|
120 | ackCode.setCode("Multiple patients were found in the MPI");
|
---|
121 |
|
---|
122 | result = null;
|
---|
123 | } else {
|
---|
124 | log.info("patient found in MPI. Currently IGNORE record!");
|
---|
125 | ackCode.setCode("Patient found in MPI. Currently IGNORE record");
|
---|
126 | }
|
---|
127 | }
|
---|
128 | ackDetail.setCode(ackCode);
|
---|
129 | acknowledge.getAcknowledgementDetail().add(ackDetail);
|
---|
130 | result.getAcknowledgement().add(acknowledge);
|
---|
131 |
|
---|
132 | return result;
|
---|
133 | }
|
---|
134 |
|
---|
135 | }
|
---|