use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientWithPageSizeNotProvided.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.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().createFhirClientV2();
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(TransformerUtilsV2.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());
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method readEobForExistingDMEClaim.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
* works as expected for a {@link DMEClaim}-derived {@link ExplanationOfBenefit} that does exist
* in the DB.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void readEobForExistingDMEClaim() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
DMEClaim claim = loadedRecords.stream().filter(r -> r instanceof DMEClaim).map(r -> (DMEClaim) r).findFirst().get();
ExplanationOfBenefit eob = fhirClient.read().resource(ExplanationOfBenefit.class).withId(TransformerUtilsV2.buildEobId(ClaimTypeV2.DME, claim.getClaimId())).execute();
assertNotNull(eob);
// Compare result to transformed EOB
compareEob(ClaimTypeV2.DME, eob, loadedRecords);
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchEobWithNullLastUpdated.
/**
* Verifies that {@link gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider}
* works as with a null lastUpdated parameter after yesterday.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchEobWithNullLastUpdated() throws FHIRException {
// Load a records and clear the lastUpdated field for one
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
String claimId = loadedRecords.stream().filter(r -> r instanceof CarrierClaim).map(r -> (CarrierClaim) r).findFirst().get().getClaimId();
String beneId = findFirstBeneficary(loadedRecords).getBeneficiaryId();
// Clear lastupdated in the database
ServerTestUtils.get().doTransaction((em) -> {
em.createQuery("update CarrierClaim set lastUpdated=null where claimId=:claimId").setParameter("claimId", claimId).executeUpdate();
});
// Find all EOBs without lastUpdated
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
Bundle searchAll = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneId))).returnBundle(Bundle.class).execute();
assertEquals(Date.from(TransformerConstants.FALLBACK_LAST_UPDATED), filterToClaimType(searchAll, ClaimTypeV2.CARRIER).get(0).getMeta().getLastUpdated(), "Expect null lastUpdated fields to map to the FALLBACK_LAST_UPDATED");
// Find all EOBs with < now()
Bundle searchWithLessThan = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneId))).lastUpdated(new DateRangeParam().setUpperBoundInclusive(new Date())).returnBundle(Bundle.class).execute();
assertEquals(Date.from(TransformerConstants.FALLBACK_LAST_UPDATED), filterToClaimType(searchWithLessThan, ClaimTypeV2.CARRIER).get(0).getMeta().getLastUpdated(), "Expect null lastUpdated fields to map to the FALLBACK_LAST_UPDATED");
assertEquals(searchAll.getTotal(), searchWithLessThan.getTotal(), "Expected the search for lastUpdated <= now() to include resources with fallback" + " lastUpdated values");
// Find all EOBs with >= now()-100 seconds
Bundle searchWithGreaterThan = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneId))).lastUpdated(new DateRangeParam().setLowerBoundInclusive(Date.from(Instant.now().minusSeconds(100)))).returnBundle(Bundle.class).execute();
assertEquals(searchAll.getTotal() - 1, searchWithGreaterThan.getTotal(), "Expected the search for lastUpdated >= now()-100 to not include null lastUpdated" + " resources");
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method readEobForMissingSNFClaim.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
* works as expected for an {@link SNFClaim}-derived {@link ExplanationOfBenefit} that does not
* exist in the DB.
*/
@Test
public void readEobForMissingSNFClaim() {
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
assertThrows(ResourceNotFoundException.class, () -> {
// No data is loaded, so this should return nothing.
fhirClient.read().resource(ExplanationOfBenefit.class).withId(TransformerUtilsV2.buildEobId(ClaimTypeV2.SNF, "1234")).execute();
});
}
use of ca.uhn.fhir.rest.client.api.IGenericClient in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchForEobsIncludeTaxNumbersHandling.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#findByPatient(ca.uhn.fhir.rest.param.ReferenceParam)}
* handles the {@link ExplanationOfBenefitResourceProvider#HEADER_NAME_INCLUDE_TAX_NUMBERS} header
* properly.
*
* @throws FHIRException (indicates test failure)
*/
// TODO: Fix this test .. it isn't working. Tax number is not showing up.
@Test
public void searchForEobsIncludeTaxNumbersHandling() 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();
CarrierClaim carrierClaim = loadedRecords.stream().filter(r -> r instanceof CarrierClaim).map(r -> (CarrierClaim) r).findFirst().get();
DMEClaim dmeClaim = loadedRecords.stream().filter(r -> r instanceof DMEClaim).map(r -> (DMEClaim) r).findFirst().get();
Bundle searchResults;
ExplanationOfBenefit carrierEob;
ExplanationOfBenefit dmeEob;
// Run the search without requesting tax numbers.
searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
// Verify that tax numbers aren't present for carrier claims.
carrierEob = filterToClaimType(searchResults, ClaimTypeV2.CARRIER).get(0);
assertNull(TransformerTestUtilsV2.findCareTeamEntryForProviderTaxNumber(carrierClaim.getLines().get(0).getProviderTaxNumber(), carrierEob.getCareTeam()));
// Verify that tax numbers aren't present for DME claims.
dmeEob = filterToClaimType(searchResults, ClaimTypeV2.DME).get(0);
assertNull(TransformerTestUtilsV2.findCareTeamEntryForProviderTaxNumber(dmeClaim.getLines().get(0).getProviderTaxNumber(), dmeEob.getCareTeam()));
RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(CommonHeaders.HEADER_NAME_INCLUDE_TAX_NUMBERS, "true");
fhirClient = ServerTestUtils.get().createFhirClientWithHeadersV2(requestHeader);
searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
}
Aggregations