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.fhir.iti78;
17  
18  import org.hl7.fhir.dstu3.model.IdType;
19  import org.openehealth.ipf.commons.audit.AuditContext;
20  import org.openehealth.ipf.commons.audit.model.AuditMessage;
21  import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder;
22  import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset;
23  import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
24  import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirParticipantObjectIdTypeCode;
25  import org.openehealth.ipf.commons.ihe.fhir.support.FhirQueryAuditStrategy;
26  
27  import java.util.Map;
28  
29  /**
30   * Strategy for auditing ITI-78 transactions
31   *
32   * @author Christian Ohr
33   * @since 3.4
34   */
35  class Iti78AuditStrategy extends FhirQueryAuditStrategy {
36  
37      protected Iti78AuditStrategy(boolean serverSide) {
38          super(serverSide);
39      }
40  
41      @Override
42      public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) {
43          return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobilePatientDemographicsQuery)
44                  .addPatients(auditDataset.getPatientIds())
45                  .setQueryParameters(
46                          "MobilePatientDemographicsQuery",
47                          FhirParticipantObjectIdTypeCode.MobilePatientDemographicsQuery,
48                          auditDataset.getQueryString())
49  
50                  .getMessages();
51      }
52  
53      @Override
54      public FhirQueryAuditDataset enrichAuditDatasetFromRequest(FhirQueryAuditDataset auditDataset, Object request, Map<String, Object> parameters) {
55          FhirQueryAuditDataset dataset = super.enrichAuditDatasetFromRequest(auditDataset, request, parameters);
56          if (request instanceof IdType) {
57              IdType idType = (IdType) request;
58              dataset.getPatientIds().add(idType.getValue());
59          }
60          return dataset;
61      }
62  
63      @Override
64      public boolean enrichAuditDatasetFromResponse(FhirQueryAuditDataset auditDataset, Object response, AuditContext auditContext) {
65          boolean result = super.enrichAuditDatasetFromResponse(auditDataset, response, auditContext);
66          if (auditContext.isIncludeParticipantsFromResponse()) {
67              // NOT in CX format....
68              /*
69              if (response instanceof Patient) {
70                  auditDataset.getPatientIds().add(((Patient) response).getId());
71              } else if (response instanceof Bundle) {
72                  ((Bundle) response).getEntry().forEach(bec ->
73                          auditDataset.getPatientIds().add((bec.getResource()).getId()));
74              }
75              */
76          }
77          return result;
78      }
79  }