View Javadoc
1   /*
2    * Copyright 2018 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.audit;
17  
18  import lombok.Getter;
19  import lombok.Setter;
20  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
21  import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset;
22  
23  import java.util.ArrayList;
24  import java.util.LinkedHashSet;
25  import java.util.List;
26  import java.util.Set;
27  
28  
29  /**
30   * Generic audit dataset for FHIR-based IHE transactions.
31   *
32   * @author Christian Ohr
33   * @since 3.1
34   */
35  public class FhirAuditDataset extends AuditDataset {
36  
37      /**
38       * Request payload.
39       */
40      @Getter @Setter
41      private String requestPayload;
42  
43      /**
44       * Local address
45       */
46      @Setter
47      private String localAddress;
48  
49      /**
50       * Remote address
51       */
52      @Setter @Getter
53      private String remoteAddress;
54  
55      /**
56       * Service endpoint URL
57       */
58      @Getter @Setter
59      private String serviceEndpointUrl;
60  
61      /**
62       * Patient IDs
63       */
64      @Getter
65      private final Set<String> patientIds = new LinkedHashSet<>();
66  
67      @Getter
68      private final List<HumanUser> humanUsers = new ArrayList<>();
69  
70      @Getter @Setter
71      private String sourceUserId;
72  
73      @Getter @Setter
74      private String destinationUserId;
75  
76      public FhirAuditDataset(boolean serverSide) {
77          super(serverSide);
78      }
79  
80      /**
81       * @return the first present patient ID
82       * or <code>null</code> when no patient IDs have been collected.
83       */
84      public String getPatientId() {
85          return patientIds.isEmpty() ? null : patientIds.iterator().next();
86      }
87  
88      /**
89       * @return The machine name or IP address
90       */
91      public String getLocalAddress() {
92          return localAddress != null ? localAddress : AuditUtils.getLocalIPAddress();
93      }
94  
95  }