Search in sources :

Example 1 with CoverageService

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);
    }
}
Also used : Trace(com.newrelic.api.agent.Trace) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) ZonedDateTime(java.time.ZonedDateTime) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Constants(gov.cms.ab2d.common.util.Constants) Scheduled(org.springframework.scheduling.annotation.Scheduled) CoverageUtils.getEndDateTime(gov.cms.ab2d.worker.processor.coverage.CoverageUtils.getEndDateTime) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) ArrayList(java.util.ArrayList) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePresentCheck(gov.cms.ab2d.worker.processor.coverage.check.CoveragePresentCheck) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) CoverageNoDuplicatesCheck(gov.cms.ab2d.worker.processor.coverage.check.CoverageNoDuplicatesCheck) Service(org.springframework.stereotype.Service) AB2D_ZONE(gov.cms.ab2d.common.util.DateUtil.AB2D_ZONE) Map(java.util.Map) CoverageStableCheck(gov.cms.ab2d.worker.processor.coverage.check.CoverageStableCheck) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) ZoneOffset(java.time.ZoneOffset) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) LinkedHashSet(java.util.LinkedHashSet) DateUtil(gov.cms.ab2d.common.util.DateUtil) Contract(gov.cms.ab2d.common.model.Contract) Job(gov.cms.ab2d.common.model.Job) CoverageSearchRepository(gov.cms.ab2d.coverage.repository.CoverageSearchRepository) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) CoverageUpToDateCheck(gov.cms.ab2d.worker.processor.coverage.check.CoverageUpToDateCheck) Set(java.util.Set) CoverageUtils.getAttestationTime(gov.cms.ab2d.worker.processor.coverage.CoverageUtils.getAttestationTime) CoverageService(gov.cms.ab2d.coverage.service.CoverageService) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) AB2D_EPOCH(gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH) List(java.util.List) Lock(java.util.concurrent.locks.Lock) Slf4j(lombok.extern.slf4j.Slf4j) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) DayOfWeek(java.time.DayOfWeek) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) CoveragePeriodsPresentCheck(gov.cms.ab2d.worker.processor.coverage.check.CoveragePeriodsPresentCheck) PdpClientService(gov.cms.ab2d.common.service.PdpClientService) CoverageMapping(gov.cms.ab2d.coverage.model.CoverageMapping) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) CoverageStableCheck(gov.cms.ab2d.worker.processor.coverage.check.CoverageStableCheck) ArrayList(java.util.ArrayList) CoverageNoDuplicatesCheck(gov.cms.ab2d.worker.processor.coverage.check.CoverageNoDuplicatesCheck) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ArrayList(java.util.ArrayList) List(java.util.List) CoverageUpToDateCheck(gov.cms.ab2d.worker.processor.coverage.check.CoverageUpToDateCheck) CoveragePresentCheck(gov.cms.ab2d.worker.processor.coverage.check.CoveragePresentCheck) CoveragePeriodsPresentCheck(gov.cms.ab2d.worker.processor.coverage.check.CoveragePeriodsPresentCheck)

Aggregations

Trace (com.newrelic.api.agent.Trace)1 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)1 Contract (gov.cms.ab2d.common.model.Contract)1 Job (gov.cms.ab2d.common.model.Job)1 PdpClientService (gov.cms.ab2d.common.service.PdpClientService)1 PropertiesService (gov.cms.ab2d.common.service.PropertiesService)1 Constants (gov.cms.ab2d.common.util.Constants)1 DateUtil (gov.cms.ab2d.common.util.DateUtil)1 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)1 AB2D_ZONE (gov.cms.ab2d.common.util.DateUtil.AB2D_ZONE)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)1 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)1 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)1 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)1 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)1 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)1 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)1 CoverageSearchRepository (gov.cms.ab2d.coverage.repository.CoverageSearchRepository)1 CoverageService (gov.cms.ab2d.coverage.service.CoverageService)1