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  
17  package org.openehealth.ipf.commons.ihe.xds.core.audit.event;
18  
19  import org.openehealth.ipf.commons.audit.AuditContext;
20  import org.openehealth.ipf.commons.audit.model.TypeValuePairType;
21  import org.openehealth.ipf.commons.audit.types.EventType;
22  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
23  import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder;
24  import org.openehealth.ipf.commons.ihe.xds.core.audit.codes.XdsParticipantObjectIdTypeCode;
25  import org.openehealth.ipf.commons.ihe.xds.core.audit.XdsQueryAuditDataset;
26  
27  import java.nio.charset.Charset;
28  import java.util.LinkedList;
29  import java.util.List;
30  
31  /**
32   * @author Christian Ohr
33   * @since 3.5
34   */
35  public class XdsQueryInformationBuilder extends QueryInformationBuilder<XdsQueryInformationBuilder> {
36  
37      public XdsQueryInformationBuilder(AuditContext auditContext,
38                                        XdsQueryAuditDataset auditDataset,
39                                        EventType eventType,
40                                        PurposeOfUse... purposesOfUse) {
41          super(auditContext, auditDataset, eventType, purposesOfUse);
42      }
43  
44      public XdsQueryInformationBuilder setQueryParameters(XdsQueryAuditDataset auditDataset, XdsParticipantObjectIdTypeCode participantObjectIdTypeCode) {
45          // Add QueryEncoding and HomeCommunityId as details, if applicable
46          List<TypeValuePairType> tvp = new LinkedList<>();
47          if (auditDataset.getQueryUuid() != null && !auditDataset.getQueryUuid().isEmpty()) {
48              tvp.add(new TypeValuePairType(QUERY_ENCODING, Charset.defaultCharset().toString()));
49          }
50          if (auditDataset.getHomeCommunityId() != null) {
51              tvp.add(new TypeValuePairType(
52                      URN_IHE_ITI_XCA_2010_HOME_COMMUNITY_ID,
53                      auditDataset.getHomeCommunityId()));
54          }
55          return setQueryParameters(
56                  auditDataset.getQueryUuid(),
57                  participantObjectIdTypeCode,
58                  auditDataset.getRequestPayload(),
59                  tvp);
60      }
61  }