1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.EventActionCode;
21 import org.openehealth.ipf.commons.audit.codes.EventIdCode;
22 import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
23 import org.openehealth.ipf.commons.audit.codes.ParticipantObjectIdTypeCode;
24 import org.openehealth.ipf.commons.audit.types.EventType;
25 import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
26
27 import java.util.Collections;
28
29
30
31
32
33
34
35
36
37
38
39
40 public class OrderRecordBuilder extends BaseAuditMessageBuilder<OrderRecordBuilder> {
41
42 public OrderRecordBuilder(EventOutcomeIndicator outcome,
43 String eventOutcomeDescription,
44 EventActionCode eventActionCode,
45 EventType eventType,
46 PurposeOfUse... purposesOfUse) {
47 super();
48 setEventIdentification(outcome,
49 eventOutcomeDescription,
50 eventActionCode,
51 EventIdCode.OrderRecord,
52 eventType,
53 purposesOfUse
54 );
55 }
56
57
58
59
60
61
62 public OrderRecordBuilder setPatientParticipantObject(String patientId, String patientName) {
63 if (patientId != null) {
64 addPatientParticipantObject(patientId, patientName, Collections.emptyList(), null);
65 }
66 return self();
67 }
68
69 @Override
70 public void validate() {
71 super.validate();
72 int participants = getMessage().getActiveParticipants().size();
73 if (participants < 1 || participants > 2) {
74 throw new AuditException("Must have one or two ActiveParticipants");
75 }
76 if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.PatientNumber).size() != 1) {
77 throw new AuditException("Must one ParticipantObjectIdentification with ParticipantObjectIDTypeCode PatientNumber");
78 }
79 }
80 }