Skip to content

Commit

Permalink
Revert ab2d 6276 (#421)
Browse files Browse the repository at this point in the history
 Revert Post request to BFD
  • Loading branch information
smirnovaae authored Jan 14, 2025
1 parent a88824e commit 5654a3a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gov.cms.ab2d.bfd.client;

import ca.uhn.fhir.rest.api.SearchStyleEnum;
import ca.uhn.fhir.rest.gclient.TokenClientParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
Expand Down Expand Up @@ -162,8 +161,7 @@ public IBaseBundle requestPartDEnrolleesFromServer(FhirVersion version, String c
.withAdditionalHeader(BFDClient.BFD_HDR_BULK_CLIENTID, contractNumber)
.withAdditionalHeader(BFDClient.BFD_HDR_BULK_JOBID, getJobId())
.withAdditionalHeader(INCLUDE_IDENTIFIERS_HEADER, MBI_HEADER_VALUE)
.count(contractToBenePageSize)
.usingStyle(SearchStyleEnum.POST);
.count(contractToBenePageSize);
log.info("Executing request to get Part D Enrollees " + request);
return request.returnBundle(version.getBundleClass())
.encodedJson()
Expand Down Expand Up @@ -191,8 +189,7 @@ public IBaseBundle requestPartDEnrolleesFromServer(FhirVersion version, String c
.withAdditionalHeader(BFDClient.BFD_HDR_BULK_CLIENTID, contractNumber)
.withAdditionalHeader(BFDClient.BFD_HDR_BULK_JOBID, getJobId())
.withAdditionalHeader(INCLUDE_IDENTIFIERS_HEADER, MBI_HEADER_VALUE)
.count(contractToBenePageSize)
.usingStyle(SearchStyleEnum.POST);
.count(contractToBenePageSize);
log.info("Executing request to get Part D Enrollees " + request);
return request.returnBundle(version.getBundleClass())
.encodedJson()
Expand Down
31 changes: 8 additions & 23 deletions ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
import com.newrelic.api.agent.Trace;
import gov.cms.ab2d.fhir.FhirVersion;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.client.methods.HttpGet;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -54,32 +50,21 @@ public BFDSearchImpl(HttpClient httpClient, Environment environment, BfdClientVe
@Override
public IBaseBundle searchEOB(long patientId, OffsetDateTime since, OffsetDateTime until, int pageSize, String bulkJobId, FhirVersion version, String contractNum) throws IOException {
String urlLocation = bfdClientVersions.getUrl(version);
StringBuilder url = new StringBuilder(urlLocation + "ExplanationOfBenefit?patient=" + patientId + "&excludeSAMHSA=true");

HttpPost request = new HttpPost(urlLocation + "ExplanationOfBenefit/_search");
// No active profiles means use JSON
if (environment.getActiveProfiles().length == 0) {
request.addHeader("Accept", "application/fhir+json;q=1.0, application/json+fhir;q=0.9");
}
request.addHeader(HttpHeaders.ACCEPT, "gzip");
request.addHeader(HttpHeaders.ACCEPT_CHARSET, "utf-8");
request.addHeader(BFDClient.BFD_HDR_BULK_CLIENTID, contractNum);
request.addHeader(BFDClient.BFD_HDR_BULK_JOBID, bulkJobId);

List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("patient", "" + patientId));
params.add(new BasicNameValuePair("excludeSAMHSA", "true"));
if (since != null) {
params.add(new BasicNameValuePair("_lastUpdated", "ge" + since));
url.append("&_lastUpdated=ge").append(since);
}

if (until != null) {
params.add(new BasicNameValuePair("_lastUpdated", "le" + until));
url.append("&_lastUpdated=le").append(until);
}

if (pageSize > 0) {
params.add(new BasicNameValuePair("_count", "" + pageSize));
url.append("&_count=").append(pageSize);
}
request.setEntity(new UrlEncodedFormEntity(params));

HttpGet request = new HttpGet(url.toString());
log.info("Executing BFD Search Request " + request);

byte[] responseBytes = getEOBSFromBFD(patientId, request);
Expand All @@ -91,7 +76,7 @@ public IBaseBundle searchEOB(long patientId, OffsetDateTime since, OffsetDateTim
Method exists to track connection to BFD for New Relic
*/
@Trace
private byte[] getEOBSFromBFD(long patientId, HttpPost request) throws IOException {
private byte[] getEOBSFromBFD(long patientId, HttpGet request) throws IOException {
byte[] responseBytes;
try (CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(request)) {
int status = response.getStatusLine().getStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void setupBFDClient() throws IOException {

// Ensure timeouts are working.
MockUtils.createMockServerExpectation(
"/v2/fhir/ExplanationOfBenefit/_search",
"/v2/fhir/ExplanationOfBenefit",
HttpStatus.SC_OK,
getRawJson(SAMPLE_EOB_BUNDLE),
List.of(Parameter.param("patient", TEST_PATIENT_ID.toString()),
Expand All @@ -74,7 +74,7 @@ public static void setupBFDClient() throws IOException {
);

MockUtils.createMockServerExpectation(
"/v2/fhir/Patient/_search",
"/v2/fhir/Patient",
HttpStatus.SC_OK,
getRawJson(SAMPLE_PATIENT_BUNDLE),
List.of(Parameter.param("_has:Coverage.extension",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void setupBFDClient() throws IOException {

// Ensure timeouts are working.
MockUtils.createMockServerExpectation(
"/v1/fhir/ExplanationOfBenefit/_search",
"/v1/fhir/ExplanationOfBenefit",
HttpStatus.SC_OK,
StringUtils.EMPTY,
Collections.singletonList(Parameter.param("patient", TEST_SLOW_PATIENT_ID.toString())),
Expand All @@ -92,15 +92,15 @@ public static void setupBFDClient() throws IOException {

for (String patientId : TEST_PATIENT_IDS) {
MockUtils.createMockServerExpectation(
"/v1/fhir/Patient/_search" + patientId,
"/v1/fhir/Patient/" + patientId,
HttpStatus.SC_OK,
getRawJson(SAMPLE_PATIENT_PATH_PREFIX + patientId + ".json"),
List.of(),
MOCK_PORT_V1
);

MockUtils.createMockServerExpectation(
"/v1/fhir/ExplanationOfBenefit/_search",
"/v1/fhir/ExplanationOfBenefit",
HttpStatus.SC_OK,
getRawJson(SAMPLE_EOB_PATH_PREFIX + patientId + ".json"),
List.of(Parameter.param("patient", patientId),
Expand All @@ -110,7 +110,7 @@ public static void setupBFDClient() throws IOException {
}

MockUtils.createMockServerExpectation(
"/v1/fhir/Patient/_search",
"/v1/fhir/Patient",
HttpStatus.SC_OK,
getRawJson(SAMPLE_PATIENT_PATH_PREFIX + "/bundle/patientbundle.json"),
List.of(),
Expand All @@ -119,14 +119,14 @@ public static void setupBFDClient() throws IOException {

// Patient that exists, but has no records
MockUtils.createMockServerExpectation(
"/v1/fhir/Patient/_search" + TEST_NO_RECORD_PATIENT_ID,
"/v1/fhir/Patient/" + TEST_NO_RECORD_PATIENT_ID,
HttpStatus.SC_OK,
getRawJson(SAMPLE_PATIENT_PATH_PREFIX + TEST_NO_RECORD_PATIENT_ID + ".json"),
List.of(),
MOCK_PORT_V1
);
MockUtils.createMockServerExpectation(
"/v1/fhir/ExplanationOfBenefit/_search",
"/v1/fhir/ExplanationOfBenefit",
HttpStatus.SC_OK,
getRawJson(SAMPLE_EOB_PATH_PREFIX + TEST_NO_RECORD_PATIENT_ID + ".json"),
List.of(Parameter.param("patient", TEST_NO_RECORD_PATIENT_ID.toString()),
Expand All @@ -135,14 +135,14 @@ public static void setupBFDClient() throws IOException {
);

MockUtils.createMockServerExpectation(
"/v1/fhir/Patient/_search" + TEST_NO_RECORD_PATIENT_ID_MBI,
"/v1/fhir/Patient/" + TEST_NO_RECORD_PATIENT_ID_MBI,
HttpStatus.SC_OK,
getRawJson(SAMPLE_PATIENT_PATH_PREFIX + TEST_NO_RECORD_PATIENT_ID_MBI + ".json"),
List.of(),
MOCK_PORT_V1
);
MockUtils.createMockServerExpectation(
"/v1/fhir/ExplanationOfBenefit/_search",
"/v1/fhir/ExplanationOfBenefit",
HttpStatus.SC_OK,
getRawJson(SAMPLE_EOB_PATH_PREFIX + TEST_NO_RECORD_PATIENT_ID_MBI + ".json"),
List.of(Parameter.param("patient", TEST_NO_RECORD_PATIENT_ID_MBI.toString()),
Expand All @@ -153,7 +153,7 @@ public static void setupBFDClient() throws IOException {
// Create mocks for pages of the results
for (String startIndex : List.of("10", "20", "30")) {
MockUtils.createMockServerExpectation(
"/v1/fhir/ExplanationOfBenefit/_search",
"/v1/fhir/ExplanationOfBenefit",
HttpStatus.SC_OK,
getRawJson(SAMPLE_EOB_PATH_PREFIX + TEST_PATIENT_ID + "_" + startIndex + ".json"),
List.of(Parameter.param("patient", TEST_PATIENT_ID.toString()),
Expand All @@ -166,7 +166,7 @@ public static void setupBFDClient() throws IOException {

for (String month : CONTRACT_MONTHS) {
MockUtils.createMockServerExpectation(
"/v1/fhir/Patient/_search",
"/v1/fhir/Patient/",
HttpStatus.SC_OK,
getRawJson(SAMPLE_PATIENT_PATH_PREFIX + "/bundle/patientbundle.json"),
List.of(Parameter.param("_has:Coverage.extension",
Expand Down Expand Up @@ -247,7 +247,7 @@ void shouldNotHaveNextBundle() {
"Should have no next link since all the resources are in the bundle");
}

// @Test
@Test
void shouldHaveNextBundle() {
org.hl7.fhir.dstu3.model.Bundle response = (org.hl7.fhir.dstu3.model.Bundle) bbc.requestEOBFromServer(STU3, TEST_PATIENT_ID, CONTRACT);

Expand Down
53 changes: 17 additions & 36 deletions ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/MockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static String getRawJson(String path) throws IOException {
}

/**
* Helper method that configures the mock server to respond to a given POST request
* Helper method that configures the mock server to respond to a given GET request
*
* @param path The path segment of the URL that would be received by BlueButton
* @param respCode The desired HTTP response code
Expand All @@ -47,41 +47,22 @@ static MockServerClient createMockServerExpectation(String path, int respCode, S
static MockServerClient createMockServerExpectation(String path, int respCode, String payload,
List<Parameter> qStringParams, int delayMs, int port) {
MockServerClient mock = new MockServerClient("localhost", port);
if (path.contains("/fhir/metadata")) {
mock.when(
HttpRequest.request()
.withMethod("GET")
.withPath(path)
.withBody(params(qStringParams)),
Times.unlimited()
).respond(
org.mockserver.model.HttpResponse.response()
.withStatusCode(respCode)
.withHeader(
new Header("Content-Type",
"application/json;charset=UTF-8")
)
.withBody(payload)
.withDelay(TimeUnit.MILLISECONDS, delayMs)
);
} else {
mock.when(
HttpRequest.request()
.withMethod("POST")
.withPath(path)
.withBody(params(qStringParams)),
Times.unlimited()
).respond(
org.mockserver.model.HttpResponse.response()
.withStatusCode(respCode)
.withHeader(
new Header("Content-Type",
"application/json;charset=UTF-8")
)
.withBody(payload)
.withDelay(TimeUnit.MILLISECONDS, delayMs)
);
}
mock.when(
HttpRequest.request()
.withMethod("GET")
.withPath(path)
.withQueryStringParameters(qStringParams),
Times.unlimited()
).respond(
org.mockserver.model.HttpResponse.response()
.withStatusCode(respCode)
.withHeader(
new Header("Content-Type",
"application/json;charset=UTF-8")
)
.withBody(payload)
.withDelay(TimeUnit.MILLISECONDS, delayMs)
);
return mock;
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {

// AB2D libraries
fhirVersion='2.1.0'
bfdVersion='3.2.0'
bfdVersion='2.5.0'
aggregatorVersion='2.0.1'
filtersVersion='2.1.0'
eventClientVersion='3.2.1'
Expand Down

0 comments on commit 5654a3a

Please sign in to comment.