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.pdqcore;
17  
18  import ca.uhn.hl7v2.model.Message;
19  import org.openehealth.ipf.commons.audit.AuditContext;
20  import org.openehealth.ipf.commons.audit.model.AuditMessage;
21  import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType;
22  import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport;
23  import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder;
24  import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode;
25  import org.openehealth.ipf.commons.ihe.hl7v2.audit.QueryAuditDataset;
26  
27  import java.util.Map;
28  
29  import static java.util.Objects.requireNonNull;
30  
31  /**
32   * Generic audit strategy for ITI-21 and ITI-22 (PDQ).
33   *
34   * @author Dmytro Rud
35   */
36  public abstract class PdqAuditStrategy extends AuditStrategySupport<QueryAuditDataset> {
37  
38      private final MllpEventTypeCode eventTypeCode;
39      private final ParticipantObjectIdType participantObjectIdType;
40      
41      public PdqAuditStrategy(boolean serverSide, MllpEventTypeCode eventTypeCode, ParticipantObjectIdType participantObjectIdType) {
42          super(serverSide);
43          this.eventTypeCode = requireNonNull(eventTypeCode, "eventTypeCode must be not null");
44          this.participantObjectIdType = requireNonNull(participantObjectIdType, "participantObjectIdType must be not null");
45      }
46      
47      @Override
48      public QueryAuditDataset enrichAuditDatasetFromRequest(QueryAuditDataset auditDataset, Object msg, Map<String, Object> parameters) {
49          PdqAuditStrategyUtils.enrichAuditDatasetFromRequest(auditDataset, (Message)msg, parameters);
50          return auditDataset;
51      }
52      
53      @Override
54      public boolean enrichAuditDatasetFromResponse(QueryAuditDataset auditDataset, Object msg, AuditContext auditContext) {
55          PdqAuditStrategyUtils.enrichAuditDatasetFromResponse(auditDataset, (Message)msg, auditContext);
56          return true;
57      }
58  
59      @Override
60      public QueryAuditDataset createAuditDataset() {
61          return new QueryAuditDataset(isServerSide());
62      }
63  
64      @Override
65      public AuditMessage[] makeAuditMessage(AuditContext auditContext, QueryAuditDataset auditDataset) {
66          return new QueryInformationBuilder(auditContext, auditDataset, eventTypeCode)
67                  .setQueryParameters(
68                          auditDataset.getMessageControlId(),
69                          participantObjectIdType,
70                          auditDataset.getPayload(),
71                          "MSH-10", auditDataset.getMessageControlId())
72                  .addPatients(auditDataset.getPatientIds())
73                  .getMessages();
74      }
75  }