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 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
74
75
76
77
78
79
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
88
89
90
91
92
93
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 }