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  
17  package org.openehealth.ipf.commons.ihe.fhir.iti83;
18  
19  import ca.uhn.fhir.rest.client.api.IGenericClient;
20  import ca.uhn.fhir.rest.gclient.IClientExecutable;
21  import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInput;
22  import org.hl7.fhir.dstu3.model.Parameters;
23  import org.hl7.fhir.dstu3.model.Patient;
24  import org.hl7.fhir.dstu3.model.StringType;
25  import org.openehealth.ipf.commons.ihe.fhir.ClientRequestFactory;
26  
27  import java.util.Map;
28  
29  /**
30   * Request Factory for Iti-83 requests
31   *
32   * @author Christian Ohr
33   * @since 3.4
34   */
35  public class Iti83ClientRequestFactory implements ClientRequestFactory<IOperationUntypedWithInput<Parameters>> {
36  
37      @Override
38      public IClientExecutable<IOperationUntypedWithInput<Parameters>, ?> getClientExecutable(IGenericClient client, Object requestData, Map<String, Object> parameters) {
39  
40          if (requestData instanceof Parameters) {
41              return getClientExecutable(client, (Parameters) requestData);
42          } else {
43              Parameters p = new Parameters();
44              parameters.entrySet().stream()
45                      .filter(entry -> Iti83Constants.ITI83_PARAMETERS.contains(entry.getKey()))
46                      .forEach(entry -> p.addParameter()
47                              .setName(entry.getKey())
48                              .setValue(new StringType(entry.getValue().toString())));
49              return getClientExecutable(client, p);
50          }
51  
52      }
53  
54      private IClientExecutable<IOperationUntypedWithInput<Parameters>, ?> getClientExecutable(IGenericClient client, Parameters requestData) {
55          return client.operation()
56                  .onType(Patient.class)
57                  .named(Iti83Constants.PIXM_OPERATION_NAME)
58                  .withParameters(requestData)
59                  .useHttpGet();
60      }
61  }