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());
}
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"));
}
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%"));
}
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());
}
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);
}
}
Aggregations