source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Adapters/General/MpiEJB/src/java/gov/hhs/fha/nhinc/adaptercomponentmpi/hl7parsers/HL7Parser201305.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.1 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.adaptercomponentmpi.hl7parsers;
6
7//import gov.hhs.fha.nhinc.mpi.*;
8import gov.hhs.fha.nhinc.mpilib.*;
9import java.util.List;
10import java.io.Serializable;
11import java.util.Iterator;
12import javax.xml.bind.JAXBElement;
13import org.apache.commons.logging.Log;
14import org.apache.commons.logging.LogFactory;
15import org.hl7.v3.*;
16
17/**
18 *
19 * @author rayj
20 */
21public class HL7Parser201305 {
22
23 private static Log log = LogFactory.getLog(HL7Parser201305.class);
24
25 public static String ExtractGender(PRPAMT201306UVParameterList params) {
26 log.debug("Entering HL7Parser201305.ExtractGender method...");
27
28 String genderCode = null;
29
30 // Extract the gender from the query parameters - Assume only one was specified
31 if (params.getLivingSubjectAdministrativeGender() != null &&
32 params.getLivingSubjectAdministrativeGender().size() > 0 &&
33 params.getLivingSubjectAdministrativeGender().get(0) != null) {
34 PRPAMT201306UVLivingSubjectAdministrativeGender gender = params.getLivingSubjectAdministrativeGender().get(0);
35
36 if (gender.getValue() != null &&
37 gender.getValue().size() > 0 &&
38 gender.getValue().get(0) != null) {
39 CE administrativeGenderCode = gender.getValue().get(0);
40
41 log.info("Found gender in query parameters = " + administrativeGenderCode.getCode());
42 genderCode = administrativeGenderCode.getCode();
43 } else {
44 log.info("query does not contain a gender code");
45 }
46 } else {
47 log.info("query does not contain a gender code");
48 }
49
50 log.debug("Exiting HL7Parser201305.ExtractGender method...");
51 return genderCode;
52 }
53
54 public static String ExtractBirthdate(PRPAMT201306UVParameterList params) {
55 log.debug("Entering HL7Parser201305.ExtractBirthdate method...");
56
57 String birthDate = null;
58
59 // Extract the birth time from the query parameters - Assume only one was specified
60 if (params.getLivingSubjectBirthTime() != null &&
61 params.getLivingSubjectBirthTime().size() > 0 &&
62 params.getLivingSubjectBirthTime().get(0) != null) {
63 PRPAMT201306UVLivingSubjectBirthTime birthTime = params.getLivingSubjectBirthTime().get(0);
64
65 if (birthTime.getValue() != null &&
66 birthTime.getValue().size() > 0 &&
67 birthTime.getValue().get(0) != null) {
68 IVLTSExplicit birthday = birthTime.getValue().get(0);
69 log.info("Found birthTime in query parameters = " + birthday.getValue());
70 birthDate = birthday.getValue();
71 } else {
72 log.info("message does not contain a birthtime");
73 }
74 } else {
75 log.info("message does not contain a birthtime");
76 }
77
78 log.debug("Exiting HL7Parser201305.ExtractBirthdate method...");
79 return birthDate;
80 }
81
82 public static PersonName ExtractPersonName(PRPAMT201306UVParameterList params) {
83 log.debug("Entering HL7Parser201305.ExtractPersonName method...");
84
85 PersonName personname = new PersonName();
86
87 // Extract the name from the query parameters - Assume only one was specified
88 if (params.getLivingSubjectName() != null &&
89 params.getLivingSubjectName().size() > 0 &&
90 params.getLivingSubjectName().get(0) != null) {
91 PRPAMT201306UVLivingSubjectName name = params.getLivingSubjectName().get(0);
92
93 if (name.getValue() != null &&
94 name.getValue().size() > 0 &&
95 name.getValue().get(0) != null) {
96 List<Serializable> choice = name.getValue().get(0).getContent();
97
98 log.info("choice.size()=" + choice.size());
99
100 Iterator<Serializable> iterSerialObjects = choice.iterator();
101
102 String nameString = "";
103 EnExplicitFamily lastname = new EnExplicitFamily();
104 EnExplicitGiven firstname = new EnExplicitGiven();
105
106 while (iterSerialObjects.hasNext()) {
107 log.info("in iterSerialObjects.hasNext() loop");
108
109 Serializable contentItem = iterSerialObjects.next();
110
111 if (contentItem instanceof String) {
112 log.info("contentItem is string");
113 String strValue = (String) contentItem;
114
115 if (nameString != null) {
116 nameString += strValue;
117 } else {
118 nameString = strValue;
119 }
120 log.info("nameString=" + nameString);
121 } else if (contentItem instanceof JAXBElement) {
122 log.info("contentItem is JAXBElement");
123
124 JAXBElement oJAXBElement = (JAXBElement) contentItem;
125
126 if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
127 lastname = (EnExplicitFamily) oJAXBElement.getValue();
128 log.info("found lastname element; content=" + lastname.getContent());
129 } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
130 firstname = (EnExplicitGiven) oJAXBElement.getValue();
131 log.info("found firstname element; content=" + firstname.getContent());
132 } else {
133 log.info("other name part=" + (ENXPExplicit) oJAXBElement.getValue());
134 }
135 } else {
136 log.info("contentItem is other");
137 }
138 }
139
140 // If text string in patient name, then set in name
141 // else set in element.
142 boolean namefound = false;
143 if (lastname.getContent() != null) {
144 personname.setLastName(lastname.getContent());
145 log.info("FamilyName : " + personname.getLastName());
146 namefound = true;
147 }
148
149 if (firstname.getContent() != null) {
150 personname.setFirstName(firstname.getContent());
151 log.info("GivenName : " + personname.getFirstName());
152 namefound = true;
153 }
154
155 if (!namefound && !nameString.trim().contentEquals("")) {
156 log.info("setting name by nameString " + nameString);
157 personname.setLastName(nameString);
158
159 }
160 } else {
161 log.info("message does not contain a subject name");
162 }
163 } else {
164 log.info("message does not contain a subject name");
165 }
166
167 log.debug("Exiting HL7Parser201305.ExtractPersonName method...");
168 return personname;
169 }
170
171 public static Identifiers ExtractPersonIdentifiers(
172 PRPAMT201306UVParameterList params) {
173 log.debug("Entering HL7Parser201305.ExtractPersonIdentifiers method...");
174
175 Identifiers ids = new Identifiers();
176 Identifier id = new Identifier();
177
178 if (params.getLivingSubjectId() != null &&
179 params.getLivingSubjectId().size() > 0 &&
180 params.getLivingSubjectId().get(0) != null) {
181 PRPAMT201306UVLivingSubjectId livingSubjectId = params.getLivingSubjectId().get(0);
182
183 if (livingSubjectId.getValue() != null &&
184 livingSubjectId.getValue().size() > 0 &&
185 livingSubjectId.getValue().get(0) != null) {
186 II subjectId = livingSubjectId.getValue().get(0);
187
188 if (subjectId.getExtension() != null &&
189 subjectId.getExtension().length() > 0 &&
190 subjectId.getRoot() != null &&
191 subjectId.getRoot().length() > 0) {
192 id.setId(subjectId.getExtension());
193 id.setOrganizationId(subjectId.getRoot());
194 log.info("Created id from patient identifier [organization=" + id.getOrganizationId() + "][id=" + id.getId() + "]");
195 ids.add(id);
196 } else {
197 log.info("message does not contain an id");
198 }
199 } else {
200 log.info("message does not contain an id");
201 }
202 } else {
203 log.info("message does not contain an id");
204 }
205
206 log.debug("Exiting HL7Parser201305.ExtractPersonIdentifiers method...");
207 return ids;
208 }
209
210 public static PRPAMT201306UVParameterList ExtractHL7QueryParamsFromMessage(
211 org.hl7.v3.PRPAIN201305UV message) {
212 log.debug("Entering HL7Parser201305.ExtractHL7QueryParamsFromMessage method...");
213 PRPAMT201306UVParameterList queryParamList = null;
214
215 if (message == null) {
216 log.warn("input message was null, no query parameters present in message");
217 return null;
218 }
219
220 PRPAIN201305UVQUQIMT021001UV01ControlActProcess controlActProcess = message.getControlActProcess();
221 if (controlActProcess == null) {
222 log.info("controlActProcess is null - no query parameters present in message");
223 return null;
224 }
225
226 if (controlActProcess.getQueryByParameter() != null &&
227 controlActProcess.getQueryByParameter().getValue() != null) {
228 PRPAMT201306UVQueryByParameter queryParams = (PRPAMT201306UVQueryByParameter) controlActProcess.getQueryByParameter().getValue();
229
230 if (queryParams.getParameterList() != null) {
231 queryParamList = queryParams.getParameterList();
232 }
233
234 }
235
236 log.debug("Exiting HL7Parser201305.ExtractHL7QueryParamsFromMessage method...");
237 return queryParamList;
238 }
239
240 public static Patient ExtractMpiPatientFromMessage(
241 org.hl7.v3.PRPAIN201305UV message) {
242 log.debug("Entering HL7Parser201305.ExtractMpiPatientFromMessage method...");
243
244 PRPAMT201306UVParameterList queryParamList = ExtractHL7QueryParamsFromMessage(message);
245 Patient mpipatient = ExtractMpiPatientFromQueryParams(queryParamList);
246
247 log.debug("Exiting HL7Parser201305.ExtractMpiPatientFromMessage method...");
248 return mpipatient;
249 }
250
251 public static Patient ExtractMpiPatientFromQueryParams(
252 PRPAMT201306UVParameterList params) {
253 log.debug("Entering HL7Parser201305.ExtractMpiPatientFromQueryParams method...");
254
255 Patient mpiPatient = new Patient();
256
257 if (params != null) {
258 mpiPatient.setName(ExtractPersonName(params));
259 mpiPatient.setGender(ExtractGender(params));
260
261 String birthdateString = ExtractBirthdate(params);
262 mpiPatient.setDateOfBirth(birthdateString);
263
264 Identifiers ids = ExtractPersonIdentifiers(params);
265 mpiPatient.setIdentifiers(ids);
266 } else {
267 mpiPatient = null;
268 }
269
270 log.debug("Exiting HL7Parser201305.ExtractMpiPatientFromQueryParams method...");
271 return mpiPatient;
272 }
273}
Note: See TracBrowser for help on using the repository browser.