1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.transform.subdisc;
|
---|
6 |
|
---|
7 | import java.util.List;
|
---|
8 | import java.io.Serializable;
|
---|
9 | import java.util.Iterator;
|
---|
10 | import javax.xml.bind.JAXBElement;
|
---|
11 | import org.apache.commons.logging.Log;
|
---|
12 | import org.apache.commons.logging.LogFactory;
|
---|
13 | import org.hl7.v3.*;
|
---|
14 | import gov.hhs.fha.nhinc.common.nhinccommon.PersonNameType;
|
---|
15 | import gov.hhs.fha.nhinc.common.nhinccommon.CeType;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | *
|
---|
19 | * @author MFLYNN02
|
---|
20 | */
|
---|
21 | public class HL7Extractors {
|
---|
22 |
|
---|
23 | private static Log log = LogFactory.getLog(HL7Extractors.class);
|
---|
24 |
|
---|
25 | public static PRPAIN201301UVMFMIMT700701UV01Subject1 ExtractSubjectFromMessage(org.hl7.v3.PRPAIN201301UV message) {
|
---|
26 | //assume one subject for now
|
---|
27 |
|
---|
28 | if (message == null) {
|
---|
29 | log.info("message is null - no patient");
|
---|
30 | return null;
|
---|
31 | }
|
---|
32 | PRPAIN201301UVMFMIMT700701UV01ControlActProcess controlActProcess = message.getControlActProcess();
|
---|
33 | if (controlActProcess == null) {
|
---|
34 | log.info("controlActProcess is null - no patient");
|
---|
35 | return null;
|
---|
36 | }
|
---|
37 | //HL7Parser.PrintId(controlActProcess.getId(), "controlActProcess");
|
---|
38 |
|
---|
39 | List<PRPAIN201301UVMFMIMT700701UV01Subject1> subjects = controlActProcess.getSubject();
|
---|
40 | if ((subjects == null) || (subjects.size() == 0)) {
|
---|
41 | log.info("subjects is blank/null - no patient");
|
---|
42 | return null;
|
---|
43 | }
|
---|
44 |
|
---|
45 | //for now, assume we only need one subject, this will need to be modified later
|
---|
46 | PRPAIN201301UVMFMIMT700701UV01Subject1 subject = subjects.get(0);
|
---|
47 | //HL7Parser.PrintId(subject.getTypeId(), "subject");
|
---|
48 |
|
---|
49 | return subject;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public static PRPAIN201302UVMFMIMT700701UV01Subject1 ExtractSubjectFromMessage(org.hl7.v3.PRPAIN201302UV message) {
|
---|
53 | //assume one subject for now
|
---|
54 |
|
---|
55 | if (message == null) {
|
---|
56 | log.info("message is null - no patient");
|
---|
57 | return null;
|
---|
58 | }
|
---|
59 | PRPAIN201302UVMFMIMT700701UV01ControlActProcess controlActProcess = message.getControlActProcess();
|
---|
60 | if (controlActProcess == null) {
|
---|
61 | log.info("controlActProcess is null - no patient");
|
---|
62 | return null;
|
---|
63 | }
|
---|
64 | //HL7Parser.PrintId(controlActProcess.getId(), "controlActProcess");
|
---|
65 |
|
---|
66 | List<PRPAIN201302UVMFMIMT700701UV01Subject1> subjects = controlActProcess.getSubject();
|
---|
67 | if ((subjects == null) || (subjects.size() == 0)) {
|
---|
68 | log.info("subjects is blank/null - no patient");
|
---|
69 | return null;
|
---|
70 | }
|
---|
71 |
|
---|
72 | //for now, assume we only need one subject, this will need to be modified later
|
---|
73 | PRPAIN201302UVMFMIMT700701UV01Subject1 subject = subjects.get(0);
|
---|
74 | //HL7Parser.PrintId(subject.getTypeId(), "subject");
|
---|
75 |
|
---|
76 | return subject;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public static PRPAIN201303UVMFMIMT700701UV01Subject1 ExtractSubjectFromMessage(org.hl7.v3.PRPAIN201303UV message) {
|
---|
80 | //assume one subject for now
|
---|
81 |
|
---|
82 | if (message == null) {
|
---|
83 | log.info("message is null - no patient");
|
---|
84 | return null;
|
---|
85 | }
|
---|
86 | PRPAIN201303UVMFMIMT700701UV01ControlActProcess controlActProcess = message.getControlActProcess();
|
---|
87 | if (controlActProcess == null) {
|
---|
88 | log.info("controlActProcess is null - no patient");
|
---|
89 | return null;
|
---|
90 | }
|
---|
91 | //HL7Parser.PrintId(controlActProcess.getId(), "controlActProcess");
|
---|
92 |
|
---|
93 | List<PRPAIN201303UVMFMIMT700701UV01Subject1> subjects = controlActProcess.getSubject();
|
---|
94 | if ((subjects == null) || (subjects.size() == 0)) {
|
---|
95 | log.info("subjects is blank/null - no patient");
|
---|
96 | return null;
|
---|
97 | }
|
---|
98 |
|
---|
99 | //for now, assume we only need one subject, this will need to be modified later
|
---|
100 | PRPAIN201303UVMFMIMT700701UV01Subject1 subject = subjects.get(0);
|
---|
101 | //HL7Parser.PrintId(subject.getTypeId(), "subject");
|
---|
102 |
|
---|
103 | return subject;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public static PRPAIN201310UVMFMIMT700711UV01Subject1 ExtractSubjectFromMessage(org.hl7.v3.PRPAIN201310UV message) {
|
---|
107 | //assume one subject for now
|
---|
108 |
|
---|
109 | if (message == null) {
|
---|
110 | log.info("message is null - no patient");
|
---|
111 | return null;
|
---|
112 | }
|
---|
113 |
|
---|
114 | PRPAIN201310UVMFMIMT700711UV01ControlActProcess controlActProcess = message.getControlActProcess();
|
---|
115 | if (controlActProcess == null) {
|
---|
116 | log.info("controlActProcess is null - no patient");
|
---|
117 | return null;
|
---|
118 | }
|
---|
119 | //HL7Parser.PrintId(controlActProcess.getId(), "controlActProcess");
|
---|
120 |
|
---|
121 | List<PRPAIN201310UVMFMIMT700711UV01Subject1> subjects = controlActProcess.getSubject();
|
---|
122 | if ((subjects == null) || (subjects.size() == 0)) {
|
---|
123 | log.info("subjects is blank/null - no patient");
|
---|
124 | return null;
|
---|
125 | }
|
---|
126 |
|
---|
127 | //for now, assume we only need one subject, this will need to be modified later
|
---|
128 | PRPAIN201310UVMFMIMT700711UV01Subject1 subject = subjects.get(0);
|
---|
129 | //HL7Parser.PrintId(subject.getTypeId(), "subject");
|
---|
130 |
|
---|
131 | return subject;
|
---|
132 | }
|
---|
133 |
|
---|
134 | public static PRPAMT201301UVPatient ExtractHL7PatientFromMessage(org.hl7.v3.PRPAIN201301UV message) {
|
---|
135 | PRPAMT201301UVPatient patient = null;
|
---|
136 | log.info("in ExtractPatient");
|
---|
137 |
|
---|
138 | PRPAIN201301UVMFMIMT700701UV01Subject1 subject = ExtractSubjectFromMessage(message);
|
---|
139 | if (subject == null) {
|
---|
140 | return null;
|
---|
141 | }
|
---|
142 | PRPAIN201301UVMFMIMT700701UV01RegistrationEvent registrationevent = subject.getRegistrationEvent();
|
---|
143 | if (registrationevent == null) {
|
---|
144 | log.info("registrationevent is null - no patient");
|
---|
145 | return null;
|
---|
146 | }
|
---|
147 | //HL7Parser.PrintId(registrationevent.getTypeId(), "registrationevent");
|
---|
148 |
|
---|
149 | PRPAIN201301UVMFMIMT700701UV01Subject2 subject1 = registrationevent.getSubject1();
|
---|
150 | if (subject1 == null) {
|
---|
151 | log.info("subject1 is null - no patient");
|
---|
152 | return null;
|
---|
153 | }
|
---|
154 | //HL7Parser.PrintId(subject1.getTypeId(), "subject1");
|
---|
155 |
|
---|
156 | patient = subject1.getPatient();
|
---|
157 | if (patient == null) {
|
---|
158 | log.info("patient is null - no patient");
|
---|
159 | return null;
|
---|
160 | }
|
---|
161 | //HL7Parser.PrintId(patient.getId(), "patient");
|
---|
162 |
|
---|
163 | log.info("done with ExtractPatient");
|
---|
164 | return patient;
|
---|
165 | }
|
---|
166 |
|
---|
167 | public static PRPAMT201302UVPatient ExtractHL7PatientFromMessage(org.hl7.v3.PRPAIN201302UV message) {
|
---|
168 | PRPAMT201302UVPatient patient = null;
|
---|
169 | log.info("in ExtractPatient");
|
---|
170 |
|
---|
171 | PRPAIN201302UVMFMIMT700701UV01Subject1 subject = ExtractSubjectFromMessage(message);
|
---|
172 | if (subject == null) {
|
---|
173 | return null;
|
---|
174 | }
|
---|
175 | PRPAIN201302UVMFMIMT700701UV01RegistrationEvent registrationevent = subject.getRegistrationEvent();
|
---|
176 | if (registrationevent == null) {
|
---|
177 | log.info("registrationevent is null - no patient");
|
---|
178 | return null;
|
---|
179 | }
|
---|
180 | //HL7Parser.PrintId(registrationevent.getTypeId(), "registrationevent");
|
---|
181 |
|
---|
182 | PRPAIN201302UVMFMIMT700701UV01Subject2 subject1 = registrationevent.getSubject1();
|
---|
183 | if (subject1 == null) {
|
---|
184 | log.info("subject1 is null - no patient");
|
---|
185 | return null;
|
---|
186 | }
|
---|
187 | //HL7Parser.PrintId(subject1.getTypeId(), "subject1");
|
---|
188 |
|
---|
189 | patient = subject1.getPatient();
|
---|
190 | if (patient == null) {
|
---|
191 | log.info("patient is null - no patient");
|
---|
192 | return null;
|
---|
193 | }
|
---|
194 | //HL7Parser.PrintId(patient.getId(), "patient");
|
---|
195 |
|
---|
196 | log.info("done with ExtractPatient");
|
---|
197 | return patient;
|
---|
198 | }
|
---|
199 |
|
---|
200 | public static PRPAMT201305UVPatient ExtractHL7PatientFromMessage(org.hl7.v3.PRPAIN201303UV message) {
|
---|
201 | PRPAMT201305UVPatient patient = null;
|
---|
202 | log.info("in ExtractPatient");
|
---|
203 |
|
---|
204 | PRPAIN201303UVMFMIMT700701UV01Subject1 subject = ExtractSubjectFromMessage(message);
|
---|
205 | if (subject == null) {
|
---|
206 | return null;
|
---|
207 | }
|
---|
208 | PRPAIN201303UVMFMIMT700701UV01RegistrationEvent registrationevent = subject.getRegistrationEvent();
|
---|
209 | if (registrationevent == null) {
|
---|
210 | log.info("registrationevent is null - no patient");
|
---|
211 | return null;
|
---|
212 | }
|
---|
213 | //HL7Parser.PrintId(registrationevent.getTypeId(), "registrationevent");
|
---|
214 |
|
---|
215 | PRPAIN201303UVMFMIMT700701UV01Subject2 subject1 = registrationevent.getSubject1();
|
---|
216 | if (subject1 == null) {
|
---|
217 | log.info("subject1 is null - no patient");
|
---|
218 | return null;
|
---|
219 | }
|
---|
220 | //HL7Parser.PrintId(subject1.getTypeId(), "subject1");
|
---|
221 |
|
---|
222 | patient = subject1.getPatient();
|
---|
223 | if (patient == null) {
|
---|
224 | log.info("patient is null - no patient");
|
---|
225 | return null;
|
---|
226 | }
|
---|
227 | //HL7Parser.PrintId(patient.getId(), "patient");
|
---|
228 |
|
---|
229 | log.info("done with ExtractPatient");
|
---|
230 | return patient;
|
---|
231 | }
|
---|
232 |
|
---|
233 | public static PRPAMT201304UVPatient ExtractHL7PatientFromMessage(org.hl7.v3.PRPAIN201310UV message) {
|
---|
234 | PRPAMT201304UVPatient patient = null;
|
---|
235 | log.info("in ExtractPatient");
|
---|
236 |
|
---|
237 | PRPAIN201310UVMFMIMT700711UV01Subject1 subject = ExtractSubjectFromMessage(message);
|
---|
238 | if (subject == null) {
|
---|
239 | return null;
|
---|
240 | }
|
---|
241 |
|
---|
242 | PRPAIN201310UVMFMIMT700711UV01RegistrationEvent registrationevent = subject.getRegistrationEvent();
|
---|
243 | if (registrationevent == null) {
|
---|
244 | log.info("registrationevent is null - no patient");
|
---|
245 | return null;
|
---|
246 | }
|
---|
247 | //HL7Parser.PrintId(registrationevent.getTypeId(), "registrationevent");
|
---|
248 |
|
---|
249 | PRPAIN201310UVMFMIMT700711UV01Subject2 subject1 = registrationevent.getSubject1();
|
---|
250 | if (subject1 == null) {
|
---|
251 | log.info("subject1 is null - no patient");
|
---|
252 | return null;
|
---|
253 | }
|
---|
254 | //HL7Parser.PrintId(subject1.getTypeId(), "subject1");
|
---|
255 |
|
---|
256 |
|
---|
257 | patient = subject1.getPatient();
|
---|
258 | if (patient == null) {
|
---|
259 | log.info("patient is null - no patient");
|
---|
260 | return null;
|
---|
261 | }
|
---|
262 | //HL7Parser.PrintId(patient.getId(), "patient");
|
---|
263 |
|
---|
264 | log.info("done with ExtractPatient");
|
---|
265 | return patient;
|
---|
266 | }
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * This method translates a List<PN> into an PersonName object.
|
---|
270 | *
|
---|
271 | * @param The List of PN objects to be translated
|
---|
272 | * @param The Person object
|
---|
273 | */
|
---|
274 | public static PersonNameType translatePNListtoPersonNameType(List<PNExplicit> names) {
|
---|
275 | log.debug("HL7Extractor.translatePNListtoPersonNameType() -- Begin");
|
---|
276 | PersonNameType personName = new PersonNameType();
|
---|
277 | // NameType
|
---|
278 | if (names.get(0).getUse().size() > 0) {
|
---|
279 | CeType nameType = new CeType();
|
---|
280 | nameType.setCode(names.get(0).getUse().get(0));
|
---|
281 | personName.setNameType(nameType);
|
---|
282 | }
|
---|
283 | // Name parts
|
---|
284 | if (names.size() > 0 &&
|
---|
285 | names.get(0).getContent() != null) {
|
---|
286 | List<Serializable> choice = names.get(0).getContent();
|
---|
287 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
288 |
|
---|
289 | String nameString = "";
|
---|
290 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
291 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
292 | Boolean hasName = false;
|
---|
293 |
|
---|
294 | while (iterSerialObjects.hasNext()) {
|
---|
295 | Serializable contentItem = iterSerialObjects.next();
|
---|
296 |
|
---|
297 | if (contentItem instanceof String) {
|
---|
298 | String strValue = (String) contentItem;
|
---|
299 | if (nameString != null) {
|
---|
300 | nameString += strValue;
|
---|
301 | } else {
|
---|
302 | nameString = strValue;
|
---|
303 | }
|
---|
304 | System.out.println("Here is the contents of the string: " + strValue);
|
---|
305 | } else if (contentItem instanceof JAXBElement) {
|
---|
306 | JAXBElement oJAXBElement = (JAXBElement) contentItem;
|
---|
307 | log.debug("Found JAXBElement");
|
---|
308 | if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
|
---|
309 | familyName = (EnExplicitFamily) oJAXBElement.getValue();
|
---|
310 | log.debug("Found FamilyName " + familyName.getContent());
|
---|
311 | hasName = true;
|
---|
312 | } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
|
---|
313 | givenName = (EnExplicitGiven) oJAXBElement.getValue();
|
---|
314 | log.debug("Found GivenName " + givenName.getContent());
|
---|
315 | hasName = true;
|
---|
316 | }
|
---|
317 | }
|
---|
318 | }
|
---|
319 | // If text string, then set in familyName
|
---|
320 | // else set in element.
|
---|
321 | if (nameString != null && hasName == false) {
|
---|
322 | log.debug("set org name text ");
|
---|
323 | personName.setFamilyName(nameString);
|
---|
324 | } else {
|
---|
325 | if (givenName.getContent() != null &&
|
---|
326 | givenName.getContent().length() > 0) {
|
---|
327 | log.debug("set org name given ");
|
---|
328 | personName.setGivenName(givenName.getContent());
|
---|
329 |
|
---|
330 | }
|
---|
331 | if (familyName.getContent() != null &&
|
---|
332 | familyName.getContent().length() > 0) {
|
---|
333 | log.debug("set org name family ");
|
---|
334 | personName.setFamilyName(familyName.getContent());
|
---|
335 | }
|
---|
336 |
|
---|
337 | }
|
---|
338 | }
|
---|
339 | log.debug("HL7Extractor.translatePNListtoPersonNameType() -- End");
|
---|
340 | return personName;
|
---|
341 |
|
---|
342 | }
|
---|
343 |
|
---|
344 | /**
|
---|
345 | * This method translates a List of EN objects to a PersonName object.
|
---|
346 | *
|
---|
347 | * @param The List<EN> objects to be translated
|
---|
348 | * @param The PersonName object
|
---|
349 | */
|
---|
350 | public static PersonNameType translateENListtoPersonNameType(List<ENExplicit> names) {
|
---|
351 | log.debug("HL7Extractor.translateENListtoPersonNameType() -- Begin");
|
---|
352 | PersonNameType personName = new PersonNameType();
|
---|
353 | // NameType
|
---|
354 | if (names.size() > 0 && names.get(0).getUse().size() > 0) {
|
---|
355 | CeType nameType = new CeType();
|
---|
356 | nameType.setCode(names.get(0).getUse().get(0));
|
---|
357 | personName.setNameType(nameType);
|
---|
358 | }
|
---|
359 | if (names.size() > 0 &&
|
---|
360 | names.get(0).getContent() != null) {
|
---|
361 | List<Serializable> choice = names.get(0).getContent();
|
---|
362 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
363 |
|
---|
364 | String nameString = "";
|
---|
365 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
366 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
367 |
|
---|
368 | while (iterSerialObjects.hasNext()) {
|
---|
369 | Serializable contentItem = iterSerialObjects.next();
|
---|
370 |
|
---|
371 | if (contentItem instanceof String) {
|
---|
372 | String strValue = (String) contentItem;
|
---|
373 | if (nameString != null) {
|
---|
374 | nameString += strValue;
|
---|
375 | } else {
|
---|
376 | nameString = strValue;
|
---|
377 | }
|
---|
378 | System.out.println("Here is the contents of the string: " + strValue);
|
---|
379 | } else if (contentItem instanceof JAXBElement) {
|
---|
380 | JAXBElement oJAXBElement = (JAXBElement) contentItem;
|
---|
381 |
|
---|
382 | if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
|
---|
383 | familyName = (EnExplicitFamily) oJAXBElement.getValue();
|
---|
384 |
|
---|
385 | } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
|
---|
386 | givenName = (EnExplicitGiven) oJAXBElement.getValue();
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | }
|
---|
391 | // If text string in HomeCommunity.representativeOrg, then set in familyName
|
---|
392 | // else set in element.
|
---|
393 | if (nameString != null) {
|
---|
394 | log.debug("set org name text ");
|
---|
395 | personName.setFamilyName(nameString);
|
---|
396 | } else {
|
---|
397 | if (givenName.getContent() != null &&
|
---|
398 | givenName.getContent().length() > 0) {
|
---|
399 | log.debug("set org name given ");
|
---|
400 | personName.setGivenName(givenName.getContent());
|
---|
401 |
|
---|
402 | }
|
---|
403 | if (familyName.getContent() != null &&
|
---|
404 | familyName.getContent().length() > 0) {
|
---|
405 | log.debug("set org name family ");
|
---|
406 | personName.setFamilyName(familyName.getContent());
|
---|
407 | }
|
---|
408 |
|
---|
409 | }
|
---|
410 |
|
---|
411 | }
|
---|
412 | log.debug("HL7Extractor.translateENListtoPersonNameType() -- End");
|
---|
413 | return personName;
|
---|
414 | }
|
---|
415 |
|
---|
416 | public static PRPAMT201301UVPerson ExtractHL7PatientPersonFromHL7Patient(PRPAMT201301UVPatient patient) {
|
---|
417 | JAXBElement<PRPAMT201301UVPerson> patientPersonElement = patient.getPatientPerson();
|
---|
418 | PRPAMT201301UVPerson patientPerson = patientPerson = patientPersonElement.getValue();
|
---|
419 | return patientPerson;
|
---|
420 | }
|
---|
421 |
|
---|
422 | public static PRPAMT201302UVPerson ExtractHL7PatientPersonFromHL7Patient(PRPAMT201302UVPatient patient) {
|
---|
423 | JAXBElement<PRPAMT201302UVPerson> patientPersonElement = patient.getPatientPerson();
|
---|
424 | PRPAMT201302UVPerson patientPerson = patientPerson = patientPersonElement.getValue();
|
---|
425 | return patientPerson;
|
---|
426 | }
|
---|
427 |
|
---|
428 | public static PRPAMT201301UVPerson ExtractHL7PatientPersonFrom201301Message(org.hl7.v3.PRPAIN201301UV message) {
|
---|
429 | //assume one subject for now
|
---|
430 | PRPAMT201301UVPatient patient = ExtractHL7PatientFromMessage(message);
|
---|
431 | PRPAMT201301UVPerson patientPerson = ExtractHL7PatientPersonFromHL7Patient(patient);
|
---|
432 | return patientPerson;
|
---|
433 | }
|
---|
434 |
|
---|
435 | public static PRPAMT201302UVPerson ExtractHL7PatientPersonFrom201302Message(org.hl7.v3.PRPAIN201302UV message) {
|
---|
436 | //assume one subject for now
|
---|
437 | PRPAMT201302UVPatient patient = ExtractHL7PatientFromMessage(message);
|
---|
438 | PRPAMT201302UVPerson patientPerson = ExtractHL7PatientPersonFromHL7Patient(patient);
|
---|
439 | return patientPerson;
|
---|
440 | }
|
---|
441 | }
|
---|