View Javadoc
1   /*
2    * Copyright 2018 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  
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   * Builds an Audit Event representing a Order Record event as specified in
31   * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.13
32   * <p>
33   * This message describes the event of an order being created, modified, accessed, or deleted.
34   * This message may only include information about a single patient.
35   * </p>
36   *
37   * @author Christian Ohr
38   * @since 3.5
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       * @param patientId   patient ID
59       * @param patientName patient name
60       * @return this
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  }