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.iti31;
17  
18  import ca.uhn.hl7v2.model.Message;
19  import org.openehealth.ipf.commons.audit.AuditContext;
20  import org.openehealth.ipf.commons.audit.AuditException;
21  import org.openehealth.ipf.commons.audit.codes.EventActionCode;
22  import org.openehealth.ipf.commons.audit.model.AuditMessage;
23  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport;
24  import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder;
25  import org.openehealth.ipf.commons.ihe.hl7v2.audit.FeedAuditDataset;
26  import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode;
27  
28  import java.util.Map;
29  
30  public class Iti31AuditStrategy extends AuditStrategySupport<FeedAuditDataset> {
31  
32  
33      public Iti31AuditStrategy(boolean serverSide) {
34          super(serverSide);
35      }
36  
37      @Override
38      public FeedAuditDataset enrichAuditDatasetFromRequest(FeedAuditDataset auditDataset, Object msg, Map<String, Object> parameters) {
39          Iti31AuditStrategyUtils.enrichAuditDatasetFromRequest(auditDataset, (Message) msg);
40          return auditDataset;
41      }
42  
43      @Override
44      public AuditMessage[] makeAuditMessage(AuditContext auditContext, FeedAuditDataset auditDataset) {
45          switch (auditDataset.getMessageType()) {
46              case "A01":
47              case "A04":
48              case "A05":
49                  return new AuditMessage[]{
50                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true)
51                  };
52              case "A02":
53              case "A03":
54              case "A06":
55              case "A07":
56              case "A08":
57              case "A09":
58              case "A10":
59              case "A12":
60              case "A13":
61              case "A14":
62              case "A15":
63              case "A16":
64              case "A25":
65              case "A26":
66              case "A27":
67              case "A32":
68              case "A33":
69              case "A38":
70              case "A44":
71              case "A52":
72              case "A53":
73              case "A54":
74              case "A55":
75              case "Z99":
76                  return new AuditMessage[]{
77                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true)
78                  };
79              case "A40":
80                  return new AuditMessage[]{
81                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false),
82                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true)
83                  };
84              case "A41":
85                  return new AuditMessage[]{
86                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, true)
87                  };
88              default:
89                  throw new AuditException("Cannot create audit message for event " + auditDataset.getMessageType());
90          }
91      }
92  
93      protected AuditMessage patientRecordAuditMessage(AuditContext auditContext,
94                                                       final FeedAuditDataset auditDataset,
95                                                       EventActionCode eventActionCode,
96                                                       boolean newPatientId) {
97          return new PatientRecordEventBuilder<>(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityManagement)
98  
99                  // Type=MSH-10 (the literal string), Value=the value of MSH-10 (from the message content, base64 encoded)
100                 .addPatients(
101                         "MSH-10", auditDataset.getMessageControlId(),
102                         newPatientId ? auditDataset.getPatientId() : auditDataset.getOldPatientId()
103                 )
104                 .getMessage();
105     }
106 
107     @Override
108     public FeedAuditDataset createAuditDataset() {
109         return new FeedAuditDataset(isServerSide());
110     }
111 }