use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class PatientLinkBuilderTest method onePageTest.
@Test
public void onePageTest() {
PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=10");
assertTrue(paging.isPagingRequested());
assertTrue(paging.isFirstPage());
assertEquals(10, paging.getPageSize());
Bundle bundle = new Bundle();
TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(new Patient()));
assertTrue(bundle.getLink().isEmpty());
paging.addLinks(bundle);
assertNotNull(bundle.getLink(Constants.LINK_SELF));
assertNotNull(bundle.getLink(Constants.LINK_FIRST));
UriComponents firstLink = UriComponentsBuilder.fromUriString(bundle.getLink(Constants.LINK_FIRST).getUrl()).build();
assertEquals("10", firstLink.getQueryParams().getFirst(Constants.PARAM_COUNT));
assertNull(bundle.getLink(Constants.LINK_NEXT));
}
use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class PatientLinkBuilderTest method missingCountTest.
@Test
public void missingCountTest() {
// Missing _count
PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&cursor=999");
assertFalse(paging.isPagingRequested());
assertTrue(paging.isFirstPage());
assertEquals(PatientLinkBuilder.MAX_PAGE_SIZE, paging.getPageSize());
Bundle bundle = new Bundle();
assertTrue(bundle.getLink().isEmpty());
paging.addLinks(bundle);
assertTrue(bundle.getLink().isEmpty());
}
use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class PatientLinkBuilderTest method emptyPageTest.
@Test
public void emptyPageTest() {
PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=10");
assertTrue(paging.isPagingRequested());
assertTrue(paging.isFirstPage());
assertEquals(10, paging.getPageSize());
Bundle bundle = new Bundle();
assertTrue(bundle.getLink().isEmpty());
paging.addLinks(bundle);
assertNotNull(bundle.getLink(Constants.LINK_SELF));
assertNotNull(bundle.getLink(Constants.LINK_FIRST));
}
use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProvider method searchByCoverageContractAndYearMonth.
@Trace
private Bundle searchByCoverageContractAndYearMonth(// of relational search is more common.
TokenParam coverageId, LocalDate yearMonth, RequestDetails requestDetails) {
checkCoverageId(coverageId);
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
// requested.
if (!requestHeader.isMBIinIncludeIdentifiers() || requestHeader.isHICNinIncludeIdentifiers()) {
throw new InvalidRequestException(String.format("This endpoint requires the '%s: mbi' header.", CommonHeaders.HEADER_NAME_INCLUDE_IDENTIFIERS));
}
PatientLinkBuilder paging = new PatientLinkBuilder(requestDetails.getCompleteUrl());
Operation operation = new Operation(Operation.Endpoint.V1_PATIENT);
operation.setOption("by", "coverageContractForYearMonth");
requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
operation.publishOperationName();
List<Beneficiary> matchingBeneficiaries = fetchBeneficiariesByContractAndYearMonth(coverageId, yearMonth, paging);
boolean hasAnotherPage = matchingBeneficiaries.size() > paging.getPageSize();
if (hasAnotherPage) {
matchingBeneficiaries = matchingBeneficiaries.subList(0, paging.getPageSize());
paging = new PatientLinkBuilder(paging, hasAnotherPage);
}
List<IBaseResource> patients = matchingBeneficiaries.stream().map(b -> BeneficiaryTransformer.transform(metricRegistry, b, requestHeader)).collect(Collectors.toList());
Bundle bundle = TransformerUtils.createBundle(patients, paging, loadedFilterManager.getTransactionTime());
TransformerUtils.workAroundHAPIIssue1585(requestDetails);
return bundle;
}
use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProvider method searchByCoverageContractAndYearMonth.
@Trace
private Bundle searchByCoverageContractAndYearMonth(// of relational search is more common.
TokenParam coverageId, LocalDate yearMonth, RequestDetails requestDetails) {
checkCoverageId(coverageId);
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
// requested.
if (!requestHeader.isMBIinIncludeIdentifiers() || requestHeader.isHICNinIncludeIdentifiers()) {
throw new InvalidRequestException(String.format("This endpoint requires the '%s: mbi' header.", CommonHeaders.HEADER_NAME_INCLUDE_IDENTIFIERS));
}
PatientLinkBuilder paging = new PatientLinkBuilder(requestDetails.getCompleteUrl());
Operation operation = new Operation(Operation.Endpoint.V2_PATIENT);
operation.setOption("by", "coverageContractForYearMonth");
requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
operation.publishOperationName();
List<Beneficiary> matchingBeneficiaries = fetchBeneficiariesByContractAndYearMonth(coverageId, yearMonth, paging);
boolean hasAnotherPage = matchingBeneficiaries.size() > paging.getPageSize();
if (hasAnotherPage) {
matchingBeneficiaries = matchingBeneficiaries.subList(0, paging.getPageSize());
paging = new PatientLinkBuilder(paging, hasAnotherPage);
}
List<IBaseResource> patients = matchingBeneficiaries.stream().map(b -> BeneficiaryTransformerV2.transform(metricRegistry, b, requestHeader)).collect(Collectors.toList());
Bundle bundle = TransformerUtilsV2.createBundle(patients, paging, loadedFilterManager.getTransactionTime());
TransformerUtilsV2.workAroundHAPIIssue1585(requestDetails);
return bundle;
}
Aggregations