source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Adapters/General/MpiManagerEJB/src/java/gov/hhs/fha/nhinc/adaptermpimanager/HL7Parsers/HL7Parser201301.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: 14.1 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package gov.hhs.fha.nhinc.adaptermpimanager.HL7Parsers;
7
8import gov.hhs.fha.nhinc.adaptermpimanager.*;
9import gov.hhs.fha.nhinc.mpilib.*;
10import java.util.List;
11import java.io.Serializable;
12import java.util.Iterator;
13import javax.xml.bind.JAXBElement;
14import org.apache.commons.logging.Log;
15import org.apache.commons.logging.LogFactory;
16import org.hl7.v3.*;
17
18/**
19 *
20 * @author rayj
21 */
22public class HL7Parser201301 {
23
24 private static Log log = LogFactory.getLog(HL7Parser201301.class);
25
26 public static void PrintMessageIdFromMessage(org.hl7.v3.PRPAIN201301UV message) {
27 if (!(message == null)) {
28 HL7Parser.PrintId(message.getId(), "message");
29 }
30 }
31
32 public static String ExtractGender(PRPAMT201301UVPerson person) {
33 String genderCode = null;
34 CE administrativeGenderCode = person.getAdministrativeGenderCode();
35 if (administrativeGenderCode == null) {
36 log.info("message does not contain a gender code");
37 } else {
38 log.info("person.getAdministrativeGenderCode().getCode()=" + person.getAdministrativeGenderCode().getCode());
39 log.info("person.getAdministrativeGenderCode().getDisplayName()=" + person.getAdministrativeGenderCode().getDisplayName());
40 genderCode = person.getAdministrativeGenderCode().getCode();
41 }
42 return genderCode;
43 }
44
45 public static String ExtractBirthdate(PRPAMT201301UVPerson person) {
46 String birthDate = null;
47 if (person.getBirthTime() == null) {
48 log.info("message does not contain a birthtime");
49 } else {
50 birthDate = person.getBirthTime().getValue();
51 if (birthDate == null) {
52 log.info("message does not contain a birthtime");
53 } else {
54 log.info("person.getBirthTime().getValue()=" + person.getBirthTime().getValue());
55 }
56 }
57 return birthDate;
58 }
59
60 public static PersonName ExtractPersonName(PRPAMT201301UVPerson person) {
61 //temp logic to prove i can get to name - long term would want to store discrete name parts
62 //also assume one name, not multiple names
63 PersonName personname = new PersonName();
64
65 log.info("patientPerson.getName().size() " + person.getName().size());
66 if (person.getName() != null &&
67 person.getName().size() > 0 &&
68 person.getName().get(0) != null &&
69 person.getName().get(0).getContent() != null) {
70
71 List<Serializable> choice = person.getName().get(0).getContent();
72 log.info("choice.size()=" + choice.size());
73
74 Iterator<Serializable> iterSerialObjects = choice.iterator();
75
76 String nameString = "";
77 EnExplicitFamily lastname = new EnExplicitFamily();
78 EnExplicitGiven firstname = new EnExplicitGiven();
79
80 while (iterSerialObjects.hasNext()) {
81 log.info("in iterSerialObjects.hasNext() loop");
82
83 Serializable contentItem = iterSerialObjects.next();
84
85 if (contentItem instanceof String) {
86 log.info("contentItem is string");
87 String strValue = (String) contentItem;
88
89 if (nameString != null) {
90 nameString += strValue;
91 } else {
92 nameString = strValue;
93 }
94 log.info("nameString=" + nameString);
95 } else if (contentItem instanceof JAXBElement) {
96 log.info("contentItem is JAXBElement");
97
98 JAXBElement oJAXBElement = (JAXBElement) contentItem;
99
100 if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
101 lastname = (EnExplicitFamily) oJAXBElement.getValue();
102 log.info("found lastname element; content=" + lastname.getContent());
103 } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
104 firstname = (EnExplicitGiven) oJAXBElement.getValue();
105 log.info("found firstname element; content=" + firstname.getContent());
106 } else {
107 log.info("other name part=" + (ENXPExplicit) oJAXBElement.getValue());
108 }
109 } else {
110 log.info("contentItem is other");
111 }
112 }
113
114 // If text string in patient name, then set in name
115 // else set in element.
116 boolean namefound = false;
117 if (lastname.getContent() != null) {
118 personname.setLastName(lastname.getContent());
119 log.info("FamilyName : " + personname.getLastName());
120 namefound = true;
121 }
122
123 if (firstname.getContent() != null) {
124 personname.setFirstName(firstname.getContent());
125 log.info("GivenName : " + personname.getFirstName());
126 namefound = true;
127 }
128
129 if (!namefound && !nameString.trim().contentEquals("")) {
130 log.info("setting name by nameString " + nameString);
131 personname.setLastName(nameString);
132 } else {
133 }
134 }
135 log.info("returning personname");
136 return personname;
137 }
138
139 public static Identifiers ExtractPersonIdentifiers(PRPAMT201301UVPatient patient) {
140 Identifiers ids = new Identifiers();
141 for (II patientid : patient.getId()) {
142 Identifier id = new Identifier();
143 id.setId(patientid.getExtension());
144 id.setOrganizationId(patientid.getRoot());
145 log.info("Created id from patient identifier [organization=" + id.getOrganizationId() + "][id=" + id.getId() + "]");
146 ids.add(id);
147 }
148
149 PRPAMT201301UVPerson person = ExtractHL7PatientPersonFromHL7Patient(patient);
150 for (II personid : person.getId()) {
151 Identifier id = new Identifier();
152 id.setId(personid.getExtension());
153 id.setOrganizationId(personid.getRoot());
154 log.info("Created id from person identifier [organization=" + id.getOrganizationId() + "][id=" + id.getId() + "]");
155 ids.add(id);
156 }
157
158 List<PRPAMT201301UVOtherIDs> OtherIds = person.getAsOtherIDs();
159 for (PRPAMT201301UVOtherIDs otherPersonIds : OtherIds) {
160 for (II otherPersonId : otherPersonIds.getId()) {
161 Identifier id = new Identifier();
162 id.setId(otherPersonId.getExtension());
163 id.setOrganizationId(otherPersonId.getRoot());
164 log.info("Created id from person other identifier [organization=" + id.getOrganizationId() + "][id=" + id.getId() + "]");
165 ids.add(id);
166 }
167 }
168
169 return ids;
170 }
171
172 public static PRPAMT201301UVPerson ExtractHL7PatientPersonFromHL7Patient(PRPAMT201301UVPatient patient) {
173 JAXBElement<PRPAMT201301UVPerson> patientPersonElement = patient.getPatientPerson();
174 PRPAMT201301UVPerson patientPerson = patientPerson = patientPersonElement.getValue();
175 return patientPerson;
176 }
177
178 public static PRPAMT201301UVPerson ExtractHL7PatientPersonFrom201301Message(org.hl7.v3.PRPAIN201301UV message) {
179 //assume one subject for now
180 PRPAMT201301UVPatient patient = ExtractHL7PatientFromMessage(message);
181 PRPAMT201301UVPerson patientPerson = ExtractHL7PatientPersonFromHL7Patient(patient);
182 return patientPerson;
183 }
184
185 public static PRPAMT201301UVPatient ExtractHL7PatientFromMessage(org.hl7.v3.PRPAIN201301UV message) {
186 //assume one subject for now
187 PRPAMT201301UVPatient patient = null;
188 log.info("in ExtractPatient");
189
190 if (message == null) {
191 log.info("message is null - no patient");
192 return null;
193 }
194 PRPAIN201301UVMFMIMT700701UV01ControlActProcess controlActProcess = message.getControlActProcess();
195 if (controlActProcess == null) {
196 log.info("controlActProcess is null - no patient");
197 return null;
198 }
199 HL7Parser.PrintId(controlActProcess.getId(), "controlActProcess");
200
201 List<PRPAIN201301UVMFMIMT700701UV01Subject1> subjects = controlActProcess.getSubject();
202 if ((subjects == null) || (subjects.size() == 0)) {
203 log.info("subjects is blank/null - no patient");
204 return null;
205 }
206
207 //for now, assume we only need one subject, this will need to be modified later
208 PRPAIN201301UVMFMIMT700701UV01Subject1 subject = subjects.get(0);
209 HL7Parser.PrintId(subject.getTypeId(), "subject");
210
211 PRPAIN201301UVMFMIMT700701UV01RegistrationEvent registrationevent = subject.getRegistrationEvent();
212 if (registrationevent == null) {
213 log.info("registrationevent is null - no patient");
214 return null;
215 }
216 HL7Parser.PrintId(registrationevent.getTypeId(), "registrationevent");
217
218 PRPAIN201301UVMFMIMT700701UV01Subject2 subject1 = registrationevent.getSubject1();
219 if (subject1 == null) {
220 log.info("subject1 is null - no patient");
221 return null;
222 }
223 HL7Parser.PrintId(subject1.getTypeId(), "subject1");
224
225 patient = subject1.getPatient();
226 if (patient == null) {
227 log.info("patient is null - no patient");
228 return null;
229 }
230 HL7Parser.PrintId(patient.getId(), "patient");
231
232 log.info("done with ExtractPatient");
233 return patient;
234 }
235
236 public static Patient ExtractMpiPatientFromMessage(org.hl7.v3.PRPAIN201301UV message) {
237 PRPAMT201301UVPatient hl7patient = ExtractHL7PatientFromMessage(message);
238 Patient mpipatient = ExtractMpiPatientFromHL7Patient(hl7patient);
239 return mpipatient;
240 }
241
242 public static Patient ExtractMpiPatientFromHL7Patient(PRPAMT201301UVPatient patient) {
243 PRPAMT201301UVPerson patientPerson = ExtractHL7PatientPersonFromHL7Patient(patient);
244 Patient mpiPatient = new Patient();
245 mpiPatient.setName(ExtractPersonName(patientPerson));
246 mpiPatient.setGender(ExtractGender(patientPerson));
247 String birthdateString = ExtractBirthdate(patientPerson);
248 mpiPatient.setDateOfBirth(birthdateString);
249
250 Identifiers ids = ExtractPersonIdentifiers(patient);
251 mpiPatient.setIdentifiers(ids);
252 return mpiPatient;
253 }
254
255 public static org.hl7.v3.PRPAIN201301UV BuildMessagePRPAIN201301UV(Patient mpiPatient) {
256 ObjectFactory factory = new ObjectFactory();
257 org.hl7.v3.PRPAIN201301UV resultMessage = new org.hl7.v3.PRPAIN201301UV();
258
259 PRPAIN201301UVMFMIMT700701UV01Subject1 subject = new PRPAIN201301UVMFMIMT700701UV01Subject1();
260 PRPAIN201301UVMFMIMT700701UV01RegistrationEvent registrationevent = new PRPAIN201301UVMFMIMT700701UV01RegistrationEvent();
261 subject.setRegistrationEvent(registrationevent);
262
263 PRPAIN201301UVMFMIMT700701UV01Subject2 subjectA = new PRPAIN201301UVMFMIMT700701UV01Subject2();
264 registrationevent.setSubject1(subjectA);
265
266 PRPAMT201301UVPatient patient = new PRPAMT201301UVPatient();
267 subjectA.setPatient(patient);
268 PRPAMT201301UVPerson patientPerson = new PRPAMT201301UVPerson();
269 javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "patientPerson");
270 JAXBElement<PRPAMT201301UVPerson> patientPersonElement = new JAXBElement<PRPAMT201301UVPerson>(xmlqname, PRPAMT201301UVPerson.class, patientPerson);
271 patient.setPatientPerson(patientPersonElement);
272 patientPersonElement.setValue(patientPerson);
273 PRPAIN201301UVMFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201301UVMFMIMT700701UV01ControlActProcess();
274 resultMessage.setControlActProcess(controlActProcess);
275 List<PRPAIN201301UVMFMIMT700701UV01Subject1> subjects = resultMessage.getControlActProcess().getSubject();
276 subjects.add(subject);
277 if (!(mpiPatient.getDateOfBirth() == null)) {
278 TSExplicit birthtime = new TSExplicit();
279 birthtime.setValue(mpiPatient.getDateOfBirth().toString());
280 patientPerson.setBirthTime(birthtime);
281 }
282
283 CE administrativeGenderCode = new CE();
284 administrativeGenderCode.setCode(mpiPatient.getGender());
285 patientPerson.setAdministrativeGenderCode(administrativeGenderCode);
286
287 //
288 // Name.
289 //
290 PNExplicit name = (PNExplicit) (factory.createPNExplicit());
291 List namelist = name.getContent();
292
293 if (mpiPatient.getName() != null && mpiPatient.getName().getLastName().length() > 0) {
294 log.info("familyName >" + mpiPatient.getName().getLastName() + "<");
295 EnExplicitFamily familyName = new EnExplicitFamily();
296 familyName.setContent(mpiPatient.getName().getLastName());
297 familyName.setPartType("FAM");
298 namelist.add(factory.createPNExplicitFamily(familyName));
299 }
300
301 if (mpiPatient.getName() != null && mpiPatient.getName().getFirstName().length() > 0) {
302 log.info("givenName >" + mpiPatient.getName().getFirstName() + "<");
303 EnExplicitGiven givenName = new EnExplicitGiven();
304 givenName.setContent(mpiPatient.getName().getFirstName());
305 givenName.setPartType("GIV");
306 namelist.add(factory.createPNExplicitGiven(givenName));
307 }
308
309 namelist.add(" ");
310 patientPerson.getName().add(name);
311
312
313
314 for (Identifier resultPatientId : mpiPatient.getIdentifiers()) {
315 II id = new II();
316 id.setRoot(resultPatientId.getOrganizationId());
317 id.setExtension(resultPatientId.getId());
318 patient.getId().add(id);
319 }
320
321 Identifier resultPatientId = mpiPatient.getIdentifiers().get(0);
322 II id = new II();
323 id.setRoot(resultPatientId.getOrganizationId());
324 MCCIMT000100UV01Device device = new MCCIMT000100UV01Device();
325 MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
326 device.getId().add(id);
327 sender.setDevice(device);
328 resultMessage.setSender(sender);
329
330 return resultMessage;
331 }
332}
Note: See TracBrowser for help on using the repository browser.