use of org.hl7.fhir.r4b.model.Bundle 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 org.hl7.fhir.r4b.model.Bundle 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);
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatient.
/**
* 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.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsByExistingPatient() 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 the bundle contains a key for total and that the value matches the
* number of entries in the bundle
*/
assertEquals(loadedRecords.stream().filter(r -> !(r instanceof Beneficiary)).filter(r -> !(r instanceof BeneficiaryHistory)).filter(r -> !(r instanceof MedicareBeneficiaryIdHistory)).count(), searchResults.getTotal());
/*
* 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));
/*
* Verify that each of the expected claims (one for every claim type) is present
* and looks correct.
*/
assertEachEob(searchResults, loadedRecords);
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class R4ExplanationOfBenefitResourceProviderIT method testLastUpdatedUrls.
/**
* Test the set of lastUpdated values
*
* @param fhirClient to use
* @param id the bene id to use
* @param urls is a list of lastUpdate values to test to find
* @param expectedValue number of matches
*/
private void testLastUpdatedUrls(IGenericClient fhirClient, String id, List<String> urls, int expectedValue) {
// Search for each lastUpdated value
for (String lastUpdatedValue : urls) {
Bundle searchResults = fetchWithLastUpdated(fhirClient, id, lastUpdatedValue);
assertEquals(expectedValue, searchResults.getTotal(), String.format("Expected %s to filter resources correctly", lastUpdatedValue));
}
}
use of org.hl7.fhir.r4b.model.Bundle in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForSamhsaEobsWithExcludeSamhsaFalse.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} with <code>
* excludeSAMHSA=false</code> does not filter out SAMHSA-related claims.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForSamhsaEobsWithExcludeSamhsaFalse() throws FHIRException {
Beneficiary beneficiary = loadSampleAWithSamhsa();
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
Bundle searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary.getBeneficiaryId()))).and(new StringClientParam("excludeSAMHSA").matches().value("false")).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
for (ClaimType claimType : ClaimType.values()) {
// Without filtering we expect one claim for each claim type.
assertEquals(1, filterToClaimType(searchResults, claimType).size());
}
}
Aggregations