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.iti30;
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 Iti30AuditStrategy extends AuditStrategySupport<FeedAuditDataset> {
31  
32      public Iti30AuditStrategy(boolean serverSide) {
33          super(serverSide);
34      }
35  
36      @Override
37      public FeedAuditDataset enrichAuditDatasetFromRequest(FeedAuditDataset auditDataset, Object msg, Map<String, Object> parameters) {
38          Iti30AuditStrategyUtils.enrichAuditDatasetFromRequest(auditDataset, (Message) msg);
39          return auditDataset;
40      }
41  
42      @Override
43      public AuditMessage[] makeAuditMessage(AuditContext auditContext, FeedAuditDataset auditDataset) {
44          switch (auditDataset.getMessageType()) {
45              case "A28":
46                  return new AuditMessage[]{
47                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true)
48                  };
49              case "A31":
50              case "A47":
51              case "A24":
52              case "A37":
53                  return new AuditMessage[]{
54                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true)
55                  };
56              case "A40":
57                  return new AuditMessage[]{
58                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false),
59                          patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true)
60                  };
61              default:
62                  throw new AuditException("Cannot create audit message for event " + auditDataset.getMessageType());
63          }
64      }
65  
66      protected AuditMessage patientRecordAuditMessage(AuditContext auditContext,
67                                                       final FeedAuditDataset auditDataset,
68                                                       EventActionCode eventActionCode,
69                                                       boolean newPatientId) {
70          return new PatientRecordEventBuilder<>(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityManagement)
71  
72                  // Type=MSH-10 (the literal string), Value=the value of MSH-10 (from the message content, base64 encoded)
73                  .addPatients(
74                          "MSH-10", auditDataset.getMessageControlId(),
75                          newPatientId ? auditDataset.getPatientId() : auditDataset.getOldPatientId())
76                  .getMessage();
77      }
78  
79      @Override
80      public FeedAuditDataset createAuditDataset() {
81          return new FeedAuditDataset(isServerSide());
82      }
83  }