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.*;
21  import org.openehealth.ipf.commons.audit.types.EventType;
22  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
23  
24  import java.util.Collections;
25  
26  /**
27   * Builds an Audit Event representing a DICOM Instances Accessed event as specified in
28   * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.6
29   * <p>
30   * This message describes the event of DICOM SOP Instances being viewed, utilized, updated,
31   * or deleted. This message shall only include information about a single patient and can be used
32   * to summarize all activity for several studies for that patient.
33   * This message records the studies to which the instances belong, not the individual instances.
34   * </p>
35   * <p>
36   * If all instances within a study are deleted, then {@link DicomStudyDeletedBuilder} shall be used
37   * </p>
38   *
39   * @author Christian Ohr
40   * @since 3.5
41   */
42  public class DicomInstancesAccessedBuilder extends BaseAuditMessageBuilder<DicomInstancesAccessedBuilder> {
43  
44      public DicomInstancesAccessedBuilder(EventOutcomeIndicator outcome,
45                                           String eventOutcomeDescription,
46                                           EventActionCode eventActionCode,
47                                           EventType eventType,
48                                           PurposeOfUse... purposesOfUse) {
49          super();
50          setEventIdentification(outcome,
51                  eventOutcomeDescription,
52                  eventActionCode,
53                  EventIdCode.DICOMInstancesAccessed,
54                  eventType,
55                  purposesOfUse
56          );
57      }
58  
59      /**
60       * @param patientId   patient ID
61       * @param patientName patient name
62       * @return this
63       */
64      public DicomInstancesAccessedBuilder setPatientParticipantObject(String patientId, String patientName) {
65          if (patientId != null) {
66              addPatientParticipantObject(patientId, patientName, Collections.emptyList(), null);
67          }
68          return self();
69      }
70  
71      @Override
72      public void validate() {
73          super.validate();
74          int participants = getMessage().getActiveParticipants().size();
75          if (participants < 1 || participants > 2) {
76              throw new AuditException("Must have one or two ActiveParticipants");
77          }
78          if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.StudyInstanceUID).isEmpty()) {
79              throw new AuditException("Must have one or more ParticipantObjectIdentification with ParticipantObjectIDTypeCode StudyInstanceUID");
80          }
81          if (getMessage().findParticipantObjectIdentifications(poi -> poi.getParticipantObjectIDTypeCode() == ParticipantObjectIdTypeCode.PatientNumber).size() != 1) {
82              throw new AuditException("Must one ParticipantObjectIdentification with ParticipantObjectIDTypeCode PatientNumber");
83          }
84      }
85  }