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.ihe.core.atna.event;
18  
19  import org.openehealth.ipf.commons.audit.AuditContext;
20  import org.openehealth.ipf.commons.audit.codes.EventActionCode;
21  import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
22  import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCode;
23  import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCodeRole;
24  import org.openehealth.ipf.commons.audit.event.DataExportBuilder;
25  import org.openehealth.ipf.commons.audit.model.TypeValuePairType;
26  import org.openehealth.ipf.commons.audit.types.EventType;
27  import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType;
28  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
29  import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset;
30  
31  import java.util.Collections;
32  import java.util.List;
33  
34  /**
35   * Builder for building IHE-specific DataExport events.
36   * It automatically sets the AuditSource, local and remote ActiveParticipant and a Human Requestor
37   * and provides methods for adding patient IDs.
38   *
39   * @author Christian Ohr
40   * @since 3.5
41   */
42  public class PHIExportBuilder<T extends PHIExportBuilder<T>> extends IHEAuditMessageBuilder<T, DataExportBuilder> {
43  
44      public PHIExportBuilder(AuditContext auditContext,
45                              AuditDataset auditDataset,
46                              EventType eventType,
47                              PurposeOfUse... purposesOfUse) {
48          this(auditContext, auditDataset, EventActionCode.Read, eventType, purposesOfUse);
49      }
50  
51      public PHIExportBuilder(AuditContext auditContext,
52                              AuditDataset auditDataset,
53                              EventActionCode eventActionCode,
54                              EventType eventType,
55                              PurposeOfUse... purposesOfUse) {
56          this(auditContext, auditDataset, auditDataset.getEventOutcomeIndicator(),
57                  auditDataset.getEventOutcomeDescription(),
58                  eventActionCode, eventType, purposesOfUse);
59      }
60  
61      public PHIExportBuilder(AuditContext auditContext,
62                              AuditDataset auditDataset,
63                              EventOutcomeIndicator eventOutcomeIndicator,
64                              String eventOutcomeDescription,
65                              EventActionCode eventActionCode,
66                              EventType eventType,
67                              PurposeOfUse... purposesOfUse) {
68          super(auditContext, new DataExportBuilder(
69                  eventOutcomeIndicator,
70                  eventOutcomeDescription,
71                  eventActionCode,
72                  eventType,
73                  purposesOfUse));
74  
75          // First the source, then the destination
76          if (auditDataset.isServerSide()) {
77              setRemoteParticipant(auditDataset);
78              addHumanRequestor(auditDataset);
79              setLocalParticipant(auditDataset);
80          } else {
81              setLocalParticipant(auditDataset);
82              addHumanRequestor(auditDataset);
83              setRemoteParticipant(auditDataset);
84          }
85      }
86  
87      public T setPatient(String patientId) {
88          if (patientId != null) {
89              delegate.addPatientParticipantObject(patientId, null,
90                      Collections.emptyList(), null);
91          }
92          return self();
93      }
94  
95      public T addExportedEntity(
96              String objectId,
97              ParticipantObjectIdType participantObjectIdType,
98              ParticipantObjectTypeCodeRole participantObjectTypeCodeRole,
99              List<TypeValuePairType> details) {
100         return addExportedEntity(
101                 objectId,
102                 participantObjectIdType,
103                 ParticipantObjectTypeCode.System,
104                 participantObjectTypeCodeRole,
105                 details);
106     }
107 
108     public T addExportedEntity(
109             String objectId,
110             ParticipantObjectIdType participantObjectIdType,
111             ParticipantObjectTypeCode participantObjectTypeCode,
112             ParticipantObjectTypeCodeRole participantObjectTypeCodeRole,
113             List<TypeValuePairType> details) {
114         delegate.addParticipantObjectIdentification(
115                 participantObjectIdType,
116                 null,
117                 null,
118                 details,
119                 objectId,
120                 participantObjectTypeCode,
121                 participantObjectTypeCodeRole,
122                 null,
123                 null);
124         return self();
125     }
126 
127     @Override
128     public void validate() {
129         super.validate();
130     }
131 }