Skip to content

Commit

Permalink
use constants, remove unused variables
Browse files Browse the repository at this point in the history
  • Loading branch information
aschey-forpeople committed Jan 28, 2025
1 parent 71cf146 commit 4522d24
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import gov.cms.bfd.server.war.stu3.providers.ExplanationOfBenefitResourceProvider;
import gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.http.client.utils.URIBuilder;
import org.hl7.fhir.dstu3.model.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* PagingArguments encapsulates the arguments related to paging for the ExplanationOfBenefit,
* Patient, and Coverage requests.
*/
public final class OffsetLinkBuilder implements LinkBuilder {

private static final Logger LOGGER =
LoggerFactory.getLogger(ExplanationOfBenefitResourceProvider.class);

/** The page size for paging. */
private final Optional<Integer> pageSize;

Expand All @@ -45,6 +38,9 @@ public final class OffsetLinkBuilder implements LinkBuilder {
*/
private int numTotalResults = -1;

/** Start index request parameter. */
private static final String PARAM_START_INDEX = "startIndex";

/**
* Instantiates a new Offset link builder.
*
Expand All @@ -56,7 +52,8 @@ public OffsetLinkBuilder(RequestDetails requestDetails, String resource) {
StringUtils.parseIntegersFromRequest(requestDetails, Constants.PARAM_COUNT).stream()
.findFirst();
this.startIndex =
StringUtils.parseIntegersFromRequest(requestDetails, "startIndex").stream().findFirst();
StringUtils.parseIntegersFromRequest(requestDetails, PARAM_START_INDEX).stream()
.findFirst();
this.serverBase = requestDetails.getServerBaseForRequest();
this.resource = resource;
this.requestDetails = requestDetails;
Expand Down Expand Up @@ -220,16 +217,15 @@ private String createPageLink(int startIndex) {
Map<String, String[]> params = new HashMap<>(requestDetails.getParameters());

// Add in paging related changes.
params.put("startIndex", new String[] {String.valueOf(startIndex)});
params.put("_count", new String[] {String.valueOf(getPageSize())});
params.put(PARAM_START_INDEX, new String[] {String.valueOf(startIndex)});
params.put(Constants.PARAM_COUNT, new String[] {String.valueOf(getPageSize())});

try {
// Setup URL base and resource.
URIBuilder uri = new URIBuilder(serverBase + resource);

// Create query parameters by iterating thru all params entry sets. Handle multi values for
// Create query parameters by iterating through all params entry sets. Handle multi values for
// the same parameter key.
ArrayList<String> queryParams = new ArrayList<String>();
for (Map.Entry<String, String[]> paramSet : params.entrySet()) {
for (String param : paramSet.getValue()) {
uri.addParameter(paramSet.getKey(), param);
Expand Down

0 comments on commit 4522d24

Please sign in to comment.