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.DataImportBuilder;
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 DataImport 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 PHIImportBuilder<T extends PHIImportBuilder<T>> extends IHEAuditMessageBuilder<T, DataImportBuilder> {
43  
44  
45      public PHIImportBuilder(AuditContext auditContext,
46                              AuditDataset auditDataset,
47                              EventType eventType,
48                              PurposeOfUse... purposesOfUse) {
49          this(auditContext, auditDataset, EventActionCode.Create, eventType, purposesOfUse);
50      }
51  
52      public PHIImportBuilder(AuditContext auditContext,
53                              AuditDataset auditDataset,
54                              EventActionCode eventActionCode,
55                              EventType eventType,
56                              PurposeOfUse... purposesOfUse) {
57          this(auditContext, auditDataset, auditDataset.getEventOutcomeIndicator(),
58                  auditDataset.getEventOutcomeDescription(), eventActionCode, eventType, purposesOfUse);
59      }
60  
61      public PHIImportBuilder(AuditContext auditContext,
62                              AuditDataset auditDataset,
63                              EventOutcomeIndicator eventOutcomeIndicator,
64                              String eventOutcomeDescription,
65                              EventActionCode eventActionCode,
66                              EventType eventType,
67                              PurposeOfUse... purposesOfUse) {
68          super(auditContext, new DataImportBuilder(
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 addImportedEntity(
96              String objectId,
97              ParticipantObjectIdType participantObjectIdType,
98              ParticipantObjectTypeCodeRole participantObjectTypeCodeRole,
99              List<TypeValuePairType> details) {
100         return addImportedEntity(objectId, participantObjectIdType, ParticipantObjectTypeCode.System,
101                 participantObjectTypeCodeRole, details);
102     }
103 
104     public T addImportedEntity(
105             String objectId,
106             ParticipantObjectIdType participantObjectIdType,
107             ParticipantObjectTypeCode participantObjectTypeCode,
108             ParticipantObjectTypeCodeRole participantObjectTypeCodeRole,
109             List<TypeValuePairType> details) {
110         if (objectId != null) {
111             delegate.addParticipantObjectIdentification(
112                     participantObjectIdType,
113                     null,
114                     null,
115                     details,
116                     objectId,
117                     participantObjectTypeCode,
118                     participantObjectTypeCodeRole,
119                     null,
120                     null);
121         }
122         return self();
123     }
124 
125     @Override
126     public void validate() {
127         super.validate();
128     }
129 }