View Javadoc
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  
17  package org.openehealth.ipf.commons.ihe.hl7v2.audit.iti64;
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.ParticipantObjectIdTypeCode;
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.PatientRecordBuilder;
25  import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset;
26  import org.openehealth.ipf.commons.ihe.core.atna.event.IHEAuditMessageBuilder;
27  import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder;
28  import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode;
29  
30  import java.util.Arrays;
31  import java.util.Collections;
32  
33  import static org.openehealth.ipf.commons.audit.codes.ParticipantObjectDataLifeCycle.LogicalDeletion;
34  import static org.openehealth.ipf.commons.audit.codes.ParticipantObjectDataLifeCycle.Origination;
35  
36  /**
37   * ITI-64 Auditing is somewhat special, so we have a dedicated builder
38   *
39   * @author Christian Ohr
40   */
41  class IHEPatientRecordChangeLinkBuilder<T extends PatientRecordEventBuilder<T>> extends IHEAuditMessageBuilder<T, PatientRecordBuilder> {
42  
43      private static final String URN_IHE_ITI_XPID_2017_PATIENT_IDENTIFIER_TYPE = "urn:ihe:iti:xpid:2017:patientIdentifierType";
44  
45      IHEPatientRecordChangeLinkBuilder(AuditContext auditContext, AuditDataset auditDataset) {
46          super(auditContext, new PatientRecordBuilder(auditDataset.getEventOutcomeIndicator(), EventActionCode.Update, MllpEventTypeCode.XadPidLinkChange));
47  
48          // First the source, then the destination
49          if (auditDataset.isServerSide()) {
50              setRemoteParticipant(auditDataset);
51              addHumanRequestor(auditDataset);
52              setLocalParticipant(auditDataset);
53          } else {
54              setLocalParticipant(auditDataset);
55              addHumanRequestor(auditDataset);
56              setRemoteParticipant(auditDataset);
57          }
58      }
59  
60      public IHEPatientRecordChangeLinkBuilder setLocalPatientId(Iti64AuditDataset auditDataset) {
61          delegate.addPatient(auditDataset.getLocalPatientId(), null,
62                  Arrays.asList(
63                          getTypeValuePair("MSH-10", auditDataset.getMessageControlId()),
64                          getTypeValuePair(URN_IHE_ITI_XPID_2017_PATIENT_IDENTIFIER_TYPE, "localPatientId")
65                  ),
66                  // If subsumedLocalPatientId is present, then this value shall
67                  // equal "1" (Origination / Creation). Otherwise, this value is not
68                  // specialized.
69                  auditDataset.getSubsumedLocalPatientId() == null ? null : Origination);
70          return this;
71      }
72  
73      public IHEPatientRecordChangeLinkBuilder setSubsumedLocalPatientId(Iti64AuditDataset auditDataset) {
74          delegate.addPatient(auditDataset.getSubsumedLocalPatientId(), null,
75                  Arrays.asList(
76                          getTypeValuePair("MSH-10", auditDataset.getMessageControlId()),
77                          getTypeValuePair(URN_IHE_ITI_XPID_2017_PATIENT_IDENTIFIER_TYPE, "subsumedPatientId")
78                  ),
79                  LogicalDeletion);
80          return this;
81      }
82  
83      public IHEPatientRecordChangeLinkBuilder setNewPatientId(Iti64AuditDataset auditDataset) {
84          delegate.addPatient(auditDataset.getNewPatientId(), null,
85                  Arrays.asList(
86                          getTypeValuePair("MSH-10", auditDataset.getMessageControlId()),
87                          getTypeValuePair(URN_IHE_ITI_XPID_2017_PATIENT_IDENTIFIER_TYPE, "newPatientId")
88                  ),
89                  // If newPatientId and previousPatientId are not equal, then this
90                  // value shall equal "14" (Logical deletion). Otherwise, this value
91                  // is not specialized.
92                  auditDataset.getNewPatientId().equals(auditDataset.getPreviousPatientId()) ? null : Origination);
93          return this;
94      }
95  
96      public IHEPatientRecordChangeLinkBuilder setPreviousPatientId(Iti64AuditDataset auditDataset) {
97          delegate.addPatient(auditDataset.getPreviousPatientId(), null,
98                  Arrays.asList(
99                          getTypeValuePair("MSH-10", auditDataset.getMessageControlId()),
100                         getTypeValuePair(URN_IHE_ITI_XPID_2017_PATIENT_IDENTIFIER_TYPE, "previousPatientId")
101                 ),
102                 // If newPatientId and previousPatientId are not equal, then this
103                 // value shall equal "14" (Logical deletion). Otherwise, this value
104                 // is not specialized.
105                 auditDataset.getNewPatientId().equals(auditDataset.getPreviousPatientId()) ?
106                         null :
107                         LogicalDeletion);
108         return this;
109     }
110 
111     public IHEPatientRecordChangeLinkBuilder setSubmissionSet(Iti64AuditDataset auditDataset) {
112         if (auditDataset.getSubmissionSetUuid() != null) {
113             delegate.addParticipantObjectIdentification(
114                     ParticipantObjectIdTypeCode.XdsMetadata,
115                     null,
116                     null,
117                     Collections.emptyList(),
118                     auditDataset.getSubmissionSetUuid(),
119                     ParticipantObjectTypeCode.System,
120                     ParticipantObjectTypeCodeRole.Job,
121                     null,
122                     null);
123         }
124         return this;
125     }
126 
127     @Override
128     public void validate() {
129         super.validate();
130     }
131 }