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.*;
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 * Builds an Audit Event representing a Patient Record event as specified in
30 * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.4
31 * <p>
32 * This message describes the event of a patient record being created, modified, accessed, or deleted.
33 * </p>
34 *
35 * @author Christian Ohr
36 * @since 3.5
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 * @param userId The identity of the person or process manipulating the data. If both are known, then two active
64 * participants shall be included (both the person and the process).
65 * @param altUserId Alternate UserID
66 * @param userName UserName
67 * @param networkAccessPointId Network Access Point ID
68 * @param roleIds Role ids
69 * @param userIsRequestor A single user (either local or remote) shall be identified as the requestor, i.e.,
70 * UserIsRequestor with a value of TRUE. This accommodates both push and pull transfer models for media
71 * @return this
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 }