Search in sources :

Example 1 with CoverageCount

use of gov.cms.ab2d.coverage.model.CoverageCount 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 2 with CoverageCount

use of gov.cms.ab2d.coverage.model.CoverageCount 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 3 with CoverageCount

use of gov.cms.ab2d.coverage.model.CoverageCount 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 4 with CoverageCount

use of gov.cms.ab2d.coverage.model.CoverageCount 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 5 with CoverageCount

use of gov.cms.ab2d.coverage.model.CoverageCount in project ab2d by CMSgov.

the class CoverageServiceImplTest method countForContracts.

@DisplayName("Count coverage records for a group of contracts")
@Test
void countForContracts() {
    coverageService.submitSearch(period1Jan.getId(), "testing");
    coverageService.submitSearch(period1Feb.getId(), "testing");
    coverageService.submitSearch(period1March.getId(), "testing");
    coverageService.submitSearch(period1April.getId(), "testing");
    CoveragePeriod period2Feb = dataSetup.createCoveragePeriod("TST-34", 2, 2020);
    CoveragePeriod period2March = dataSetup.createCoveragePeriod("TST-34", 3, 2020);
    CoveragePeriod period2April = dataSetup.createCoveragePeriod("TST-34", 4, 2020);
    CoveragePeriod period2May = dataSetup.createCoveragePeriod("TST-34", 5, 2020);
    coverageService.submitSearch(period2Jan.getId(), "testing");
    coverageService.submitSearch(period2Feb.getId(), "testing");
    coverageService.submitSearch(period2March.getId(), "testing");
    coverageService.submitSearch(period2April.getId(), "testing");
    coverageService.submitSearch(period2May.getId(), "testing");
    CoverageSearchEvent jan1Progress = startSearchAndPullEvent();
    startSearchAndPullEvent();
    CoverageSearchEvent march1Progress = startSearchAndPullEvent();
    CoverageSearchEvent april1Progress = startSearchAndPullEvent();
    CoverageSearchEvent jan2Progress = startSearchAndPullEvent();
    startSearchAndPullEvent();
    CoverageSearchEvent march2Progress = startSearchAndPullEvent();
    startSearchAndPullEvent();
    CoverageSearchEvent may2Progress = startSearchAndPullEvent();
    // Number of beneficiaries shared between months
    // large number to attempt to trigger indexing
    // for more realistic results
    int sharedBeneficiaries = 10000;
    Set<Identifiers> fullIdentifiers = new LinkedHashSet<>();
    for (long idx = 0; idx < sharedBeneficiaries; idx++) {
        fullIdentifiers.add(createIdentifier(idx));
    }
    Set<Identifiers> halfIdentifiers = fullIdentifiers.stream().limit(5000).collect(toSet());
    // Save shared beneficiaries between months
    coverageService.insertCoverage(jan1Progress.getId(), fullIdentifiers);
    coverageService.insertCoverage(march1Progress.getId(), halfIdentifiers);
    coverageService.insertCoverage(april1Progress.getId(), fullIdentifiers);
    coverageService.completeSearch(period1Jan.getId(), "testing");
    coverageService.completeSearch(period1Feb.getId(), "testing");
    coverageService.completeSearch(period1March.getId(), "testing");
    coverageService.completeSearch(period1April.getId(), "testing");
    coverageService.insertCoverage(jan2Progress.getId(), halfIdentifiers);
    coverageService.insertCoverage(march2Progress.getId(), fullIdentifiers);
    coverageService.insertCoverage(may2Progress.getId(), halfIdentifiers);
    coverageService.completeSearch(period2Jan.getId(), "testing");
    coverageService.completeSearch(period2Feb.getId(), "testing");
    coverageService.completeSearch(period2March.getId(), "testing");
    coverageService.completeSearch(period2April.getId(), "testing");
    coverageService.completeSearch(period2May.getId(), "testing");
    List<CoverageCount> coverageCounts = coverageService.countBeneficiariesForContracts(List.of(contract1, contract2));
    assertNotNull(coverageCounts);
    assertEquals(6, coverageCounts.size());
    // No duplicate coverage periods or events
    assertEquals(coverageCounts.size(), coverageCounts.stream().map(CoverageCount::getCoveragePeriodId).collect(toSet()).size());
    assertEquals(coverageCounts.size(), coverageCounts.stream().map(CoverageCount::getCoverageEventId).collect(toSet()).size());
    Map<Integer, CoverageCount> coverageCountMap = coverageCounts.stream().collect(Collectors.toMap(CoverageCount::getCoveragePeriodId, Function.identity()));
    assertTrue(coverageCountMap.containsKey(period1Jan.getId()));
    assertEquals(fullIdentifiers.size(), coverageCountMap.get(period1Jan.getId()).getBeneficiaryCount());
    assertFalse(coverageCountMap.containsKey(period1Feb.getId()));
    assertTrue(coverageCountMap.containsKey(period1March.getId()));
    assertEquals(halfIdentifiers.size(), coverageCountMap.get(period1March.getId()).getBeneficiaryCount());
    assertTrue(coverageCountMap.containsKey(period1April.getId()));
    assertEquals(fullIdentifiers.size(), coverageCountMap.get(period1April.getId()).getBeneficiaryCount());
    assertTrue(coverageCountMap.containsKey(period2Jan.getId()));
    assertEquals(halfIdentifiers.size(), coverageCountMap.get(period2Jan.getId()).getBeneficiaryCount());
    assertFalse(coverageCountMap.containsKey(period2Feb.getId()));
    assertTrue(coverageCountMap.containsKey(period2March.getId()));
    assertEquals(fullIdentifiers.size(), coverageCountMap.get(period2March.getId()).getBeneficiaryCount());
    assertFalse(coverageCountMap.containsKey(period2April.getId()));
    assertTrue(coverageCountMap.containsKey(period2May.getId()));
    assertEquals(halfIdentifiers.size(), coverageCountMap.get(period2May.getId()).getBeneficiaryCount());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) Collections.disjoint(java.util.Collections.disjoint) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)13 ArrayList (java.util.ArrayList)11 List (java.util.List)10 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)9 DisplayName (org.junit.jupiter.api.DisplayName)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)3 ZonedDateTime (java.time.ZonedDateTime)3 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)2 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)2 LinkedHashSet (java.util.LinkedHashSet)2 Trace (com.newrelic.api.agent.Trace)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