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.model.TypeValuePairType;
22 import org.openehealth.ipf.commons.audit.types.ActiveParticipantRoleId;
23 import org.openehealth.ipf.commons.audit.types.EventType;
24 import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
25
26 import java.util.List;
27
28
29
30
31
32
33
34
35
36
37
38 public class PatientRecordBuilder extends BaseAuditMessageBuilder<PatientRecordBuilder> {
39
40 public PatientRecordBuilder(EventOutcomeIndicator outcome,
41 EventActionCode action,
42 EventType eventType,
43 PurposeOfUse... purposesOfUse) {
44 this(outcome, null, action, eventType, purposesOfUse);
45 }
46
47 public PatientRecordBuilder(EventOutcomeIndicator outcome,
48 String eventOutcomeDescription,
49 EventActionCode action,
50 EventType eventType,
51 PurposeOfUse... purposesOfUse) {
52 super();
53 setEventIdentification(outcome,
54 eventOutcomeDescription,
55 action,
56 EventIdCode.PatientRecord,
57 eventType,
58 purposesOfUse
59 );
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73 public PatientRecordBuilder addUserParticipant(String userId,
74 String altUserId,
75 String userName,
76 String networkAccessPointId,
77 List<ActiveParticipantRoleId> roleIds,
78 boolean userIsRequestor) {
79 return addActiveParticipant(userId, altUserId, userName, userIsRequestor, roleIds,
80 networkAccessPointId);
81 }
82
83 public PatientRecordBuilder addPatient(String patientId, String patientName, List<TypeValuePairType> details) {
84 return addPatientParticipantObject(patientId, patientName, details, null);
85 }
86
87 public PatientRecordBuilder addPatient(String patientId, String patientName, List<TypeValuePairType> details, ParticipantObjectDataLifeCycle lifeCycle) {
88 return addPatientParticipantObject(patientId, patientName, details, lifeCycle);
89 }
90
91 @Override
92 public void validate() {
93 super.validate();
94 int aps = getMessage().getActiveParticipants().size();
95 if (aps < 1 || aps > 2) {
96 throw new AuditException("Must have one or two user ActiveParticipants");
97 }
98 if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.PatientNumber).size() != 1) {
99 throw new AuditException("Must one ParticipantObjectIdentification with ParticipantObjectIDTypeCode PatientNumber");
100 }
101 }
102 }