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.audit;
|
---|
6 |
|
---|
7 | import org.apache.commons.logging.Log;
|
---|
8 | import org.apache.commons.logging.LogFactory;
|
---|
9 |
|
---|
10 | import com.services.nhinc.schema.auditmessage.AuditMessageType;
|
---|
11 | import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
|
---|
12 | import com.services.nhinc.schema.auditmessage.CodedValueType;
|
---|
13 | import com.services.nhinc.schema.auditmessage.EventIdentificationType;
|
---|
14 | import com.services.nhinc.schema.auditmessage.ParticipantObjectIdentificationType;
|
---|
15 |
|
---|
16 | import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
|
---|
17 |
|
---|
18 | import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType;
|
---|
19 |
|
---|
20 | import java.math.BigInteger;
|
---|
21 | import java.net.InetAddress;
|
---|
22 | import java.util.List;
|
---|
23 | import java.util.TimeZone;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | *
|
---|
27 | * @author MFLYNN02
|
---|
28 | */
|
---|
29 | public class AuditDataTransformHelper {
|
---|
30 |
|
---|
31 | private static Log log = LogFactory.getLog(AuditDataTransformHelper.class);
|
---|
32 |
|
---|
33 | public static EventIdentificationType createEventIdentification(String actionCode, Integer eventOutcome, CodedValueType eventId) {
|
---|
34 | EventIdentificationType eventIdentification = new EventIdentificationType();
|
---|
35 |
|
---|
36 | // Set the Event Action Code
|
---|
37 | eventIdentification.setEventActionCode(actionCode);
|
---|
38 |
|
---|
39 | // Set the Event Action Time
|
---|
40 | try {
|
---|
41 | java.util.GregorianCalendar today =
|
---|
42 | new java.util.GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
---|
43 | javax.xml.datatype.DatatypeFactory factory =
|
---|
44 | javax.xml.datatype.DatatypeFactory.newInstance();
|
---|
45 | javax.xml.datatype.XMLGregorianCalendar calendar =
|
---|
46 | factory.newXMLGregorianCalendar(
|
---|
47 | today.get(java.util.GregorianCalendar.YEAR),
|
---|
48 | today.get(java.util.GregorianCalendar.MONTH) + 1,
|
---|
49 | today.get(java.util.GregorianCalendar.DAY_OF_MONTH),
|
---|
50 | today.get(java.util.GregorianCalendar.HOUR_OF_DAY),
|
---|
51 | today.get(java.util.GregorianCalendar.MINUTE),
|
---|
52 | today.get(java.util.GregorianCalendar.SECOND),
|
---|
53 | today.get(java.util.GregorianCalendar.MILLISECOND),
|
---|
54 | 0);
|
---|
55 | eventIdentification.setEventDateTime(calendar);
|
---|
56 | } catch (Exception e) {
|
---|
57 | log.error("Exception when createing XMLGregorian Date");
|
---|
58 | log.error(" message: " + e.getMessage());
|
---|
59 | }
|
---|
60 | // TODO: Set the Event Outcome Indicator
|
---|
61 | eventIdentification.setEventOutcomeIndicator(BigInteger.ZERO);
|
---|
62 |
|
---|
63 | // Set the Event Id
|
---|
64 | eventIdentification.setEventID(eventId);
|
---|
65 |
|
---|
66 | return eventIdentification;
|
---|
67 | }
|
---|
68 |
|
---|
69 | public static CodedValueType createEventId(String eventCode, String eventCodeSys, String eventCodeSysName, String dispName) {
|
---|
70 | CodedValueType eventId = new CodedValueType();
|
---|
71 |
|
---|
72 | // Set the Event Id Code
|
---|
73 | eventId.setCode(eventCode);
|
---|
74 |
|
---|
75 | // Set the Event Id Codesystem
|
---|
76 | eventId.setCodeSystem(eventCodeSys);
|
---|
77 |
|
---|
78 | // Set the Event Id Codesystem Name
|
---|
79 | eventId.setCodeSystemName(eventCodeSysName);
|
---|
80 |
|
---|
81 | // Set the Event Id Display Name
|
---|
82 | eventId.setDisplayName(dispName);
|
---|
83 |
|
---|
84 | return eventId;
|
---|
85 | }
|
---|
86 |
|
---|
87 | public static AuditMessageType.ActiveParticipant createActiveParticipantFromUser(UserType userInfo, Boolean userIsReq) {
|
---|
88 | AuditMessageType.ActiveParticipant participant = new AuditMessageType.ActiveParticipant();
|
---|
89 | String ipAddr = null;
|
---|
90 |
|
---|
91 | try {
|
---|
92 | ipAddr = InetAddress.getLocalHost().getHostAddress();
|
---|
93 | } catch (Exception ex) {
|
---|
94 | ex.printStackTrace();
|
---|
95 | throw new RuntimeException();
|
---|
96 | }
|
---|
97 |
|
---|
98 | // Set the User Id
|
---|
99 | String userId = null;
|
---|
100 | if (userInfo != null &&
|
---|
101 | userInfo.getUserName() != null &&
|
---|
102 | userInfo.getUserName().length() > 0) {
|
---|
103 | userId = userInfo.getUserName();
|
---|
104 | }
|
---|
105 |
|
---|
106 | if (userId != null) {
|
---|
107 | participant.setUserID(userId);
|
---|
108 | }
|
---|
109 |
|
---|
110 | // If specified, set the User Name
|
---|
111 | String userName = null;
|
---|
112 | if (userInfo != null &&
|
---|
113 | userInfo.getPersonName() != null) {
|
---|
114 | if (userInfo.getPersonName().getGivenName() != null &&
|
---|
115 | userInfo.getPersonName().getGivenName().length() > 0) {
|
---|
116 | userName = userInfo.getPersonName().getGivenName();
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (userInfo.getPersonName().getFamilyName() != null &&
|
---|
120 | userInfo.getPersonName().getFamilyName().length() > 0) {
|
---|
121 | if (userName != null) {
|
---|
122 | userName += (" " + userInfo.getPersonName().getFamilyName());
|
---|
123 | } else {
|
---|
124 | userName = userInfo.getPersonName().getFamilyName();
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 | if (userName != null) {
|
---|
129 | participant.setUserName(userName);
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Set the UserIsRequester Flag
|
---|
133 | participant.setUserIsRequestor(userIsReq);
|
---|
134 |
|
---|
135 | // Set the Network Access Point Id to the IP Address of the machine
|
---|
136 | participant.setNetworkAccessPointID(ipAddr);
|
---|
137 |
|
---|
138 | // Set the Network Access Point Typecode
|
---|
139 | participant.setNetworkAccessPointTypeCode(AuditDataTransformConstants.NETWORK_ACCESSOR_PT_TYPE_CODE_IP);
|
---|
140 |
|
---|
141 | return participant;
|
---|
142 | }
|
---|
143 |
|
---|
144 | public static AuditMessageType.ActiveParticipant createActiveParticipant(String userId, String altUserId, String userName, Boolean userIsReq) {
|
---|
145 | AuditMessageType.ActiveParticipant participant = new AuditMessageType.ActiveParticipant();
|
---|
146 | String ipAddr = null;
|
---|
147 |
|
---|
148 | try {
|
---|
149 | ipAddr = InetAddress.getLocalHost().getHostAddress();
|
---|
150 | } catch (Exception ex) {
|
---|
151 | ex.printStackTrace();
|
---|
152 | throw new RuntimeException();
|
---|
153 | }
|
---|
154 |
|
---|
155 | // Set the User Id
|
---|
156 | if (userId != null) {
|
---|
157 | participant.setUserID(userId);
|
---|
158 | }
|
---|
159 |
|
---|
160 | // If specified, set the Alternative User Id
|
---|
161 | if (altUserId != null) {
|
---|
162 | participant.setAlternativeUserID(altUserId);
|
---|
163 | }
|
---|
164 |
|
---|
165 | // If specified, set the User Name
|
---|
166 | if (userName != null) {
|
---|
167 | participant.setUserName(userName);
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Set the UserIsRequester Flag
|
---|
171 | participant.setUserIsRequestor(userIsReq);
|
---|
172 |
|
---|
173 | // Set the Network Access Point Id to the IP Address of the machine
|
---|
174 | participant.setNetworkAccessPointID(ipAddr);
|
---|
175 |
|
---|
176 | // Set the Network Access Point Typecode
|
---|
177 | participant.setNetworkAccessPointTypeCode(AuditDataTransformConstants.NETWORK_ACCESSOR_PT_TYPE_CODE_IP);
|
---|
178 |
|
---|
179 | return participant;
|
---|
180 | }
|
---|
181 |
|
---|
182 | public static AuditSourceIdentificationType createAuditSourceIdentificationFromUser(UserType userInfo) {
|
---|
183 | AuditSourceIdentificationType auditSrcId = new AuditSourceIdentificationType();
|
---|
184 |
|
---|
185 | // Home Community ID and name
|
---|
186 | String communityId = null;
|
---|
187 | String communityName = null;
|
---|
188 |
|
---|
189 | if (userInfo != null &&
|
---|
190 | userInfo.getOrg() != null) {
|
---|
191 | if (userInfo.getOrg().getHomeCommunityId() != null &&
|
---|
192 | userInfo.getOrg().getHomeCommunityId().length() > 0) {
|
---|
193 | communityId = userInfo.getOrg().getHomeCommunityId();
|
---|
194 | }
|
---|
195 |
|
---|
196 | if (userInfo.getOrg().getName() != null &&
|
---|
197 | userInfo.getOrg().getName().length() > 0) {
|
---|
198 | communityName = userInfo.getOrg().getName();
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | // Set the Audit Source Id (community id)
|
---|
203 | if (communityId != null) {
|
---|
204 | log.debug("communityId prior to remove urn:oid" + communityId);
|
---|
205 | if (communityId.startsWith("urn:oid:")) {
|
---|
206 | auditSrcId.setAuditSourceID(communityId.substring(8));
|
---|
207 | } else {
|
---|
208 | auditSrcId.setAuditSourceID(communityId);
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | // If specified, set the Audit Enterprise Site Id (community name)
|
---|
213 | if (communityName != null) {
|
---|
214 | auditSrcId.setAuditEnterpriseSiteID(communityName);
|
---|
215 | }
|
---|
216 |
|
---|
217 | return auditSrcId;
|
---|
218 | }
|
---|
219 |
|
---|
220 | public static AuditSourceIdentificationType createAuditSourceIdentification(String communityId, String communityName) {
|
---|
221 | AuditSourceIdentificationType auditSrcId = new AuditSourceIdentificationType();
|
---|
222 |
|
---|
223 | // Set the Audit Source Id (community id)
|
---|
224 | if (communityId != null) {
|
---|
225 | if (communityId.startsWith("urn:oid:")) {
|
---|
226 | auditSrcId.setAuditSourceID(communityId.substring(8));
|
---|
227 | } else {
|
---|
228 | auditSrcId.setAuditSourceID(communityId);
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | // If specified, set the Audit Enterprise Site Id (community name)
|
---|
233 | if (communityName != null) {
|
---|
234 | auditSrcId.setAuditEnterpriseSiteID(communityName);
|
---|
235 | }
|
---|
236 |
|
---|
237 | return auditSrcId;
|
---|
238 | }
|
---|
239 |
|
---|
240 | public static ParticipantObjectIdentificationType createParticipantObjectIdentification(String patientId) {
|
---|
241 | ParticipantObjectIdentificationType partObjId = new ParticipantObjectIdentificationType();
|
---|
242 |
|
---|
243 | // Set the Partipation Object Id (patient id)
|
---|
244 | if (patientId != null) {
|
---|
245 | partObjId.setParticipantObjectID(patientId);
|
---|
246 | }
|
---|
247 |
|
---|
248 | // Set the Participation Object Typecode
|
---|
249 | partObjId.setParticipantObjectTypeCode(AuditDataTransformConstants.PARTICIPANT_OJB_TYPE_CODE_PERSON);
|
---|
250 |
|
---|
251 | // Set the Participation Object Typecode Role
|
---|
252 | partObjId.setParticipantObjectTypeCodeRole(AuditDataTransformConstants.PARTICIPANT_OJB_TYPE_CODE_ROLE_PATIENT);
|
---|
253 |
|
---|
254 | // Set the Participation Object Id Type code
|
---|
255 | CodedValueType partObjIdTypeCode = new CodedValueType();
|
---|
256 | partObjIdTypeCode.setCode(AuditDataTransformConstants.PARTICIPANT_OJB_ID_TYPE_CODE_PATIENTNUM);
|
---|
257 | partObjId.setParticipantObjectIDTypeCode(partObjIdTypeCode);
|
---|
258 |
|
---|
259 | return partObjId;
|
---|
260 | }
|
---|
261 |
|
---|
262 | public static void logAuditMessage(AuditMessageType message) {
|
---|
263 | log.debug("********** Audit Log Message ***********");
|
---|
264 | log.debug("EventIdCode: " + message.getEventIdentification().getEventID().getCode());
|
---|
265 | log.debug("EventIdCodeSystem: " + message.getEventIdentification().getEventID().getCodeSystem());
|
---|
266 |
|
---|
267 | if (message.getAuditSourceIdentification() != null &&
|
---|
268 | message.getAuditSourceIdentification().size() > 0 &&
|
---|
269 | message.getAuditSourceIdentification().get(0).getAuditSourceID() != null) {
|
---|
270 | log.debug("Home Community Id: " + message.getAuditSourceIdentification().get(0).getAuditSourceID());
|
---|
271 | } else {
|
---|
272 | log.debug("Home Community Id: There was no AuditSourceID in the message");
|
---|
273 | }
|
---|
274 |
|
---|
275 | if (message.getActiveParticipant() != null &&
|
---|
276 | message.getActiveParticipant().size() > 0) {
|
---|
277 | if (message.getActiveParticipant().get(0).getUserID() != null) {
|
---|
278 | log.debug("UserId: " + message.getActiveParticipant().get(0).getUserID());
|
---|
279 | } else {
|
---|
280 | log.debug("UserId: There was no User Id in the message");
|
---|
281 | }
|
---|
282 |
|
---|
283 | if (message.getActiveParticipant().get(0).getUserName() != null) {
|
---|
284 | log.debug("UserName: " + message.getActiveParticipant().get(0).getUserName());
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | if (message.getParticipantObjectIdentification() != null &&
|
---|
289 | message.getParticipantObjectIdentification().size() > 0 &&
|
---|
290 | message.getParticipantObjectIdentification().get(0).getParticipantObjectID() != null) {
|
---|
291 | log.debug("PatientId: " + message.getParticipantObjectIdentification().get(0).getParticipantObjectID());
|
---|
292 | } else {
|
---|
293 | log.debug("PatientId: There was no Patient Id in the message");
|
---|
294 | }
|
---|
295 | }
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * This method locates the single ExternalIdentifer object based on the given Identification Scheme.
|
---|
299 | *
|
---|
300 | * @param olExtId The list of external identifier objects to be searched.
|
---|
301 | * @param sIdentScheme The identification scheme for the item being looked for.
|
---|
302 | * @return The ExternalIdentifierType matching the search criteria.
|
---|
303 | */
|
---|
304 | public static ExternalIdentifierType findSingleExternalIdentifier(List<ExternalIdentifierType> olExtId, String sIdentScheme) {
|
---|
305 | ExternalIdentifierType oExtId = null;
|
---|
306 |
|
---|
307 | if ((olExtId != null) &&
|
---|
308 | (olExtId.size() > 0)) {
|
---|
309 | for (int i = 0; i < olExtId.size(); i++) {
|
---|
310 | if (olExtId.get(i).getIdentificationScheme().equals(sIdentScheme)) {
|
---|
311 | oExtId = olExtId.get(i);
|
---|
312 | break; // We found what we were looking for - get out of here...
|
---|
313 | }
|
---|
314 | }
|
---|
315 | }
|
---|
316 | return oExtId;
|
---|
317 | }
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * This method locates a single External Identifier by its Identification scheme and then extracts the
|
---|
321 | * value from it.
|
---|
322 | *
|
---|
323 | * @param olExtId The List of external identifiers to be searched.
|
---|
324 | * @param sIdentScheme The identification scheme to look for.
|
---|
325 | * @return The value from the specified identification scheme.
|
---|
326 | */
|
---|
327 | public static String findSingleExternalIdentifierAndExtractValue(List<ExternalIdentifierType> olExtId, String sIdentScheme) {
|
---|
328 | String sValue = null;
|
---|
329 | ExternalIdentifierType oExtId = findSingleExternalIdentifier(olExtId, sIdentScheme);
|
---|
330 | if ((oExtId != null) &&
|
---|
331 | (oExtId.getValue() != null)) {
|
---|
332 | sValue = oExtId.getValue();
|
---|
333 | }
|
---|
334 | return sValue;
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * This method creates a patient id formatted as 'patientid^^^^&communityId&ISO'
|
---|
339 | *
|
---|
340 | * @param communityId the communityId for the patient identifier
|
---|
341 | * @param patientId the patientId for the patient
|
---|
342 | * @return the properly formatted patientId.
|
---|
343 | */
|
---|
344 | public static String createCompositePatientId(String communityId, String patientId) {
|
---|
345 | String sValue = null;
|
---|
346 | sValue = patientId + "^^^&" + communityId + "&ISO";
|
---|
347 | return sValue;
|
---|
348 | }
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * This method creates a patient id formatted as 'patientid^^^^&communityId&ISO'
|
---|
352 | *
|
---|
353 | * @param assertion. Fields of interest are UserInfo.org.homeCommunityId an uniquePatientId
|
---|
354 | * @return the properly formatted patientId.
|
---|
355 | */
|
---|
356 | public static String createCompositePatientIdFromAssertion(UserType userInfo, String patientId) {
|
---|
357 | String communityId = null;
|
---|
358 | String compPatientId = null;
|
---|
359 |
|
---|
360 | if (userInfo != null &&
|
---|
361 | userInfo.getOrg() != null &&
|
---|
362 | userInfo.getOrg().getHomeCommunityId() != null) {
|
---|
363 | communityId = userInfo.getOrg().getHomeCommunityId();
|
---|
364 | }
|
---|
365 | compPatientId = AuditDataTransformHelper.createCompositePatientId(communityId, patientId);
|
---|
366 |
|
---|
367 |
|
---|
368 | return compPatientId;
|
---|
369 | }
|
---|
370 | }
|
---|