use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByMbiHashIncludeIdentifiersTrue.
/**
* 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 searchForExistingPatientByMbiHashIncludeIdentifiersTrue() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = createFhirClient("true", "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 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;
}
assertTrue(hicnUnhashedPresent);
assertTrue(mbiUnhashedPresent);
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByHicnHashIncludeIdentifiersTrue.
/**
* 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 searchForExistingPatientByHicnHashIncludeIdentifiersTrue() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = createFhirClient("true", "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_HICN_HASH, beneficiary.getHicn())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
/*
* Ensure the unhashed values for HICN and MBI are 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;
}
assertTrue(hicnUnhashedPresent);
assertTrue(mbiUnhashedPresent);
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class CoverageResourceProviderIT method searchByExistingBeneficiaryWithPaging.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
* works as expected for a {@link Beneficiary} that does exist in the DB, with paging.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchByExistingBeneficiaryWithPaging() 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();
Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtils.buildPatientId(beneficiary))).count(4).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(MedicareSegment.values().length, searchResults.getTotal());
/*
* Verify that only the first and last paging links exist, since there should
* only be one page.
*/
assertNotNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNotNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Verify that each of the expected Coverages (one for every MedicareSegment) is
* present and looks correct.
*/
Coverage partACoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientWithOddPaging.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with paging. This test uses a count of 3 to verify
* our code will not run into an IndexOutOfBoundsException on even bundle sizes.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsByExistingPatientWithOddPaging() 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();
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).count(3).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(3, searchResults.getEntry().size());
/*
* Verify that accessing all next links, eventually leading to the last page,
* will not encounter an IndexOutOfBoundsException.
*/
while (searchResults.getLink(Constants.LINK_NEXT) != null) {
searchResults = fhirClient.loadPage().next(searchResults).execute();
assertNotNull(searchResults);
assertTrue(searchResults.hasEntry());
}
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientWithPageSizeNotProvided.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with paging, providing the startIndex but not the
* pageSize (count).
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsByExistingPatientWithPageSizeNotProvided() 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();
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
/*
* Verify that no paging links exist in the bundle.
*/
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Access a created link of this bundle, providing the startIndex but not the
* pageSize (count).
*/
Bundle pagedResults = fhirClient.loadPage().byUrl(searchResults.getLink(Bundle.LINK_SELF).getUrl() + "&startIndex=4").andReturnBundle(Bundle.class).execute();
assertNotNull(pagedResults);
/*
* Verify that paging links exist in this paged bundle.
*/
assertNull(pagedResults.getLink(Constants.LINK_NEXT));
assertNotNull(pagedResults.getLink(Constants.LINK_PREVIOUS));
assertNotNull(pagedResults.getLink(Constants.LINK_FIRST));
assertNotNull(pagedResults.getLink(Constants.LINK_LAST));
/*
* Add the entries in the paged results to a list and verify that only the last
* 4 entries in the original searchResults were returned in the pagedResults.
*/
List<IBaseResource> pagedEntries = new ArrayList<>();
pagedResults.getEntry().forEach(e -> pagedEntries.add(e.getResource()));
assertEquals(4, pagedEntries.size());
}
Aggregations