Search in sources :

Example 11 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO in project ab2d by CMSgov.

the class CoverageCheckPredicatesUnitTest method whenCoverageNotDuplicated_passCoverageDuplicatedCheck.

@DisplayName("No duplicate enrollment found")
@Test
void whenCoverageNotDuplicated_passCoverageDuplicatedCheck() {
    Map<String, List<CoverageCount>> coverageCounts = new HashMap<>();
    List<String> issues = new ArrayList<>();
    CoverageNoDuplicatesCheck duplicatesCheck = new CoverageNoDuplicatesCheck(coverageService, coverageCounts, issues);
    ContractDTO contract = getContractDTO();
    List<CoverageCount> fakeCounts = List.of(new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(0).getYear(), ATTESTATION_TIME.plusMonths(0).getMonthValue(), 1, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(1).getYear(), ATTESTATION_TIME.plusMonths(1).getMonthValue(), 2, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(2).getYear(), ATTESTATION_TIME.plusMonths(2).getMonthValue(), 3, 1, 1));
    coverageCounts.put("TEST", fakeCounts);
    assertTrue(duplicatesCheck.test(contract));
    assertTrue(issues.isEmpty());
}
Also used : HashMap(java.util.HashMap) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO in project ab2d by CMSgov.

the class CoverageCheckPredicatesUnitTest method whenCoverageOutOfDate_failCoverageUpToDateCheck.

@DisplayName("Out of date coverage for a coverage period is detected")
@Test
void whenCoverageOutOfDate_failCoverageUpToDateCheck() {
    Map<String, List<CoverageCount>> coverageCounts = new HashMap<>();
    List<String> issues = new ArrayList<>();
    CoverageUpToDateCheck upToDateCheck = new CoverageUpToDateCheck(coverageService, coverageCounts, issues);
    ContractDTO contract = getContractDTO();
    CoverageSearchEvent event1 = new CoverageSearchEvent();
    event1.setId(1L);
    CoverageSearchEvent event3 = new CoverageSearchEvent();
    event3.setId(3L);
    when(coverageService.findEventWithSuccessfulOffset(anyInt(), anyInt())).thenReturn(Optional.of(event1)).thenReturn(Optional.empty()).thenReturn(Optional.of(event3));
    List<CoverageCount> fakeCounts = List.of(new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(0).getYear(), ATTESTATION_TIME.plusMonths(0).getMonthValue(), 1, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(1).getYear(), ATTESTATION_TIME.plusMonths(1).getMonthValue(), 1, 2, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(2).getYear(), ATTESTATION_TIME.plusMonths(2).getMonthValue(), 1, 3, 1));
    coverageCounts.put("TEST", fakeCounts);
    assertFalse(upToDateCheck.test(contract));
    assertEquals(1, issues.size());
    assertTrue(issues.get(0).contains("no successful search"));
    issues.clear();
    when(coverageService.findEventWithSuccessfulOffset(anyInt(), anyInt())).thenReturn(Optional.of(event1)).thenReturn(Optional.of(event1)).thenReturn(Optional.of(event3));
    assertFalse(upToDateCheck.test(contract));
    assertEquals(1, issues.size());
    assertTrue(issues.get(0).contains("old coverage search"));
}
Also used : HashMap(java.util.HashMap) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO in project ab2d by CMSgov.

the class CoverageCheckPredicatesUnitTest method whenCoverageUnstable_failCoverageStabilityCheck.

@DisplayName("Coverage changes are limited to 10% between months fails when changes are large")
@Test
void whenCoverageUnstable_failCoverageStabilityCheck() {
    Map<String, List<CoverageCount>> coverageCounts = new HashMap<>();
    List<String> issues = new ArrayList<>();
    CoverageStableCheck stableCheck = new CoverageStableCheck(coverageService, coverageCounts, issues);
    ContractDTO contract = getContractDTO();
    ZonedDateTime nonDecAttestationTime;
    if (ATTESTATION_TIME.getMonth().getValue() == 12)
        nonDecAttestationTime = ATTESTATION_TIME.plusMonths(1);
    else
        nonDecAttestationTime = ATTESTATION_TIME;
    List<CoverageCount> fakeCounts = List.of(new CoverageCount("TEST", nonDecAttestationTime.plusMonths(0).getYear(), nonDecAttestationTime.plusMonths(0).getMonthValue(), 1, 1, 10000), new CoverageCount("TEST", nonDecAttestationTime.plusMonths(1).getYear(), nonDecAttestationTime.plusMonths(1).getMonthValue(), 1, 1, 12000), new CoverageCount("TEST", nonDecAttestationTime.plusMonths(2).getYear(), nonDecAttestationTime.plusMonths(2).getMonthValue(), 1, 1, 10000));
    coverageCounts.put("TEST", fakeCounts);
    assertFalse(stableCheck.test(contract));
    int expectedIssues = (nonDecAttestationTime.getMonthValue() == 12 || nonDecAttestationTime.plusMonths(1).getMonthValue() == 12 || nonDecAttestationTime.plusMonths(2).getMonthValue() == 12) && nonDecAttestationTime.getMonthValue() != 0 ? 1 : 2;
    assertEquals(expectedIssues, issues.size());
    issues.forEach(issue -> assertTrue(issue.contains("enrollment changed")));
    assertTrue(issues.get(0).contains("20%"));
}
Also used : HashMap(java.util.HashMap) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ZonedDateTime(java.time.ZonedDateTime) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO in project ab2d by CMSgov.

the class CoverageCheckPredicatesUnitTest method whenCoverageUpToDate_passCoverageUpToDateCheck.

@DisplayName("Up to date enrollment for coverage periods passes checks")
@Test
void whenCoverageUpToDate_passCoverageUpToDateCheck() {
    Map<String, List<CoverageCount>> coverageCounts = new HashMap<>();
    List<String> issues = new ArrayList<>();
    CoverageUpToDateCheck upToDateCheck = new CoverageUpToDateCheck(coverageService, coverageCounts, issues);
    ContractDTO contract = getContractDTO();
    CoverageSearchEvent event1 = new CoverageSearchEvent();
    event1.setId(1L);
    CoverageSearchEvent event2 = new CoverageSearchEvent();
    event2.setId(2L);
    CoverageSearchEvent event3 = new CoverageSearchEvent();
    event3.setId(3L);
    when(coverageService.findEventWithSuccessfulOffset(anyInt(), anyInt())).thenReturn(Optional.of(event1)).thenReturn(Optional.of(event2)).thenReturn(Optional.of(event3));
    List<CoverageCount> fakeCounts = List.of(new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(0).getYear(), ATTESTATION_TIME.plusMonths(0).getMonthValue(), 1, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(1).getYear(), ATTESTATION_TIME.plusMonths(1).getMonthValue(), 1, 2, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(2).getYear(), ATTESTATION_TIME.plusMonths(2).getMonthValue(), 1, 3, 1));
    coverageCounts.put("TEST", fakeCounts);
    assertTrue(upToDateCheck.test(contract));
    assertTrue(issues.isEmpty());
}
Also used : HashMap(java.util.HashMap) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO 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

ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)43 Test (org.junit.jupiter.api.Test)31 DisplayName (org.junit.jupiter.api.DisplayName)27 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)18 ArrayList (java.util.ArrayList)13 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)12 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)12 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)12 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)12 Job (gov.cms.ab2d.common.model.Job)11 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)10 List (java.util.List)10 HashMap (java.util.HashMap)8 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)7 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)5 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)5 Contract (gov.cms.ab2d.common.model.Contract)4 OffsetDateTime (java.time.OffsetDateTime)4 ZonedDateTime (java.time.ZonedDateTime)4 PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)3