use of org.hl7.fhir.dstu2016may.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsWithPagingWithNegativePagingParameters.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with paging, using negative values for page size
* and start index parameters. This test expects to receive a BadRequestException, as negative
* values should result in an HTTP 400.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsWithPagingWithNegativePagingParameters() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
/*
* FIXME: At this time we cannot check for negative page size parameters due to
* the same bug described in
* https://github.com/jamesagnew/hapi-fhir/issues/1074.
*/
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
/*
* Access a created link of this bundle, providing the startIndex but not the
* pageSize (count).
*/
assertThrows(InvalidRequestException.class, () -> {
fhirClient.loadPage().byUrl(searchResults.getLink(Bundle.LINK_SELF).getUrl() + "&startIndex=-1").andReturnBundle(Bundle.class).execute();
});
}
use of org.hl7.fhir.dstu2016may.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchEobWithLastUpdatedAndPagination.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as with a
* lastUpdated parameter after yesterday.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchEobWithLastUpdatedAndPagination() throws FHIRException {
Beneficiary beneficiary = loadSampleA();
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
// Search with lastUpdated range between yesterday and now
int expectedCount = 3;
Date yesterday = Date.from(Instant.now().minus(1, ChronoUnit.DAYS));
Date now = new Date();
DateRangeParam afterYesterday = new DateRangeParam(yesterday, now);
Bundle searchResultsAfter = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).lastUpdated(afterYesterday).count(expectedCount).returnBundle(Bundle.class).execute();
assertEquals(expectedCount, searchResultsAfter.getEntry().size(), "Expected number resources return to be equal to count");
// Check self url
String selfLink = searchResultsAfter.getLink(IBaseBundle.LINK_SELF).getUrl();
assertTrue(selfLink.contains("lastUpdated"));
// Check next bundle
String nextLink = searchResultsAfter.getLink(IBaseBundle.LINK_NEXT).getUrl();
assertTrue(nextLink.contains("lastUpdated"));
Bundle nextResults = fhirClient.search().byUrl(nextLink).returnBundle(Bundle.class).execute();
assertEquals(expectedCount, nextResults.getEntry().size(), "Expected number resources return to be equal to count");
}
use of org.hl7.fhir.dstu2016may.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByLogicalId.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#searchByLogicalId(ca.uhn.fhir.rest.param.TokenParam)}
* works as expected for a {@link Patient} that does exist in the DB.
*/
@Test
public void searchForExistingPatientByLogicalId() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = createFhirClient();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.RES_ID.exactly().systemAndIdentifier(null, beneficiary.getBeneficiaryId())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
/*
* Verify that no paging links exist within the bundle.
*/
assertNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNull(searchResults.getLink(Constants.LINK_LAST));
assertEquals(1, searchResults.getTotal());
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
BeneficiaryTransformerTest.assertMatches(beneficiary, patientFromSearchResult, getRHwithIncldAddrFldHdr("false"));
}
use of org.hl7.fhir.dstu2016may.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByMbiHashIncludeIdentifiersFalse.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
* works as expected for a {@link Patient} that does exist in the DB, including identifiers to
* return the unhashed HICN and MBI.
*/
@Test
public void searchForExistingPatientByMbiHashIncludeIdentifiersFalse() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = createFhirClient("false", "true");
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, beneficiary.getMbiHash().get())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
/*
* Ensure the unhashed values for HICN and MBI are *not* present.
*/
Boolean hicnUnhashedPresent = false;
Boolean mbiUnhashedPresent = false;
Iterator<Identifier> identifiers = patientFromSearchResult.getIdentifier().iterator();
while (identifiers.hasNext()) {
Identifier identifier = identifiers.next();
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_BENE_HICN_UNHASHED))
hicnUnhashedPresent = true;
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED))
mbiUnhashedPresent = true;
}
assertFalse(hicnUnhashedPresent);
assertFalse(mbiUnhashedPresent);
}
use of org.hl7.fhir.dstu2016may.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchByPartDContractWithPaging.
/**
* Verifies that {@link
* PatientResourceProvider#searchByCoverageContract(ca.uhn.fhir.rest.param.TokenParam,
* ca.uhn.fhir.rest.param.TokenParam, String, ca.uhn.fhir.rest.api.server.RequestDetails)} works
* as expected, when paging is requested.
*/
@Test
public void searchByPartDContractWithPaging() {
ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES));
IGenericClient fhirClient = createFhirClientWithIncludeIdentifiersMbi();
// Should return a single match
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(new TokenClientParam("_has:Coverage.extension").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.PTDCNTRCT01), "S4607")).where(new TokenClientParam("_has:Coverage.rfrncyr").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.RFRNC_YR), "2018")).count(1).returnBundle(Bundle.class).execute();
// Verify that it found the expected bene and no extra pages.
assertNotNull(searchResults);
assertEquals(1, searchResults.getEntry().size());
assertNull(searchResults.getLink(Constants.LINK_NEXT));
}
Aggregations