1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
31
32
33
34
35
36
37
38
39
40
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
74
75
76
77
78
79
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
91
92
93
94
95
96
97
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
109
110
111
112
113
114
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 }