1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.core.atna.custom;
17
18 import org.openhealthtools.ihe.atna.auditor.IHEAuditor;
19 import org.openhealthtools.ihe.atna.auditor.codes.ihe.IHETransactionEventTypeCodes;
20 import org.openhealthtools.ihe.atna.auditor.codes.rfc3881.RFC3881EventCodes;
21 import org.openhealthtools.ihe.atna.auditor.context.AuditorModuleContext;
22 import org.openhealthtools.ihe.atna.auditor.events.ihe.GenericIHEAuditEventMessage;
23 import org.openhealthtools.ihe.atna.auditor.events.ihe.PatientRecordEvent;
24 import org.openhealthtools.ihe.atna.auditor.events.ihe.QueryEvent;
25 import org.openhealthtools.ihe.atna.auditor.models.rfc3881.CodedValueType;
26 import org.openhealthtools.ihe.atna.auditor.models.rfc3881.ParticipantObjectIdentificationType;
27 import org.openhealthtools.ihe.atna.auditor.models.rfc3881.TypeValuePairType;
28 import org.openhealthtools.ihe.atna.auditor.utils.EventUtils;
29
30 import java.io.UnsupportedEncodingException;
31 import java.nio.charset.Charset;
32 import java.util.List;
33
34 import static org.openehealth.ipf.commons.ihe.core.atna.custom.CustomAuditorUtils.configureEvent;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class Hl7v3Auditor extends IHEAuditor {
52
53 public static Hl7v3Auditor getAuditor() {
54 AuditorModuleContext ctx = AuditorModuleContext.getContext();
55 return (Hl7v3Auditor) ctx.getAuditor(Hl7v3Auditor.class);
56 }
57
58
59 private void auditIti44(
60 boolean serverSide,
61 RFC3881EventCodes.RFC3881EventActionCodes eventActionCode,
62 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
63 String replyToUri,
64 String userName,
65 String pixManagerUri,
66 String clientIpAddress,
67 String[] patientIds,
68 String messageId,
69 List<CodedValueType> purposesOfUse,
70 List<CodedValueType> userRoles)
71 {
72 if (! isAuditorEnabled()) {
73 return;
74 }
75
76 PatientRecordEvent event = new PatientRecordEvent(
77 true,
78 eventOutcome,
79 eventActionCode,
80 new IHETransactionEventTypeCodes.PatientIdentityFeedV3(),
81 purposesOfUse);
82
83 configureEvent(this, serverSide, event, replyToUri, userName, pixManagerUri,
84 pixManagerUri, clientIpAddress, userRoles);
85 addPatientParticipantObjects(event, patientIds, messageId);
86 audit(event);
87 }
88
89
90 public void auditIti44Add(
91 boolean serverSide,
92 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
93 String replyToUri,
94 String userName,
95 String pixManagerUri,
96 String clientIpAddress,
97 String[] patientIds,
98 String messageId,
99 List<CodedValueType> purposesOfUse,
100 List<CodedValueType> userRoles)
101 {
102 auditIti44(serverSide, RFC3881EventCodes.RFC3881EventActionCodes.CREATE,
103 eventOutcome, replyToUri, userName, pixManagerUri, clientIpAddress,
104 patientIds, messageId, purposesOfUse, userRoles);
105 }
106
107
108 public void auditIti44Revise(
109 boolean serverSide,
110 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
111 String replyToUri,
112 String userName,
113 String pixManagerUri,
114 String clientIpAddress,
115 String[] patientIds,
116 String messageId,
117 List<CodedValueType> purposesOfUse,
118 List<CodedValueType> userRoles)
119 {
120 auditIti44(serverSide, RFC3881EventCodes.RFC3881EventActionCodes.UPDATE,
121 eventOutcome, replyToUri, userName, pixManagerUri, clientIpAddress,
122 patientIds, messageId, purposesOfUse, userRoles);
123 }
124
125
126 public void auditIti44Delete(
127 boolean serverSide,
128 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
129 String replyToUri,
130 String userName,
131 String pixManagerUri,
132 String clientIpAddress,
133 String oldPatientId,
134 String messageId,
135 List<CodedValueType> purposesOfUse,
136 List<CodedValueType> userRoles)
137 {
138 String[] patientIds = new String[] { oldPatientId };
139 auditIti44(serverSide, RFC3881EventCodes.RFC3881EventActionCodes.DELETE,
140 eventOutcome, replyToUri, userName, pixManagerUri, clientIpAddress,
141 patientIds, messageId, purposesOfUse, userRoles);
142 }
143
144
145 public void auditIti45(
146 boolean serverSide,
147 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
148 String replyToUri,
149 String userName,
150 String pixManagerUri,
151 String clientIpAddress,
152 String queryPayload,
153 String[] patientIds,
154 List<CodedValueType> purposesOfUse,
155 List<CodedValueType> userRoles)
156 {
157 if (! isAuditorEnabled()) {
158 return;
159 }
160
161 QueryEvent event = new QueryEvent(
162 true,
163 eventOutcome,
164 new IHETransactionEventTypeCodes.PIXQueryV3(),
165 purposesOfUse);
166
167 configureEvent(this, serverSide, event, replyToUri, userName, pixManagerUri,
168 pixManagerUri, clientIpAddress, userRoles);
169 addPatientParticipantObjects(event, patientIds, null);
170 event.addQueryParticipantObject(null, null, payloadBytes(queryPayload), null,
171 new IHETransactionEventTypeCodes.PIXQueryV3());
172 audit(event);
173 }
174
175
176 public void auditIti46(
177 boolean serverSide,
178 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
179 String replyToUri,
180 String userName,
181 String pixManagerUri,
182 String clientIpAddress,
183 String[] patientIds,
184 String messageId,
185 List<CodedValueType> purposesOfUse,
186 List<CodedValueType> userRoles)
187 {
188 if (! isAuditorEnabled()) {
189 return;
190 }
191
192 PatientRecordEvent event = new PatientRecordEvent(
193 true,
194 eventOutcome,
195 RFC3881EventCodes.RFC3881EventActionCodes.READ,
196 new IHETransactionEventTypeCodes.PIXUpdateNotificationV3(),
197 purposesOfUse);
198
199 configureEvent(this, serverSide, event, replyToUri, userName, pixManagerUri,
200 pixManagerUri, clientIpAddress, userRoles);
201 addPatientParticipantObjects(event, patientIds, messageId);
202 audit(event);
203 }
204
205
206 public void auditIti47(
207 boolean serverSide,
208 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
209 String replyToUri,
210 String userName,
211 String pdSupplierUri,
212 String clientIpAddress,
213 String queryPayload,
214 String[] patientIds,
215 List<CodedValueType> purposesOfUse,
216 List<CodedValueType> userRoles)
217 {
218 if (! isAuditorEnabled()) {
219 return;
220 }
221
222
223 QueryEvent event = new QueryEvent(
224 true,
225 eventOutcome,
226 new IHETransactionEventTypeCodes.PatientDemographicsQueryV3(),
227 purposesOfUse);
228
229 configureEvent(this, serverSide, event, replyToUri, userName, pdSupplierUri,
230 pdSupplierUri, clientIpAddress, userRoles);
231 addPatientParticipantObjects(event, patientIds, null);
232 event.addQueryParticipantObject(null, null, payloadBytes(queryPayload), null,
233 new IHETransactionEventTypeCodes.PatientDemographicsQueryV3());
234 audit(event);
235 }
236
237
238 public void auditIti55(
239 boolean serverSide,
240 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
241 String replyToUri,
242 String userName,
243 String respondingGatewayUri,
244 String clientIpAddress,
245 String queryPayload,
246 String queryId,
247 String homeCommunityId,
248 String[] patientIds,
249 List<CodedValueType> purposesOfUses,
250 List<CodedValueType> userRoles)
251 {
252 if (! isAuditorEnabled()) {
253 return;
254 }
255
256 QueryEvent event = new QueryEvent(
257 true,
258 eventOutcome,
259 new IHETransactionEventTypeCodes.CrossGatewayPatientDiscovery(),
260 purposesOfUses);
261
262 configureEvent(this, serverSide, event, replyToUri, userName, respondingGatewayUri,
263 respondingGatewayUri, clientIpAddress, userRoles);
264 addPatientParticipantObjects(event, patientIds, null);
265 event.addQueryParticipantObject(
266 queryId,
267 homeCommunityId,
268 payloadBytes(queryPayload),
269 null,
270 new IHETransactionEventTypeCodes.CrossGatewayPatientDiscovery());
271 audit(event);
272 }
273
274
275 public void auditIti56(
276 boolean serverSide,
277 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
278 String replyToUri,
279 String userName,
280 String respondingGatewayUri,
281 String clientIpAddress,
282 String queryPayload,
283 String patientId,
284 List<CodedValueType> purposesOfUse,
285 List<CodedValueType> userRoles)
286 {
287 if (! isAuditorEnabled()) {
288 return;
289 }
290
291 Iti56QueryEvent event = new Iti56QueryEvent(
292 true,
293 eventOutcome,
294 new CustomIHETransactionEventTypeCodes.PatientLocationQuery(),
295 purposesOfUse);
296
297 configureEvent(this, serverSide, event, replyToUri, userName, respondingGatewayUri,
298 respondingGatewayUri, clientIpAddress, userRoles);
299 event.addPatientParticipantObject(patientId);
300 event.addQueryParametersObject(queryPayload);
301 audit(event);
302 }
303
304
305 public void auditPcc1(
306 boolean serverSide,
307 RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
308 String replyToUri,
309 String userName,
310 String clinicalDataSourceUri,
311 String clientIpAddress,
312 String queryPayload,
313 String queryId,
314 String[] patientIds,
315 List<CodedValueType> purposesOfUse,
316 List<CodedValueType> userRoles)
317 {
318 if (! isAuditorEnabled()) {
319 return;
320 }
321
322 QueryEvent event = new QueryEvent(
323 true,
324 eventOutcome,
325 new CustomIHETransactionEventTypeCodes.QueryExistingData(),
326 purposesOfUse);
327
328 configureEvent(this, serverSide, event, replyToUri, userName, clinicalDataSourceUri,
329 clinicalDataSourceUri, clientIpAddress, userRoles);
330 addPatientParticipantObjects(event, patientIds, null);
331 event.addQedParticipantObject(queryId, payloadBytes(queryPayload));
332 audit(event);
333 }
334
335
336 protected static byte[] payloadBytes(String payload) {
337 if (payload == null) {
338 return null;
339 }
340 try {
341 return payload.getBytes("UTF-8");
342 } catch (UnsupportedEncodingException e) {
343 return payload.getBytes(Charset.defaultCharset());
344 }
345 }
346
347
348 protected static void addPatientParticipantObjects(
349 GenericIHEAuditEventMessage event,
350 String[] patientIds,
351 String messageId)
352 {
353 if (! EventUtils.isEmptyOrNull(patientIds)) {
354 for (String patientId : patientIds) {
355 event.addPatientParticipantObject(patientId);
356 }
357
358 if (messageId != null) {
359 TypeValuePairType tvp = new TypeValuePairType();
360 tvp.setType("II");
361 tvp.setValue(payloadBytes(messageId));
362 for (ParticipantObjectIdentificationType type : event.getAuditMessage().getParticipantObjectIdentification()) {
363 type.getParticipantObjectDetail().add(tvp);
364 }
365 }
366 }
367 }
368
369
370 }