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  
17  package org.openehealth.ipf.commons.audit.event;
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.PurposeOfUse;
23  
24  import java.util.Collections;
25  
26  /**
27   * Builds an Audit Event representing a Begin Transferring DICOM Instances event as specified in
28   * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.3
29   * <p>
30   * This message describes the event of a system beginning to transfer a set of DICOM instances
31   * from one node to another node within control of the system's security domain.
32   * This message may only include information about a single patient.
33   * </p>
34   *
35   * @author Christian Ohr
36   * @since 3.5
37   */
38  public class BeginTransferringDicomInstancesBuilder extends BaseAuditMessageBuilder<BeginTransferringDicomInstancesBuilder> {
39  
40      public BeginTransferringDicomInstancesBuilder(
41              EventOutcomeIndicator outcome,
42              String eventOutcomeDescription,
43              EventType eventType,
44              PurposeOfUse... purposesOfUse) {
45          super();
46          setEventIdentification(outcome,
47                  eventOutcomeDescription,
48                  EventActionCode.Execute,
49                  EventIdCode.BeginTransferringDICOMInstances,
50                  eventType,
51                  purposesOfUse
52          );
53      }
54  
55  
56      /**
57       * @param userId          The identity of the process sending the data
58       * @param altUserId       Alternate UserID
59       * @param userName        UserName
60       * @param networkId       Network Access Point ID
61       * @param userIsRequestor Whether the destination participant represents the requestor (i.e. pull request)
62       * @return this
63       */
64      public BeginTransferringDicomInstancesBuilder setSendingProcessParticipant(String userId,
65                                                                                 String altUserId,
66                                                                                 String userName,
67                                                                                 String networkId,
68                                                                                 boolean userIsRequestor) {
69          return addSourceActiveParticipant(userId, altUserId, userName, networkId, userIsRequestor);
70      }
71  
72      /**
73       * @param userId          The identity of the process receiving the data
74       * @param altUserId       Alternate UserID
75       * @param userName        UserName
76       * @param networkId       Network Access Point ID
77       * @param userIsRequestor Whether the destination participant represents the requestor (i.e. pull request)
78       * @return this
79       */
80      public BeginTransferringDicomInstancesBuilder setReceivingProcessParticipant(String userId,
81                                                                                   String altUserId,
82                                                                                   String userName,
83                                                                                   String networkId,
84                                                                                   boolean userIsRequestor) {
85          return addDestinationActiveParticipant(userId, altUserId, userName, networkId, userIsRequestor);
86      }
87  
88      /**
89       * @param patientId   patient ID
90       * @param patientName patient name
91       * @return this
92       */
93      public BeginTransferringDicomInstancesBuilder setPatientParticipantObject(String patientId, String patientName) {
94          if (patientId != null) {
95              addPatientParticipantObject(patientId, patientName, Collections.emptyList(), null);
96          }
97          return self();
98      }
99  
100     /**
101      * @param studyId study ID
102      * @param uids    one or more SOP Class UID values
103      * @return this
104      */
105     public BeginTransferringDicomInstancesBuilder addTransferredStudyParticipantObject(String studyId, String uids) {
106         return addStudyParticipantObject(
107                 studyId,
108                 Collections.singletonList(getTypeValuePair("ContainsSOPClass", uids)));
109     }
110 
111     @Override
112     public void validate() {
113         super.validate();
114         if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Source)).size() != 1) {
115             throw new AuditException("Must have one ActiveParticipant with RoleIDCode Source");
116         }
117         if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Destination)).size() != 1) {
118             throw new AuditException("Must have one ActiveParticipant with RoleIDCode Destination");
119         }
120         if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.PatientNumber).size() != 1) {
121             throw new AuditException("Must have one ParticipantObjectIdentification with ParticipantObjectIDTypeCode PatientNumber");
122         }
123         if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.StudyInstanceUID).isEmpty()) {
124             throw new AuditException("Must have one or more ParticipantObjectIdentification with ParticipantObjectIDTypeCode StudyInstanceUID");
125         }
126     }
127 }