source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Gateway/PatientCorrelationEJB/src/java/gov/hhs/fha/nhinc/patientcorrelationservice/impl/PatientCorrelationServiceImpl.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 11.3 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package gov.hhs.fha.nhinc.patientcorrelationservice.impl;
6
7import gov.hhs.fha.nhinc.patientcorrelation.dao.CorrelatedIdentifiersDao;
8import gov.hhs.fha.nhinc.patientcorrelation.model.*;
9import gov.hhs.fha.nhinc.patientcorrelationservice.ack.AckBuilder;
10import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.PRPAIN201301UV.PRPAIN201301UVParser;
11import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.PRPAIN201303UV.PRPAIN201303UVParser;
12import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.PRPAIN201309UV.PRPAIN201309UVParser;
13import gov.hhs.fha.nhinc.patientcorrelationservice.parsers.PRPAIN201309UV.PixRetrieveResponseBuilder;
14import java.util.ArrayList;
15import java.util.Collection;
16import java.util.Comparator;
17import java.util.HashMap;
18import java.util.HashSet;
19import java.util.Iterator;
20import java.util.LinkedHashSet;
21import java.util.List;
22import java.util.Map;
23import java.util.Set;
24import java.util.TreeSet;
25import org.hl7.v3.*;
26
27/**
28 *
29 * @author svalluripalli
30 */
31public class PatientCorrelationServiceImpl {
32
33 private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(PatientCorrelationServiceImpl.class);
34
35 public static RetrievePatientCorrelationsResponseType retrievePatientCorrelations(RetrievePatientCorrelationsRequestType retrievePatientCorrelationsRequest) {
36 log.info("start PatientCorrelationServiceImpl.retrievePatientCorrelations");
37
38 PRPAIN201309UV IN201309 = retrievePatientCorrelationsRequest.getPRPAIN201309UV();
39
40 PRPAMT201307UVPatientIdentifier patIdentifier = PRPAIN201309UVParser.parseHL7PatientPersonFrom201309Message(IN201309);
41 if (patIdentifier == null) {
42 return null;
43 }
44 List<II> listII = patIdentifier.getValue();
45 if (listII == null) {
46 return null;
47 }
48 if (listII.get(0) == null) {
49 return null;
50 }
51
52 II inputPatientId = listII.get(0);
53
54 List<String> dataSourceList = extractDataSourceList(IN201309);
55
56
57 CorrelatedIdentifiersDao dao = new CorrelatedIdentifiersDao();
58 QualifiedPatientIdentifier inputQualifiedPatientIdentifier = QualifiedPatientIdentifierFactory(inputPatientId);
59 List<QualifiedPatientIdentifier> qualifiedPatientIdentifiers = dao.retrievePatientCorrelation(inputQualifiedPatientIdentifier , dataSourceList);
60 List<II> iiList = buildList(qualifiedPatientIdentifiers);
61 PRPAIN201310UV IN201310 = PixRetrieveResponseBuilder.createPixRetrieveResponse(IN201309, iiList);
62 RetrievePatientCorrelationsResponseType result = new RetrievePatientCorrelationsResponseType();
63 result.setPRPAIN201310UV(IN201310);
64 return result;
65 }
66 //controlActProcess/queryByParameter/parameterList/DataSource/value/@root
67 private static List<String> extractDataSourceList(PRPAIN201309UV IN201309) {
68 List<String> dataSourceStringList = new ArrayList<String>();
69 PRPAMT201307UVParameterList parameterList = PRPAIN201309UVParser.parseHL7ParameterListFrom201309Message(IN201309);
70 List<PRPAMT201307UVDataSource> dataSources = parameterList.getDataSource();
71
72 if (dataSources != null) {
73 for (PRPAMT201307UVDataSource datasource : dataSources) {
74 for (II value : datasource.getValue()) {
75 dataSourceStringList.add(value.getRoot());
76 }
77 }
78 }
79
80 return dataSourceStringList;
81 }
82
83 private static List<II> buildList(List<QualifiedPatientIdentifier> qualifiedPatientIdentifiers) {
84 if (qualifiedPatientIdentifiers == null) {
85 return null;
86 }
87 List<II> iiList = new ArrayList<II>();
88
89 for (QualifiedPatientIdentifier qualifiedPatientIdentifier : qualifiedPatientIdentifiers) {
90 iiList.add(IIFactory(qualifiedPatientIdentifier));
91 }
92 return iiList;
93 }
94
95 private static II IIFactory(QualifiedPatientIdentifier qualifiedPatientIdentifier) {
96 II ii = new II();
97 ii.setRoot(qualifiedPatientIdentifier.getAssigningAuthorityId());
98 ii.setExtension(qualifiedPatientIdentifier.getPatientId());
99 return ii;
100 }
101
102 private static QualifiedPatientIdentifier QualifiedPatientIdentifierFactory(II ii) {
103 QualifiedPatientIdentifier qualifiedPatientIdentifier = new QualifiedPatientIdentifier();
104 qualifiedPatientIdentifier.setAssigningAuthority(ii.getRoot());
105 qualifiedPatientIdentifier.setPatientId(ii.getExtension());
106 return qualifiedPatientIdentifier;
107 }
108
109// private static List<II> buildListFromSingleItem(II item) {
110// List<II> list = new ArrayList<II>();
111// list.add(item);
112// return list;
113// }
114//
115// private static List<II> filterList(List<II> originalList, List<II> inclusionList, List<II> exclusionList) {
116// List<II> filteredList;
117//
118// if ((originalList == null) || (originalList.size() == 0)) {
119// filteredList = originalList;
120// } else if ((inclusionList == null) && (exclusionList == null)) {
121// filteredList = originalList;
122// } else {
123// filteredList = new ArrayList<II>();
124// for (II item : originalList) {
125// if (itemAllowed(item, inclusionList, exclusionList)) {
126// filteredList.add(item);
127// }
128// }
129// }
130//
131// return filteredList;
132// }
133//
134// private static boolean itemAllowed(II item, List<II> inclusionList, List<II> exclusionList) {
135// boolean result = true;
136//
137// if (inclusionList != null) {
138// boolean found = false;
139// for (II inclusionItem : inclusionList) {
140// if (rootsEqual(item, inclusionItem)) {
141// found = true;
142// break;
143// }
144// }
145//
146// result = found;
147// }
148//
149// if (result) {
150// if (exclusionList != null) {
151// boolean found = false;
152// for (II exclusionItem : exclusionList) {
153// if (rootsEqual(item, exclusionItem)) {
154// found = true;
155// break;
156// }
157// }
158// result = !found;
159// }
160// }
161//
162// return result;
163// }
164//
165// private static boolean rootsEqual(II a, II b) {
166// boolean result;
167// if (a == null) {
168// result = (b == null);
169// } else if (b == null) {
170// result = (a == null);
171// } else if (a.getRoot() == null) {
172// result = (b.getRoot() == null);
173// } else if (b.getRoot() == null) {
174// result = (a.getRoot() == null);
175// } else {
176// result = (a.getRoot().contentEquals(b.getRoot()));
177// }
178// return result;
179// }
180 public static AddPatientCorrelationResponseType addPatientCorrelation(AddPatientCorrelationRequestType addPatientCorrelationRequest) {
181 PRPAIN201301UV IN201301 = addPatientCorrelationRequest.getPRPAIN201301UV();
182
183 PRPAMT201301UVPatient patient = PRPAIN201301UVParser.ParseHL7PatientPersonFrom201301Message(IN201301);
184 String patientId = "";
185 String patientAssigningAuthId = "";
186 String correlatedPatientId = "";
187 String correlatedPatientAssigningAuthId = "";
188 if (patient == null) {
189 return null;
190 }
191 List<II> ids = patient.getId();
192 if (ids == null) {
193 return null;
194 }
195 if (ids.get(0) == null) {
196 return null;
197 }
198 if (ids.get(1) == null) {
199 return null;
200 }
201 patientId = ids.get(0).getExtension();
202 if (patientId != null && !patientId.equals("")) {
203 } else {
204 return null;
205 }
206 patientAssigningAuthId = ids.get(0).getRoot();
207 if (patientAssigningAuthId != null && !patientAssigningAuthId.equals("")) {
208 } else {
209 return null;
210 }
211 correlatedPatientId = ids.get(1).getExtension();
212 if (correlatedPatientId != null & !correlatedPatientId.equals("")) {
213 } else {
214 return null;
215 }
216 correlatedPatientAssigningAuthId = ids.get(1).getRoot();
217 if (correlatedPatientAssigningAuthId != null && !correlatedPatientAssigningAuthId.equals("")) {
218 } else {
219 return null;
220 }
221 if (patientAssigningAuthId.equals(correlatedPatientAssigningAuthId) && patientId.equals(correlatedPatientId)) {
222 return null;
223 }
224 CorrelatedIdentifiers correlatedIdentifers = new CorrelatedIdentifiers();
225 correlatedIdentifers.setCorrelatedPatientAssigningAuthorityId(correlatedPatientAssigningAuthId);
226 correlatedIdentifers.setCorrelatedPatientId(correlatedPatientId);
227 correlatedIdentifers.setPatientId(patientId);
228 correlatedIdentifers.setPatientAssigningAuthorityId(patientAssigningAuthId);
229 CorrelatedIdentifiersDao dao = new CorrelatedIdentifiersDao();
230 dao.addPatientCorrelation(correlatedIdentifers);
231
232
233 AddPatientCorrelationResponseType result = new AddPatientCorrelationResponseType();
234 result.setMCCIIN000002UV01(AckBuilder.BuildAck(IN201301) );
235 return result;
236 }
237
238 public static RemovePatientCorrelationResponseType removePatientCorrelation(RemovePatientCorrelationRequestType removePatientCorrelationRequest) {
239 PRPAIN201303UV IN201303 = removePatientCorrelationRequest.getPRPAIN201303UV();
240
241 PRPAMT201305UVPatient patient = PRPAIN201303UVParser.parseHL7PatientPersonFrom201303Message(IN201303);
242 if (patient == null) {
243 return null;
244 }
245
246 List<II> ids = patient.getId();
247 if (ids == null) {
248 return null;
249 }
250
251 String patientId = (ids.get(0) != null) ? ids.get(0).getExtension() : "";
252 String patientAssigningAuthId = (ids.get(0) != null) ? ids.get(0).getRoot() : "";
253 String correlatedPatientId = (ids.get(1) != null) ? ids.get(1).getExtension() : "";
254 String correlatedPatientAssigningAuthId = (ids.get(1) != null) ? ids.get(1).getRoot() : "";
255 CorrelatedIdentifiers correlatedIdentifers = new CorrelatedIdentifiers();
256 CorrelatedIdentifiers correlatedPatientIdentifers = new CorrelatedIdentifiers();
257 correlatedIdentifers.setCorrelatedPatientAssigningAuthorityId(correlatedPatientAssigningAuthId);
258 correlatedIdentifers.setCorrelatedPatientId(correlatedPatientId);
259 correlatedIdentifers.setPatientId(patientId);
260 correlatedIdentifers.setPatientAssigningAuthorityId(patientAssigningAuthId);
261 correlatedPatientIdentifers.setCorrelatedPatientAssigningAuthorityId(patientAssigningAuthId);
262 correlatedPatientIdentifers.setCorrelatedPatientId(patientId);
263 correlatedPatientIdentifers.setPatientId(correlatedPatientId);
264 correlatedPatientIdentifers.setPatientAssigningAuthorityId(correlatedPatientAssigningAuthId);
265 CorrelatedIdentifiersDao dao = new CorrelatedIdentifiersDao();
266 dao.removePatientCorrelation(correlatedIdentifers);
267 dao.removePatientCorrelation(correlatedPatientIdentifers);
268
269 RemovePatientCorrelationResponseType result = new RemovePatientCorrelationResponseType();
270 MCCIIN000002UV01 ack = new MCCIIN000002UV01();
271 result.setMCCIIN000002UV01(ack);
272 return result;
273 }
274}
Note: See TracBrowser for help on using the repository browser.