Skip to content

Commit

Permalink
Rad 610 qsh changes (#377)
Browse files Browse the repository at this point in the history
* CQL issue with connection pool exhaustion

* RAD-610 QueryingServerHelper new methods

* RAD-610 QueryingServerHelper test added
  • Loading branch information
marianbuenosayres authored Sep 20, 2023
1 parent 77c1635 commit 6987866
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fhir-helpers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.elimu.a2d2</groupId>
<artifactId>fhir-helpers</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<packaging>jar</packaging>
<name>fhir-helpers</name>
<url>http://maven.apache.org</url>
Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</parent>

<artifactId>fhir-query-helper-base</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<description>CDS Helper base</description>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.regex.Pattern;

import org.apache.http.HttpStatus;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -557,6 +558,61 @@ public FhirResponse<List<IBaseResource>> query(QueryBuilder builder) {
}
return new FhirResponse<>(new ArrayList<>(), -1, "not invoked due to internal error");
}

/**
*
* @param qb
* @return
*/
public FhirResponse<IBaseBundle> queryPageByLink(QueryBuilder qb) {
return queryPageByLink(qb.buildQuery(fhirUrl), qb.useCache());
}

/**
*
* @param url
* @return
*/
public FhirResponse<IBaseBundle> queryPageByLink(String url) {
return queryPageByLink(url, true);
}

/**
*
* @param url
* @return
*/
public FhirResponse<IBaseBundle> queryPageByLinkNoCache(String url) {
return queryPageByLink(url, false);
}

/**
*
* @param url
* @param useCache
* @return
*/
protected FhirResponse<IBaseBundle> queryPageByLink(String url, boolean useCache) {
try {
if(!useCache) {
avoidCache.set(Boolean.TRUE);
}
PerformanceHelper.getInstance().beginClock(QUERYINGSERVERHELPER, "queryPageByLink");
if (url == null) {
return null;
}
FhirResponse<IBaseResource> res = fetchServer("Bundle", url);
return new FhirResponse<>((IBaseBundle) res.getResult(), res.getResponseStatusCode(), res.getResponseStatusInfo());
} catch (Exception e) {
log.error( ERROR_MSG + e.getMessage() + ". [" + e.getClass().getName() + "]");
} finally {
PerformanceHelper.getInstance().endClock(QUERYINGSERVERHELPER, "queryPageByLink");
if (!useCache) {
avoidCache.set(Boolean.FALSE);
}
}
return new FhirResponse<>(null, -1, "not invoked due to internal error");
}

/**
* Creates a separate thread where a query to the FHIR server will be done.
Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-dstu2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</parent>

<artifactId>fhir-query-helper-dstu2</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<packaging>jar</packaging>
<description>CDS Helper</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;

import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -33,6 +34,7 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
Expand All @@ -41,7 +43,7 @@
import io.elimu.a2d2.cds.fhir.helper.QueryBuilder;
import io.elimu.a2d2.cds.fhir.helper.QueryingServerHelper;

@Ignore("No valid public FHIR servers available to test this")
//@Ignore("No valid public FHIR servers available to test this")
public class QueryingServerHelperTest {

private static QueryingServerHelper queryingServerHelper = spy(QueryingServerHelper.class);
Expand All @@ -59,6 +61,10 @@ public class QueryingServerHelperTest {
private static List<IBaseResource> iBaseList = new ArrayList<IBaseResource>();

private static FhirResponse<List<IBaseResource>> fhirResponse = null;

private static FhirResponse<IBaseBundle> fhirResponse2 = null;

private static FhirResponse<IBaseBundle> fhirResponse3 = null;

private static FhirResponse<IBaseResource> fhirResponseObservation = null;

Expand All @@ -75,6 +81,10 @@ public static void setup() {
iBaseList.add(patient);
iBaseList.add(observation);
fhirResponse = new FhirResponse<>(iBaseList, 200, "responseInfo");
Bundle bundle = new Bundle();
bundle.addLink().setRelation("next").setUrl("http://fhir2/someOtherUrl");
fhirResponse2 = new FhirResponse<>(bundle, 200, "responseInfo");
fhirResponse3 = new FhirResponse<>(new Bundle(), 200, "responseInfo2");
}

@Test
Expand Down Expand Up @@ -123,6 +133,24 @@ public void testQueryBuilder() {
Assert.assertNotNull(retval.getResult());
}

@Test
public void testQueryPage() {
doReturn(fhirResponse2).when(queryingServerHelper).fetchServer(eq("Bundle"), eq(FHIR2_URL + "/Patient?_count=50"));
doReturn(fhirResponse3).when(queryingServerHelper).fetchServer(eq("Bundle"), eq("http://fhir2/someOtherUrl"));
FhirResponse<IBaseBundle> retval = queryingServerHelper.queryPageByLink(new QueryBuilder().resourceType("Patient"));
Assert.assertNotNull(retval);
Assert.assertEquals(200, retval.getResponseStatusCode());
Bundle b = (Bundle) retval.getResult();
Assert.assertNotNull(b);
Assert.assertNotNull(b.getLink("next"));
FhirResponse<IBaseBundle> retval2 = queryingServerHelper.queryPageByLink(b.getLink("next").getUrl());
Assert.assertEquals(200, retval2.getResponseStatusCode());
Assert.assertEquals("responseInfo2", retval2.getResponseStatusInfo());
Bundle b2 = (Bundle) retval2.getResult();
Assert.assertNotNull(b2);
Assert.assertNull(b2.getLink("next"));
}

@Test
public void fhirQueryAsync() {
doReturn(fhirResponse).when(queryingServerHelper).queryServer(any(), any());
Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-dstu3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</parent>

<artifactId>fhir-query-helper-dstu3</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<packaging>jar</packaging>
<description>CDS Helper DSTU3</description>

Expand Down
2 changes: 1 addition & 1 deletion fhir-query-helper-r4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</parent>

<artifactId>fhir-query-helper-r4</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<packaging>jar</packaging>
<description>CDS Helper R4</description>

Expand Down
2 changes: 1 addition & 1 deletion oauth-helpers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</parent>

<artifactId>oauth-helpers</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<description>OAuth Helper</description>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<protobuf-java.version>3.21.8</protobuf-java.version>
<mockito.version>2.23.0</mockito.version>
<jedis.version>4.0.1</jedis.version>
<cds.helper.version>0.0.15</cds.helper.version>
<cds.helper.version>0.0.16</cds.helper.version>
<freemarker.version>2.3.30</freemarker.version>
<jacoco.version>0.8.7</jacoco.version>
<jaxb.api.version>2.3.1</jaxb.api.version>
Expand Down

0 comments on commit 6987866

Please sign in to comment.