View Javadoc
1   /*
2    * Copyright 2017 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.audit.event;
17  
18  
19  import org.openehealth.ipf.commons.audit.AuditException;
20  import org.openehealth.ipf.commons.audit.codes.*;
21  import org.openehealth.ipf.commons.audit.types.EventType;
22  import org.openehealth.ipf.commons.audit.types.MediaType;
23  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
24  
25  import java.util.Collections;
26  
27  import static java.util.Objects.requireNonNull;
28  
29  /**
30   * Builds an Audit Event representing a Data Export event as specified in
31   * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.4
32   * <p>
33   * This message describes the event of exporting data from a system, meaning that the data
34   * is leaving control of the system's security domain. Examples of exporting include printing to paper,
35   * recording on film, conversion to another format for storage in an EHR, writing to removable media,
36   * or sending via e-mail. Multiple patients may be described in one event message.
37   * </p>
38   *
39   * @author Christian Ohr
40   * @since 3.5
41   */
42  public class DataExportBuilder extends BaseAuditMessageBuilder<DataExportBuilder> {
43  
44      public DataExportBuilder(EventOutcomeIndicator outcome,
45                               EventType eventType,
46                               PurposeOfUse... purposesOfUse) {
47          this(outcome, null, eventType, purposesOfUse);
48      }
49  
50      public DataExportBuilder(EventOutcomeIndicator outcome,
51                               String eventOutcomeDescription,
52                               EventType eventType,
53                               PurposeOfUse... purposesOfUse) {
54          this(outcome, eventOutcomeDescription, EventActionCode.Read, eventType, purposesOfUse);
55      }
56  
57      public DataExportBuilder(EventOutcomeIndicator outcome,
58                               String eventOutcomeDescription,
59                               EventActionCode eventActionCode,
60                               EventType eventType,
61                               PurposeOfUse... purposesOfUse) {
62          super();
63          setEventIdentification(outcome,
64                  eventOutcomeDescription,
65                  eventActionCode,
66                  EventIdCode.Export,
67                  eventType,
68                  purposesOfUse
69          );
70      }
71  
72      /**
73       * @param userId               The identity of the remote user or process receiving the data
74       * @param altUserId            Alternate UserID
75       * @param userName             UserName
76       * @param networkAccessPointId Network Access Point ID
77       * @param userIsRequestor      A single user (either local or remote) shall be identified as the requestor, i.e.,
78       *                             UserIsRequestor with a value of TRUE. This accommodates both push and pull transfer models for media
79       * @return this
80       */
81      public DataExportBuilder addReceivingParticipant(String userId,
82                                                       String altUserId,
83                                                       String userName,
84                                                       String networkAccessPointId,
85                                                       boolean userIsRequestor) {
86          return addDestinationActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
87      }
88  
89      /**
90       * @param userId               The identity of the local user or process exporting the data. If both are known,
91       *                             then two active participants shall be included (both the person and the process).
92       * @param altUserId            Alternate UserID
93       * @param userName             UserName
94       * @param networkAccessPointId Network Access Point ID
95       * @param userIsRequestor      A single user (either local or remote) shall be identified as the requestor, i.e.,
96       *                             UserIsRequestor with a value of TRUE. This accommodates both push and pull transfer models for media
97       * @return this
98       */
99      public DataExportBuilder addExportingParticipant(String userId,
100                                                      String altUserId,
101                                                      String userName,
102                                                      String networkAccessPointId,
103                                                      boolean userIsRequestor) {
104         return addSourceActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
105     }
106 
107     /**
108      * @param userId               UserID
109      * @param altUserId            Alternate UserID
110      * @param userName             UserName
111      * @param networkAccessPointId Network Access Point ID
112      * @param mediaIdentifier      Media Identifier
113      * @param mediaType            Media Type
114      * @return this
115      */
116     public DataExportBuilder setDestinationMediaParticipant(String userId, String altUserId, String userName,
117                                                             String networkAccessPointId,
118                                                             NetworkAccessPointTypeCode networkAccessPointTypeCode,
119                                                             String mediaIdentifier,
120                                                             MediaType mediaType) {
121         return addActiveParticipant(
122                 userId,
123                 altUserId,
124                 userName,
125                 false,
126                 Collections.singletonList(ActiveParticipantRoleIdCode.DestinationMedia),
127                 networkAccessPointId,
128                 networkAccessPointTypeCode,
129                 mediaIdentifier,
130                 requireNonNull(mediaType));
131     }
132 
133     @Override
134     public void validate() {
135         super.validate();
136         int sources = getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Source)).size();
137         if (sources < 1 || sources > 2) {
138             throw new AuditException("Must have one or two ActiveParticipant with RoleIDCode Source");
139         }
140         if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.DestinationMedia)).size() != 1) {
141             throw new AuditException("Must have one ActiveParticipant with RoleIDCode DestinationMedia");
142         }
143         if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.PatientNumber).isEmpty()) {
144             throw new AuditException("Must one or more ParticipantObjectIdentification with ParticipantObjectIDTypeCode PatientNumber");
145         }
146     }
147 }