View Javadoc
1   /*
2    * Copyright 2011 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.rfc3881.RFC3881EventCodes;
20  import org.openhealthtools.ihe.atna.auditor.context.AuditorModuleContext;
21  import org.openhealthtools.ihe.atna.auditor.events.ihe.ImportEvent;
22  import org.openhealthtools.ihe.atna.auditor.events.ihe.QueryEvent;
23  import org.openhealthtools.ihe.atna.auditor.utils.EventUtils;
24  
25  import java.io.UnsupportedEncodingException;
26  import java.nio.charset.Charset;
27  import java.util.Collection;
28  import java.util.Collections;
29  
30  import static org.openehealth.ipf.commons.ihe.core.atna.custom.CustomAuditorUtils.configureEvent;
31  
32  /**
33   * Implementation of Fhir Auditors to send audit messages for
34   * <ul>
35   * <li>ITI-65, ITI-66, ITI67 (MHD)</li>
36   * <li>ITI-78 (PDQM Query)</li>
37   * <li>ITI-83 (PIXM Query)</li>
38   * </ul>
39   *
40   * @author Christian Ohr
41   * @since 3.1
42   * @deprecated
43   */
44  public class FhirAuditor extends IHEAuditor {
45  
46      public static FhirAuditor getAuditor() {
47          AuditorModuleContext ctx = AuditorModuleContext.getContext();
48          return (FhirAuditor) ctx.getAuditor(FhirAuditor.class);
49      }
50  
51      public void auditIti65(
52              boolean serverSide,
53              RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
54              String documentResponderUri,
55              String clientIpAddress,
56              String patientId,
57              String manifestId) {
58          if (!isAuditorEnabled()) {
59              return;
60          }
61          ImportEvent importEvent = new ImportEvent(false, eventOutcome, new CustomIHETransactionEventTypeCodes.ProvideDocumentBundle(), null);
62          configureEvent(this, serverSide, importEvent, null, null, documentResponderUri, documentResponderUri, clientIpAddress, null);
63  
64          if (!EventUtils.isEmptyOrNull(patientId)) {
65              importEvent.addPatientParticipantObject(patientId);
66          }
67  
68          importEvent.addSubmissionSetParticipantObject(manifestId);
69  
70          audit(importEvent);
71      }
72  
73      public void auditIti66(
74              boolean serverSide,
75              RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
76              String documentResponderUri,
77              String clientIpAddress,
78              String queryString,
79              Collection<String> patientIds) {
80          if (!isAuditorEnabled()) {
81              return;
82          }
83  
84          QueryEvent event = new QueryEvent(
85                  true,
86                  eventOutcome,
87                  new CustomIHETransactionEventTypeCodes.DocumentManifestQuery(),
88                  Collections.emptyList());
89  
90          configureEvent(this, serverSide, event, null, null, documentResponderUri, documentResponderUri, clientIpAddress, null);
91          if (!EventUtils.isEmptyOrNull(patientIds)) {
92              patientIds.forEach(event::addPatientParticipantObject);
93          }
94          event.addQueryParticipantObject("MobileDocumentManifestQuery", null, payloadBytes(queryString), null,
95                  new CustomIHETransactionEventTypeCodes.DocumentManifestQuery());
96  
97          audit(event);
98      }
99  
100     public void auditIti67(
101             boolean serverSide,
102             RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
103             String documentResponderUri,
104             String clientIpAddress,
105             String queryString,
106             Collection<String> patientIds) {
107         if (!isAuditorEnabled()) {
108             return;
109         }
110 
111         QueryEvent event = new QueryEvent(
112                 true,
113                 eventOutcome,
114                 new CustomIHETransactionEventTypeCodes.DocumentReferenceQuery(),
115                 Collections.emptyList());
116 
117         configureEvent(this, serverSide, event, null, null, documentResponderUri, documentResponderUri, clientIpAddress, null);
118         if (!EventUtils.isEmptyOrNull(patientIds)) {
119             patientIds.forEach(event::addPatientParticipantObject);
120         }
121         event.addQueryParticipantObject("MobileDocumentReferenceQuery", null, payloadBytes(queryString), null,
122                 new CustomIHETransactionEventTypeCodes.DocumentReferenceQuery());
123 
124         audit(event);
125     }
126 
127     public void auditIti78(
128             boolean serverSide,
129             RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
130             String pdqSupplierUri,
131             String clientIpAddress,
132             String queryString,
133             Collection<String> patientIds) {
134         if (!isAuditorEnabled()) {
135             return;
136         }
137 
138         QueryEvent event = new QueryEvent(
139                 true,
140                 eventOutcome,
141                 new CustomIHETransactionEventTypeCodes.PDQMQuery(),
142                 Collections.emptyList());
143 
144         configureEvent(this, serverSide, event, null, null, pdqSupplierUri, pdqSupplierUri, clientIpAddress, null);
145         if (!EventUtils.isEmptyOrNull(patientIds)) {
146             patientIds.forEach(event::addPatientParticipantObject);
147         }
148         event.addQueryParticipantObject("MobilePatientDemographicsQuery", null, payloadBytes(queryString), null,
149                 new CustomIHETransactionEventTypeCodes.PDQMQuery());
150         audit(event);
151     }
152 
153     public void auditIti83(
154             boolean serverSide,
155             RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
156             String pixManagerUri,
157             String clientIpAddress,
158             String queryString,
159             Collection<String> patientIds) {
160         if (!isAuditorEnabled()) {
161             return;
162         }
163 
164         QueryEvent event = new QueryEvent(
165                 true,
166                 eventOutcome,
167                 new CustomIHETransactionEventTypeCodes.PIXMQuery(),
168                 Collections.emptyList());
169 
170         configureEvent(this, serverSide, event, null, null, pixManagerUri, pixManagerUri, clientIpAddress, null);
171         if (!EventUtils.isEmptyOrNull(patientIds)) {
172             patientIds.forEach(event::addPatientParticipantObject);
173         }
174         event.addQueryParticipantObject("PIXmQuery", null, payloadBytes(queryString), null,
175                 new CustomIHETransactionEventTypeCodes.PIXMQuery());
176         audit(event);
177     }
178 
179 
180     protected static byte[] payloadBytes(String payload) {
181         if (payload == null) {
182             return null;
183         }
184         try {
185             return payload.getBytes("UTF-8");
186         } catch (UnsupportedEncodingException e) {
187             return payload.getBytes(Charset.defaultCharset());
188         }
189     }
190 
191 
192 }