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 DataImportBuilder extends BaseAuditMessageBuilder<DataImportBuilder> {
43  
44      public DataImportBuilder(EventOutcomeIndicator outcome,
45                               EventType eventType,
46                               PurposeOfUse... purposesOfUse) {
47          this(outcome, null, eventType, purposesOfUse);
48      }
49  
50      public DataImportBuilder(EventOutcomeIndicator outcome,
51                               String eventOutcomeDescription,
52                               EventType eventType,
53                               PurposeOfUse... purposesOfUse) {
54          this(outcome, eventOutcomeDescription, EventActionCode.Create, eventType, purposesOfUse);
55      }
56  
57      public DataImportBuilder(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.Import,
67                  eventType,
68                  purposesOfUse
69          );
70      }
71  
72      /**
73       * @param userId               The identity of the local user or process importing 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 DataImportBuilder addImportingParticipant(String userId, String altUserId, String userName,
82                                                       String networkAccessPointId, boolean userIsRequestor) {
83          return addDestinationActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
84      }
85  
86      /**
87       * @param userId               UserID
88       * @param altUserId            Alternate UserID
89       * @param userName             UserName
90       * @param networkAccessPointId Network Access Point ID
91       * @param userIsRequestor      A single user (either local or remote) shall be identified as the requestor, i.e.,
92       *                             UserIsRequestor with a value of TRUE. This accommodates both push and pull transfer models for media
93       * @return this
94       */
95      public DataImportBuilder addSourceParticipant(String userId, String altUserId, String userName,
96                                                       String networkAccessPointId, boolean userIsRequestor) {
97          return super.addSourceActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
98      }
99  
100     public DataImportBuilder setSourceMediaParticipant(String userId, String altUserId, String userName,
101                                                        NetworkAccessPointTypeCode networkAccessPointType,
102                                                        String networkAccessPointId,
103                                                        String mediaIdentifier,
104                                                        MediaType mediaType) {
105         return addActiveParticipant(
106                 userId,
107                 altUserId,
108                 userName,
109                 false,
110                 Collections.singletonList(ActiveParticipantRoleIdCode.SourceMedia),
111                 networkAccessPointId,
112                 networkAccessPointType,
113                 mediaIdentifier,
114                 requireNonNull(mediaType));
115     }
116 
117     @Override
118     public void validate() {
119         super.validate();
120         if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Destination)).isEmpty()) {
121             throw new AuditException("Must have one or more ActiveParticipant with RoleIDCode Destination");
122         }
123         if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.SourceMedia)).size() != 1) {
124             throw new AuditException("Must have one ActiveParticipant with RoleIDCode SourceMedia");
125         }
126         if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.PatientNumber).isEmpty()) {
127             throw new AuditException("Must one or more ParticipantObjectIdentification with ParticipantObjectIDTypeCode PatientNumber");
128         }
129     }
130 }