View Javadoc
1   /*
2    * Copyright 2012 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  package org.openehealth.ipf.commons.ihe.core.atna.custom;
17  
18  import org.apache.commons.lang3.StringUtils;
19  import org.openhealthtools.ihe.atna.auditor.PIXAuditor;
20  import org.openhealthtools.ihe.atna.auditor.codes.ihe.IHETransactionParticipantObjectIDTypeCodes;
21  import org.openhealthtools.ihe.atna.auditor.codes.rfc3881.RFC3881EventCodes;
22  import org.openhealthtools.ihe.atna.auditor.codes.rfc3881.RFC3881ParticipantObjectCodes;
23  import org.openhealthtools.ihe.atna.auditor.context.AuditorModuleContext;
24  import org.openhealthtools.ihe.atna.auditor.events.ihe.PatientRecordEvent;
25  import org.openhealthtools.ihe.atna.auditor.models.rfc3881.TypeValuePairType;
26  
27  import java.util.Arrays;
28  
29  import static org.openehealth.ipf.commons.ihe.core.atna.custom.CustomAuditorUtils.configureEvent;
30  
31  /**
32   * Implementation of ATNA Auditors for the following HL7v2-based transactions:
33   * <ul>
34   *     <li>ITI-64 -- Notify XAD-PID Link Change</li>
35   * </ul>
36   *
37   * @author Dmytro Rud
38   * @deprecated
39   */
40  public class CustomPixAuditor extends PIXAuditor {
41  
42      public static CustomPixAuditor getAuditor() {
43          AuditorModuleContext ctx = AuditorModuleContext.getContext();
44          return (CustomPixAuditor) ctx.getAuditor(CustomPixAuditor.class);
45      }
46  
47      public void auditIti64(
48              boolean serverSide,
49              RFC3881EventCodes.RFC3881EventOutcomeCodes eventOutcome,
50              String pixManagerIpAddress,
51              String sendingFacility,
52              String sendingApp,
53              String documentRegistryUri,
54              String receivingFacility,
55              String receivingApp,
56              String hl7MessageControlId,
57              String localPatientId,
58              String subsumedLocalPatientId,
59              String newPatientId,
60              String previousPatientId,
61              String submissionSetUuid)
62      {
63          if (! isAuditorEnabled()) {
64              return;
65          }
66  
67          CustomIHETransactionEventTypeCodes.NotifyXadPidLinkChange transactionCode =
68                  new CustomIHETransactionEventTypeCodes.NotifyXadPidLinkChange();
69  
70          PatientRecordEvent event = new PatientRecordEvent(
71                  true,
72                  eventOutcome,
73                  RFC3881EventCodes.RFC3881EventActionCodes.UPDATE,
74                  transactionCode,
75                  null);
76  
77          configureEvent(
78                  this,
79                  serverSide,
80                  event,
81                  sendingFacility + '|' + sendingApp,
82                  null,
83                  receivingFacility + '|' + receivingApp,
84                  documentRegistryUri,
85                  pixManagerIpAddress,
86                  null);
87  
88          TypeValuePairType messageIdVP           = event.getTypeValuePair("MSH-10", hl7MessageControlId);
89          TypeValuePairType localPatientIdVP      = event.getTypeValuePair("urn:ihe:iti:xpid:2017:patientIdentifierType", "localPatientId");
90          TypeValuePairType subsumedPatientIdVP   = event.getTypeValuePair("urn:ihe:iti:xpid:2017:patientIdentifierType", "subsumedPatientId");
91          TypeValuePairType newPatientIdIdVP      = event.getTypeValuePair("urn:ihe:iti:xpid:2017:patientIdentifierType", "newPatientId");
92          TypeValuePairType previousPatientIdIdVP = event.getTypeValuePair("urn:ihe:iti:xpid:2017:patientIdentifierType", "previousPatientId");
93  
94          boolean subsumedLocalPatientIdPresent = StringUtils.isNoneBlank(subsumedLocalPatientId);
95          boolean newPatientIdEqualsToPrevious = StringUtils.equals(newPatientId, previousPatientId);
96  
97          event.addParticipantObjectIdentification(
98                  new RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectIDTypeCodes.PatientNumber(),
99                  null,
100                 null,
101                 Arrays.asList(messageIdVP, localPatientIdVP),
102                 localPatientId,
103                 RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeCodes.PERSON,
104                 RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeRoleCodes.PATIENT,
105                 subsumedLocalPatientIdPresent ? RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectDataLifeCycleCodes.ORIGINATION : null,
106                 null);
107 
108         if (subsumedLocalPatientIdPresent) {
109             event.addParticipantObjectIdentification(
110                     new RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectIDTypeCodes.PatientNumber(),
111                     null,
112                     null,
113                     Arrays.asList(messageIdVP, subsumedPatientIdVP),
114                     subsumedLocalPatientId,
115                     RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeCodes.PERSON,
116                     RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeRoleCodes.PATIENT,
117                     RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectDataLifeCycleCodes.LOGICAL_DELETION,
118                     null);
119         }
120 
121         event.addParticipantObjectIdentification(
122                 new RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectIDTypeCodes.PatientNumber(),
123                 null,
124                 null,
125                 Arrays.asList(messageIdVP, newPatientIdIdVP),
126                 newPatientId,
127                 RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeCodes.PERSON,
128                 RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeRoleCodes.PATIENT,
129                 newPatientIdEqualsToPrevious ? null : RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectDataLifeCycleCodes.ORIGINATION,
130                 null);
131 
132         event.addParticipantObjectIdentification(
133                 new RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectIDTypeCodes.PatientNumber(),
134                 null,
135                 null,
136                 Arrays.asList(messageIdVP, previousPatientIdIdVP),
137                 previousPatientId,
138                 RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeCodes.PERSON,
139                 RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeRoleCodes.PATIENT,
140                 newPatientIdEqualsToPrevious ? null : RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectDataLifeCycleCodes.LOGICAL_DELETION,
141                 null);
142 
143         if (serverSide && StringUtils.isNotBlank(submissionSetUuid)) {
144             event.addParticipantObjectIdentification(
145                     new IHETransactionParticipantObjectIDTypeCodes.SubmissionSet(),
146                     null,
147                     null,
148                     null,
149                     submissionSetUuid,
150                     RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeCodes.SYSTEM,
151                     RFC3881ParticipantObjectCodes.RFC3881ParticipantObjectTypeRoleCodes.JOB,
152                     null,
153                     null);
154         }
155 
156         audit(event);
157     }
158 
159 }