1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.commons.ihe.fhir.pcc44;
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.ICriterion;
22 import ca.uhn.fhir.rest.gclient.IQuery;
23 import org.hl7.fhir.dstu3.model.Bundle;
24 import org.hl7.fhir.instance.model.api.IBaseBundle;
25 import org.hl7.fhir.instance.model.api.IBaseResource;
26 import org.openehealth.ipf.commons.ihe.fhir.ClientRequestFactory;
27 import org.openehealth.ipf.commons.ihe.fhir.Constants;
28
29 import java.util.Map;
30
31
32
33
34
35
36
37 public class Pcc44ClientRequestFactory implements ClientRequestFactory<IQuery<Bundle>> {
38
39 @Override
40 public IClientExecutable<IQuery<Bundle>, ?> getClientExecutable(IGenericClient client, Object requestData, Map<String, Object> parameters) {
41 IQuery<IBaseBundle> query;
42 String queriedResourceType = (String)parameters.get(Constants.FHIR_RESOURCE_TYPE_HEADER);
43 if (requestData instanceof ICriterion) {
44 query = client.search()
45 .forResource(queriedResourceType)
46 .where((ICriterion<?>) requestData);
47 } else {
48 query = client.search()
49 .byUrl(requestData.toString());
50 }
51 if (parameters.containsKey(Constants.FHIR_COUNT)) {
52 query.count(Integer.parseInt(parameters.get(Constants.FHIR_COUNT).toString()));
53 }
54 return query.returnBundle(Bundle.class);
55 }
56
57 }