use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProviderIT method searchForExistingPatientByHistoricalMbiHash.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
* works as expected for MBIs that should be present as a {@link BeneficiaryHistory} record.
*/
@Test
public void searchForExistingPatientByHistoricalMbiHash() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = createFhirClient();
loadedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r).forEach(h -> {
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, h.getMbiHash().get())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(1, searchResults.getTotal());
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
assertEquals(h.getBeneficiaryId(), patientFromSearchResult.getIdElement().getIdPart());
});
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProviderIT method searchForExistingPatientByPartDContractNumIncludeIdentifiersTrueWithPagingAndMultipleMbis.
/**
* Regression test for part of BFD-525, which verifies that duplicate entries are not returned
* when 1) plain-text identifiers are requested, 2) a beneficiary has multiple historical
* identifiers, and 3) paging is requested. (This oddly specific combo had been bugged earlier and
* was quite tricky to resolve).
*/
@Test
public void searchForExistingPatientByPartDContractNumIncludeIdentifiersTrueWithPagingAndMultipleMbis() {
ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES, StaticRifResource.SAMPLE_A_MEDICARE_BENEFICIARY_ID_HISTORY, StaticRifResource.SAMPLE_A_MEDICARE_BENEFICIARY_ID_HISTORY_EXTRA));
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 the bene wasn't duplicated.
assertNotNull(searchResults);
assertEquals(1, searchResults.getEntry().size());
// Double-check that the bene has multiple identifiers.
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
assertEquals(// was 4
1, patientFromSearchResult.getIdentifier().stream().filter(i -> TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED.equals(i.getSystem())).count());
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProviderIT 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().createFhirClientV2();
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(TransformerUtilsV2.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 -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProviderIT method searchWithLastUpdated.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary} works as
* expected for a search with a lastUpdated value.
*/
@Test
public void searchWithLastUpdated() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
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(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
LOGGER.info("Bundle information: database {}, first {}", searchResults.getMeta().getLastUpdated(), searchResults.getEntry().get(0).getResource().getMeta().getLastUpdated());
Date nowDate = new Date();
Date secondsAgoDate = Date.from(Instant.now().minusSeconds(100));
DateRangeParam inBoundsRange = new DateRangeParam().setLowerBoundInclusive(secondsAgoDate).setUpperBoundExclusive(nowDate);
LOGGER.info("Query Date Range {}", inBoundsRange);
Bundle searchInBoundsResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(inBoundsRange).returnBundle(Bundle.class).execute();
assertNotNull(searchInBoundsResults);
assertEquals(MedicareSegment.values().length, searchInBoundsResults.getTotal());
Date hourAgoDate = Date.from(Instant.now().minusSeconds(3600));
DateRangeParam outOfBoundsRange = new DateRangeParam(hourAgoDate, secondsAgoDate);
Bundle searchOutOfBoundsResult = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(outOfBoundsRange).returnBundle(Bundle.class).execute();
assertNotNull(searchOutOfBoundsResult);
assertEquals(0, searchOutOfBoundsResult.getTotal());
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProviderIT method searchByExistingBeneficiary.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.R4CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
* works as expected for a {@link Beneficiary} that does exist in the DB.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchByExistingBeneficiary() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
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(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(MedicareSegment.values().length, searchResults.getTotal());
/*
* 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));
/*
* 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 -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
Aggregations