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.ActiveParticipantRoleIdCode;
21 import org.openehealth.ipf.commons.audit.codes.EventActionCode;
22 import org.openehealth.ipf.commons.audit.codes.EventIdCode;
23 import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
24 import org.openehealth.ipf.commons.audit.types.ActiveParticipantRoleId;
25 import org.openehealth.ipf.commons.audit.types.EventType;
26 import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
27
28 import java.util.Collections;
29
30 /**
31 * Builds an Audit Event representing a Query event as specified in
32 * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.10
33 * <p>
34 * This message describes the event of a Query being issued or received.
35 * The message does NOT record the response to the query, but merely records the fact
36 * that a query was issued.
37 * </p>
38 *
39 * @author Christian Ohr
40 * @since 3.5
41 */
42 public class QueryBuilder extends BaseAuditMessageBuilder<QueryBuilder> {
43
44 public QueryBuilder(EventOutcomeIndicator outcome,
45 EventType eventType,
46 PurposeOfUse... purposesOfUse) {
47 this(outcome, null, eventType, purposesOfUse);
48 }
49
50 public QueryBuilder(EventOutcomeIndicator outcome,
51 String eventOutcomeDescription,
52 EventType eventType,
53 PurposeOfUse... purposesOfUse) {
54 super();
55 setEventIdentification(outcome,
56 eventOutcomeDescription,
57 EventActionCode.Execute,
58 EventIdCode.Query,
59 eventType,
60 purposesOfUse
61 );
62 }
63
64 /**
65 * Process Issuing the Query
66 *
67 * @param userId UserID
68 * @param altUserId Alternate UserID
69 * @param userName UserName
70 * @param networkAccessPointId Network Access Point ID
71 * @param userIsRequestor A single user (either local or remote) shall be identified as the requestor, i.e.,
72 * UserIsRequestor with a value of TRUE. This accommodates both push and pull transfer models for media
73 * @return this
74 */
75 public QueryBuilder setQueryingParticipant(String userId,
76 String altUserId,
77 String userName,
78 String networkAccessPointId,
79 boolean userIsRequestor) {
80 return addSourceActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
81 }
82
83 /**
84 * The process that will respond to the query
85 *
86 * @param userId UserID
87 * @param altUserId Alternate UserID
88 * @param userName UserName
89 * @param networkAccessPointId Network Access Point ID
90 * @param userIsRequestor A single user (either local or remote) shall be identified as the requestor, i.e.,
91 * UserIsRequestor with a value of TRUE. This accommodates both push and pull transfer models for media
92 * @return this
93 */
94 public QueryBuilder setRespondingParticipant(String userId,
95 String altUserId,
96 String userName,
97 String networkAccessPointId,
98 boolean userIsRequestor) {
99 return addDestinationActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
100 }
101
102
103 /**
104 * @param userId UserID
105 * @param altUserId Alternate UserID
106 * @param userName UserName
107 * @param networkId Network Access Point ID
108 * @param userIsRequestor Whether the destination participant represents the requestor (i.e. pull request)
109 * @return this
110 */
111 public QueryBuilder addOtherActiveParticipant(String userId,
112 String altUserId,
113 String userName,
114 ActiveParticipantRoleId roleId,
115 String networkId,
116 boolean userIsRequestor) {
117 return addActiveParticipant(userId, altUserId, userName, userIsRequestor, Collections.singletonList(roleId), networkId);
118 }
119
120 @Override
121 public void validate() {
122 super.validate();
123 if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Source)).size() != 1) {
124 throw new AuditException("Must have one ActiveParticipant with RoleIDCode Source");
125 }
126 if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Destination)).size() != 1) {
127 throw new AuditException("Must have one ActiveParticipant with RoleIDCode Destination");
128 }
129
130 // DICOM restricts Participating Object to be one SOP Queried and the Query, but IHE also uses this Audit Event
131 // for all sorts of other queries, so we cannot validate this at this point.
132 }
133 }