use of gov.cms.ab2d.coverage.service.CoverageService in project ab2d by CMSgov.
the class CoverageDriverImpl method verifyCoverage.
/**
* Verify that coverage data cached in the database matches expected business requirements.
*
* Steps
* - List of all contracts that are active contracts
* - Check whether contracts have a coverage period for every month since the contract
* attested. If not, log issue and filter out because other checks do not apply.
* {@link CoveragePeriodsPresentCheck}
* - Get count of beneficiaries for every month for every contract
* - Check that there are no {@link CoverageNoDuplicatesCheck}
* - Check that every month for a contract has some enrollment except
* for the current month {@link CoveragePresentCheck}
* - Check that the coverage for a contract and month is from the latest
* successful search {@link CoverageUpToDateCheck}
* - Check that the coverage month to month has not changed drastically {@link CoverageStableCheck}
* - If there are any issues report all of those issues and fail
*
* @throws CoverageVerificationException if one or more violations of expected business level behavior are found
*/
@Override
public void verifyCoverage() {
List<String> issues = new ArrayList<>();
// Only filter contracts that matter
List<ContractDTO> enabledContracts = pdpClientService.getAllEnabledContracts().stream().filter(contract -> !contract.isTestContract()).filter(contract -> contractNotBeingUpdated(issues, contract)).map(Contract::toDTO).toList();
// Don't perform other verification checks if coverage for months is outright missing
List<ContractDTO> filteredContracts = enabledContracts.stream().filter(new CoveragePeriodsPresentCheck(coverageService, null, issues)).toList();
// Query for counts of beneficiaries for each contract
Map<String, List<CoverageCount>> coverageCounts = coverageService.countBeneficiariesForContracts(filteredContracts.stream().map(mapping::map).toList()).stream().collect(groupingBy(CoverageCount::getContractNumber));
// Use counts to perform other checks and count passing contracts
long passingContracts = filteredContracts.stream().filter(new CoverageNoDuplicatesCheck(coverageService, coverageCounts, issues)).filter(new CoveragePresentCheck(coverageService, coverageCounts, issues)).filter(new CoverageUpToDateCheck(coverageService, coverageCounts, issues)).filter(new CoverageStableCheck(coverageService, coverageCounts, issues)).count();
String message = String.format("Verified that %d contracts pass all coverage checks out of %d", passingContracts, enabledContracts.size());
log.info(message);
if (!issues.isEmpty()) {
throw new CoverageVerificationException(message, issues);
}
}
Aggregations