diff --git a/fhir-helpers/pom.xml b/fhir-helpers/pom.xml
index 9bd4baf8..a07da57c 100644
--- a/fhir-helpers/pom.xml
+++ b/fhir-helpers/pom.xml
@@ -20,7 +20,7 @@
4.0.0
io.elimu.a2d2
fhir-helpers
- 0.0.17
+ 0.0.18
jar
fhir-helpers
http://maven.apache.org
diff --git a/fhir-query-helper-base/pom.xml b/fhir-query-helper-base/pom.xml
index e6a6f968..4606d951 100644
--- a/fhir-query-helper-base/pom.xml
+++ b/fhir-query-helper-base/pom.xml
@@ -27,7 +27,7 @@
fhir-query-helper-base
- 0.0.17
+ 0.0.18
CDS Helper base
diff --git a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java
index 158b0e06..6b628607 100644
--- a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java
+++ b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java
@@ -35,6 +35,7 @@
import java.util.regex.Pattern;
import org.apache.http.HttpStatus;
+import org.apache.http.client.HttpClient;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.Logger;
@@ -116,6 +117,12 @@ public QueryingServerHelperBase(String url, FhirVersionAbs fhirVersion, FhirVers
log.info("Cache config: {}", (cacheService == null) ? "NO_CACHE" : cacheService.getCacheType());
}
+
+ public void setHttpClient(HttpClient client) {
+ for (int count = 0; count < clients.size(); count++) {
+ clients.next().getFhirContext().getRestfulClientFactory().setHttpClient(client);
+ }
+ }
private synchronized static Rotator getClientInstance(FhirContext ctxt, String fhirUrl) {
String key = genClientKey(ctxt, fhirUrl);
diff --git a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/Rotator.java b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/Rotator.java
index 6c307714..65a81efa 100644
--- a/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/Rotator.java
+++ b/fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/Rotator.java
@@ -41,6 +41,9 @@ public synchronized T next() {
iter = rotation.iterator();
}
return iter.next();
+ }
+ public int size() {
+ return rotation.size();
}
}
diff --git a/fhir-query-helper-dstu2/pom.xml b/fhir-query-helper-dstu2/pom.xml
index 2589ac75..5f27fa78 100644
--- a/fhir-query-helper-dstu2/pom.xml
+++ b/fhir-query-helper-dstu2/pom.xml
@@ -25,7 +25,7 @@
fhir-query-helper-dstu2
- 0.0.17
+ 0.0.18
jar
CDS Helper
diff --git a/fhir-query-helper-dstu2/src/test/java/io/elimu/a2d2/cds/fhir/helper/test/QueryingServerHelperTest.java b/fhir-query-helper-dstu2/src/test/java/io/elimu/a2d2/cds/fhir/helper/test/QueryingServerHelperTest.java
index 984b38f6..a6922e3e 100644
--- a/fhir-query-helper-dstu2/src/test/java/io/elimu/a2d2/cds/fhir/helper/test/QueryingServerHelperTest.java
+++ b/fhir-query-helper-dstu2/src/test/java/io/elimu/a2d2/cds/fhir/helper/test/QueryingServerHelperTest.java
@@ -16,7 +16,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -25,12 +24,20 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
@@ -95,6 +102,8 @@ public void testQSH() throws Exception {
client.setDontValidateConformance(true);
client.setEncoding(EncodingEnum.JSON);*/
QueryingServerHelper qsh = new QueryingServerHelper(url);
+ HttpClient client = expectGet("https://hapi.fhir.org/baseDstu2/Patient/131?_format=json", 200, "{\"resourceType\":\"Patient\", \"id\":\"131\"}");
+ qsh.setHttpClient(client);
FhirResponse> resp = qsh.getResourceByIdInPathResponse("Patient", patientId);
Assert.assertEquals(200, resp.getResponseStatusCode());
System.out.println(resp.getResult());
@@ -111,6 +120,24 @@ public void testQSH() throws Exception {
Assert.assertEquals(200, resp.getStatusLine().getStatusCode());*/
}
+ private HttpClient expectGet(String url, int httpStatus, String responseBody) throws Exception {
+ HttpClient client = Mockito.mock(HttpClient.class);
+ Mockito.when(client.execute(Mockito.any(HttpGet.class))).thenAnswer(new Answer() {
+ @Override
+ public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
+ HttpGet get = (HttpGet) invocation.getArgument(0);
+ Assert.assertEquals(url, get.getURI().toASCIIString());
+ HttpResponse response = Mockito.mock(HttpResponse.class);
+ StatusLine statusLine = Mockito.mock(StatusLine.class);
+ Mockito.when(statusLine.getStatusCode()).thenReturn(httpStatus);
+ Mockito.when(response.getStatusLine()).thenReturn(statusLine);
+ Mockito.when(response.getEntity()).thenReturn(new StringEntity(responseBody, ContentType.APPLICATION_JSON));
+ return response;
+ }
+ });
+ return client;
+ }
+
@Test
public void testQueryBuilder() {
doReturn(fhirResponse).when(queryingServerHelper).queryServer(eq(FHIR2_URL + "/Patient?_count=1&_sort=-_lastUpdated"),
diff --git a/fhir-query-helper-dstu3/pom.xml b/fhir-query-helper-dstu3/pom.xml
index a643923d..58decb16 100644
--- a/fhir-query-helper-dstu3/pom.xml
+++ b/fhir-query-helper-dstu3/pom.xml
@@ -26,7 +26,7 @@
fhir-query-helper-dstu3
- 0.0.17
+ 0.0.18
jar
CDS Helper DSTU3
diff --git a/fhir-query-helper-r4/pom.xml b/fhir-query-helper-r4/pom.xml
index 9c25817a..d08c1c92 100644
--- a/fhir-query-helper-r4/pom.xml
+++ b/fhir-query-helper-r4/pom.xml
@@ -26,7 +26,7 @@
fhir-query-helper-r4
- 0.0.17
+ 0.0.18
jar
CDS Helper R4
diff --git a/pom.xml b/pom.xml
index 760f3542..842d532c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
3.21.8
2.23.0
4.0.1
- 0.0.17
+ 0.0.18
2.3.30
0.8.7
2.3.1