View Javadoc
1   /*
2    * Copyright 2015 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.hl7v2.audit.iti64;
17  
18  import ca.uhn.hl7v2.model.v25.datatype.CX;
19  import ca.uhn.hl7v2.model.v25.group.ADT_A43_PATIENT;
20  import ca.uhn.hl7v2.parser.EncodingCharacters;
21  import ca.uhn.hl7v2.parser.PipeParser;
22  import org.openehealth.ipf.commons.audit.AuditContext;
23  import org.openehealth.ipf.commons.audit.model.AuditMessage;
24  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport;
25  import org.openehealth.ipf.commons.ihe.hl7v2.definitions.xpid.v25.message.ADT_A43;
26  
27  import java.util.Map;
28  
29  /**
30   * Generic audit strategy for ITI-64 (Notify XAD-PID Link Change).
31   *
32   * @author Christian Ohr
33   * @author Boris Stanojevic
34   * @author Dmytro Rud
35   */
36  public class Iti64AuditStrategy extends AuditStrategySupport<Iti64AuditDataset> {
37  
38      private static final EncodingCharacters ENCODING_CHARACTERS =
39              new EncodingCharacters('|', null);
40  
41  
42      public Iti64AuditStrategy(boolean serverSide) {
43          super(serverSide);
44      }
45  
46  
47      @Override
48      public Iti64AuditDataset enrichAuditDatasetFromRequest(Iti64AuditDataset auditDataset, Object msg, Map<String, Object> parameters) {
49          ADT_A43 message = (ADT_A43) msg;
50          ADT_A43_PATIENT patient = message.getPATIENT(0);
51  
52          CX[] pidPatientIdList = patient.getPID().getPatientIdentifierList();
53          if (pidPatientIdList.length > 0) {
54              auditDataset.setNewPatientId(PipeParser.encode(pidPatientIdList[0], ENCODING_CHARACTERS));
55              if (pidPatientIdList.length > 1) {
56                  auditDataset.setLocalPatientId(PipeParser.encode(pidPatientIdList[1], ENCODING_CHARACTERS));
57              }
58          }
59  
60          CX[] mrgPatientIdList = patient.getMRG().getMrg1_PriorPatientIdentifierList();
61          if (mrgPatientIdList.length > 0) {
62              auditDataset.setPreviousPatientId(PipeParser.encode(mrgPatientIdList[0], ENCODING_CHARACTERS));
63              if (mrgPatientIdList.length > 1) {
64                  auditDataset.setSubsumedLocalPatientId(PipeParser.encode(mrgPatientIdList[1], ENCODING_CHARACTERS));
65              }
66          }
67  
68          return auditDataset;
69      }
70  
71      @Override
72      public AuditMessage[] makeAuditMessage(AuditContext auditContext, Iti64AuditDataset auditDataset) {
73          IHEPatientRecordChangeLinkBuilder builder = new IHEPatientRecordChangeLinkBuilder<>(auditContext, auditDataset)
74                  .setLocalPatientId(auditDataset);
75          if (auditDataset.getSubsumedLocalPatientId() != null) {
76              builder.setSubsumedLocalPatientId(auditDataset);
77          }
78          return builder
79                  .setNewPatientId(auditDataset)
80                  .setPreviousPatientId(auditDataset)
81                  .setSubmissionSet(auditDataset)
82                  .getMessages();
83      }
84  
85  
86      @Override
87      public Iti64AuditDataset createAuditDataset() {
88          return new Iti64AuditDataset(isServerSide());
89      }
90  }