use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProvider method searchByCoverageContractByFieldName.
public Bundle searchByCoverageContractByFieldName(// of relational search is more common.
TokenParam coverageId, String cursor, RequestDetails requestDetails) {
checkCoverageId(coverageId);
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(requestDetails);
PatientLinkBuilder paging = new PatientLinkBuilder(requestDetails.getCompleteUrl());
Operation operation = new Operation(Operation.Endpoint.V2_PATIENT);
operation.setOption("by", "coverageContract");
requestHeader.getNVPairs().forEach((n, v) -> operation.setOption(n, v.toString()));
operation.publishOperationName();
List<Beneficiary> matchingBeneficiaries = fetchBeneficiaries(coverageId, requestHeader, 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(beneficiary -> {
// Null out the unhashed HICNs
beneficiary.setHicnUnhashed(Optional.empty());
Patient patient = BeneficiaryTransformerV2.transform(metricRegistry, beneficiary, requestHeader);
return patient;
}).collect(Collectors.toList());
Bundle bundle = TransformerUtilsV2.createBundle(patients, paging, loadedFilterManager.getTransactionTime());
TransformerUtilsV2.workAroundHAPIIssue1585(requestDetails);
return bundle;
}
use of gov.cms.bfd.server.war.commons.PatientLinkBuilder in project beneficiary-fhir-data by CMSgov.
the class PatientLinkBuilderTest method noCountTest.
@Test
public void noCountTest() {
PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL);
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 testMdcLogsInAddResourcesToBundle.
@Test
public void testMdcLogsInAddResourcesToBundle() {
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().setId("Id")));
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));
bundle = new Bundle();
TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(new Coverage().setBeneficiary(new Reference("Patient/Id"))));
assertTrue(bundle.getLink().isEmpty());
paging.addLinks(bundle);
assertNotNull(bundle.getLink(Constants.LINK_SELF));
assertNotNull(bundle.getLink(Constants.LINK_FIRST));
firstLink = UriComponentsBuilder.fromUriString(bundle.getLink(Constants.LINK_FIRST).getUrl()).build();
assertEquals("10", firstLink.getQueryParams().getFirst(Constants.PARAM_COUNT));
assertNull(bundle.getLink(Constants.LINK_NEXT));
bundle = new Bundle();
TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(new ExplanationOfBenefit().setPatient(new Reference("Patient/Id"))));
assertTrue(bundle.getLink().isEmpty());
paging.addLinks(bundle);
assertNotNull(bundle.getLink(Constants.LINK_SELF));
assertNotNull(bundle.getLink(Constants.LINK_FIRST));
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 fullPageTest.
@Test
public void fullPageTest() {
// test a page with a page size of 1 and 1 patient in the result
PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=1");
assertTrue(paging.isPagingRequested());
assertTrue(paging.isFirstPage());
assertEquals(1, paging.getPageSize());
Bundle bundle = new Bundle();
Patient patient = new Patient();
patient.setId("1");
TransformerUtils.addResourcesToBundle(bundle, Collections.singletonList(patient));
assertTrue(bundle.getLink().isEmpty());
paging.addLinks(bundle);
assertNotNull(bundle.getLink(Constants.LINK_SELF));
assertNotNull(bundle.getLink(Constants.LINK_FIRST));
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 emptyCursorTest.
@Test
public void emptyCursorTest() {
PatientLinkBuilder paging = new PatientLinkBuilder(TEST_CONTRACT_URL + "&_count=10&cursor=");
assertTrue(paging.isPagingRequested());
assertTrue(paging.isFirstPage());
assertEquals(10, paging.getPageSize());
}
Aggregations