Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 8575f7d

Browse files
RT-2007: qsh response body (#456)
* OT-2007 changes to QSH to return responseBody as a String
1 parent a33453b commit 8575f7d

15 files changed

Lines changed: 49 additions & 20 deletions

File tree

a2d2-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
<dependency>
311311
<groupId>io.elimu.a2d2</groupId>
312312
<artifactId>generic-helpers</artifactId>
313-
<version>0.0.21</version>
313+
<version>0.0.22</version>
314314
<scope>test</scope>
315315
</dependency>
316316
<!-- web development, including Tomcat and spring-webmvc -->

fhir-helpers/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<modelVersion>4.0.0</modelVersion>
2121
<groupId>io.elimu.a2d2</groupId>
2222
<artifactId>fhir-helpers</artifactId>
23-
<version>0.0.21</version>
23+
<version>0.0.22</version>
2424
<packaging>jar</packaging>
2525
<name>fhir-helpers</name>
2626
<url>http://maven.apache.org</url>

fhir-query-helper-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</parent>
2828

2929
<artifactId>fhir-query-helper-base</artifactId>
30-
<version>0.0.21</version>
30+
<version>0.0.22</version>
3131
<description>CDS Helper base</description>
3232

3333
<properties>

fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/FhirResponse.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,20 @@ public class FhirResponse<T> implements Serializable {
4040
* The response string related to the HTTP status
4141
*/
4242
private String responseStatusInfo;
43+
44+
private String responseBody;
4345

4446
public FhirResponse(T result, int responseStatusCode, String responseStatusInfo) {
47+
this(result, responseStatusCode, responseStatusInfo, null);
48+
}
49+
50+
public FhirResponse(T result, int responseStatusCode, String responseStatusInfo, String responseBody) {
4551
this.result = result;
4652
this.responseStatusCode = responseStatusCode;
4753
this.responseStatusInfo = responseStatusInfo;
54+
this.responseBody = responseBody;
4855
}
49-
56+
5057
/**
5158
* @return the result object for the query
5259
*/
@@ -82,4 +89,11 @@ public void setResponseStatusInfo(String responseStatusInfo) {
8289
this.responseStatusInfo = responseStatusInfo;
8390
}
8491

92+
public String getResponseBody() {
93+
return responseBody;
94+
}
95+
96+
public void setResponseBody(String responseBody) {
97+
this.responseBody = responseBody;
98+
}
8599
}

fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelperBase.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ protected <S> FhirResponse<S> runWithInterceptors(QueryingCallback<S> callback,
340340
} finally {
341341
client.notInUse();
342342
}
343-
return new FhirResponse<>(result, tracker.getResponseStatusCode(), tracker.getResponseStatusInfo());
343+
return new FhirResponse<>(result, tracker.getResponseStatusCode(), tracker.getResponseStatusInfo(), tracker.getResponseBody());
344344
}
345345

346346
public boolean hasCacheHeaderInterceptor(List<IClientInterceptor> interceptors) {
@@ -394,7 +394,7 @@ public U execute(FhirClientWrapper client) {
394394
}
395395
}, client);
396396
if (resourceBundle.getResult() == null) {
397-
return new FhirResponse<>(null, resourceBundle.getResponseStatusCode(), resourceBundle.getResponseStatusInfo());
397+
return new FhirResponse<>(null, resourceBundle.getResponseStatusCode(), resourceBundle.getResponseStatusInfo(), resourceBundle.getResponseBody());
398398
}
399399
return resourceBundle;
400400
}
@@ -482,18 +482,20 @@ private FhirResponse<IBaseResource> getResourceList(String resourceType, String
482482
if (usePath) {
483483
FhirResponse<IBaseResource> resp = fetchServer(resourceType, resourceQuery);
484484
List<IBaseResource> result = resp == null || resp.getResult() == null ? null : Arrays.asList(resp.getResult());
485-
resourceList = new FhirResponse<List<IBaseResource>>(result, resp.getResponseStatusCode(), resp.getResponseStatusInfo());
485+
resourceList = new FhirResponse<List<IBaseResource>>(result, resp.getResponseStatusCode(), resp.getResponseStatusInfo(), resp.getResponseBody());
486486
} else {
487487
resourceList = queryServer(resourceQuery, qb);
488488
}
489489
}
490490
if(resourceList != null) {
491491
if (resourceList.getResult() != null && resourceList.getResult().size()==1) {
492492
return new FhirResponse<>(resourceList.getResult().get(0),
493-
resourceList.getResponseStatusCode(), resourceList.getResponseStatusInfo());
493+
resourceList.getResponseStatusCode(), resourceList.getResponseStatusInfo(),
494+
resourceList.getResponseBody());
494495
} else {
495496
return new FhirResponse<>(null, resourceList.getResponseStatusCode(),
496-
resourceList.getResponseStatusInfo());
497+
resourceList.getResponseStatusInfo(),
498+
resourceList.getResponseBody());
497499
}
498500
} else {
499501
return new FhirResponse<>(null, HttpStatus.SC_INTERNAL_SERVER_ERROR, "Unable to get resources");
@@ -632,7 +634,7 @@ protected FhirResponse<IBaseBundle> queryPageByLink(String url, boolean useCache
632634
return null;
633635
}
634636
FhirResponse<IBaseResource> res = fetchServer("Bundle", url);
635-
return new FhirResponse<>((IBaseBundle) res.getResult(), res.getResponseStatusCode(), res.getResponseStatusInfo());
637+
return new FhirResponse<>((IBaseBundle) res.getResult(), res.getResponseStatusCode(), res.getResponseStatusInfo(), res.getResponseBody());
636638
} catch (Exception e) {
637639
log.error( ERROR_MSG + e.getMessage() + ". [" + e.getClass().getName() + "]");
638640
} finally {

fhir-query-helper-base/src/main/java/io/elimu/a2d2/cds/fhir/helper/RequestDataInterceptor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package io.elimu.a2d2.cds.fhir.helper;
1616

1717
import java.io.IOException;
18+
import java.io.InputStream;
1819
import java.util.List;
1920
import java.util.Map;
2021
import org.slf4j.Logger;
@@ -29,6 +30,7 @@ public class RequestDataInterceptor implements IClientInterceptor {
2930

3031
private int responseStatusCode = -1;
3132
private String responseStatusInfo = "not invoked";
33+
private String responseBody = null;
3234

3335
public int getResponseStatusCode() {
3436
return responseStatusCode;
@@ -37,6 +39,10 @@ public int getResponseStatusCode() {
3739
public String getResponseStatusInfo() {
3840
return responseStatusInfo;
3941
}
42+
43+
public String getResponseBody() {
44+
return responseBody;
45+
}
4046

4147
@Override
4248
public void interceptRequest(IHttpRequest theRequest) {
@@ -80,6 +86,13 @@ public void interceptResponse(IHttpResponse theResponse) throws IOException {
8086
log.trace("HTTP response status info: " + theResponse.getStatusInfo());
8187
this.responseStatusInfo = theResponse.getStatusInfo();
8288
}
89+
try {
90+
theResponse.bufferEntity();
91+
InputStream respBodyIn = theResponse.readEntity();
92+
this.responseBody = new String(respBodyIn.readAllBytes());
93+
} catch (Exception e) {
94+
log.trace("HTTP response body couldn't be read", e);
95+
}
8396
}
8497

8598
}

fhir-query-helper-dstu2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</parent>
2626

2727
<artifactId>fhir-query-helper-dstu2</artifactId>
28-
<version>0.0.21</version>
28+
<version>0.0.22</version>
2929
<packaging>jar</packaging>
3030
<description>CDS Helper</description>
3131

fhir-query-helper-dstu2/src/main/java/io/elimu/a2d2/cds/fhir/helper/QueryingServerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public List<IBaseResource> execute(FhirClientWrapper client) {
120120
}
121121
}, client);
122122
if (resourceBundle.getResult() == null) {
123-
return new FhirResponse<>(null, resourceBundle.getResponseStatusCode(), resourceBundle.getResponseStatusInfo());
123+
return new FhirResponse<>(null, resourceBundle.getResponseStatusCode(), resourceBundle.getResponseStatusInfo(), resourceBundle.getResponseBody());
124124
}
125125
return resourceBundle;
126126
}

fhir-query-helper-dstu3/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</parent>
2727

2828
<artifactId>fhir-query-helper-dstu3</artifactId>
29-
<version>0.0.21</version>
29+
<version>0.0.22</version>
3030
<packaging>jar</packaging>
3131
<description>CDS Helper DSTU3</description>
3232

fhir-query-helper-dstu3/src/main/java/io/elimu/a2d2/cds/fhir/helper/dstu3/QueryingServerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public List<IBaseResource> execute(FhirClientWrapper client) {
128128
}
129129
}, client);
130130
if (resourceBundle.getResult() == null) {
131-
return new FhirResponse<>(null, resourceBundle.getResponseStatusCode(), resourceBundle.getResponseStatusInfo());
131+
return new FhirResponse<>(null, resourceBundle.getResponseStatusCode(), resourceBundle.getResponseStatusInfo(), resourceBundle.getResponseBody());
132132
}
133133
return resourceBundle;
134134
}

0 commit comments

Comments
 (0)