Search in sources :

Example 11 with CoveragePeriod

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

the class CoverageMappingCallableTest method testTestContractYears.

@DisplayName("Test to see if it returns the correct year for test contracts")
@Test
void testTestContractYears() {
    ContractDTO contract = new ContractDTO("TESTING", "TESTING", OffsetDateTime.now(), Contract.ContractType.CLASSIC_TEST);
    CoveragePeriod period = new CoveragePeriod();
    period.setContractNumber(contract.getContractNumber());
    period.setYear(2020);
    period.setMonth(1);
    CoverageSearchEvent cse = new CoverageSearchEvent();
    cse.setCoveragePeriod(period);
    CoverageSearch search = new CoverageSearch();
    search.setPeriod(period);
    // First test that the corrected year modification works
    CoverageMapping mapping = new CoverageMapping(cse, search);
    ContractToContractCoverageMapping contractToContractCoverageMapping = new ContractToContractCoverageMapping();
    ContractForCoverageDTO contractForCoverageDTO = contractToContractCoverageMapping.map(contract);
    CoverageMappingCallable callable = new CoverageMappingCallable(STU3, mapping, bfdClient, mapping.getPeriod().getYear());
    assertEquals(3, contractForCoverageDTO.getCorrectedYear(2020));
    // Test that the corrected year modification is not applied to Synthea
    contractForCoverageDTO.setContractType(ContractForCoverageDTO.ContractType.SYNTHEA);
    assertEquals(2020, contractForCoverageDTO.getCorrectedYear(2020));
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) CoverageMapping(gov.cms.ab2d.coverage.model.CoverageMapping) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with CoveragePeriod

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

the class CoverageUpdateAndProcessorTest method queueStaleCoverageTimeRanges.

@DisplayName("Queue stale coverages ignores coverage periods with last successful search after a boundary in time")
@Test
void queueStaleCoverageTimeRanges() throws CoverageDriverException, InterruptedException {
    coveragePeriodRepo.deleteAll();
    OffsetDateTime currentDate = OffsetDateTime.now(DateUtil.AB2D_ZONE);
    OffsetDateTime previousSunday = currentDate.truncatedTo(ChronoUnit.DAYS).with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)).plusSeconds(1);
    OffsetDateTime oneMonthAgo = currentDate.minusMonths(1);
    OffsetDateTime twoMonthsAgo = currentDate.minusMonths(2);
    CoveragePeriod currentMonth = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), currentDate.getMonthValue(), currentDate.getYear());
    currentMonth.setStatus(CoverageJobStatus.SUCCESSFUL);
    currentMonth.setLastSuccessfulJob(previousSunday);
    coveragePeriodRepo.saveAndFlush(currentMonth);
    CoveragePeriod oneMonth = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), oneMonthAgo.getMonthValue(), oneMonthAgo.getYear());
    oneMonth.setStatus(CoverageJobStatus.SUCCESSFUL);
    oneMonth.setLastSuccessfulJob(previousSunday);
    coveragePeriodRepo.saveAndFlush(oneMonth);
    CoveragePeriod twoMonth = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), twoMonthsAgo.getMonthValue(), twoMonthsAgo.getYear());
    twoMonth.setStatus(CoverageJobStatus.SUCCESSFUL);
    twoMonth.setLastSuccessfulJob(previousSunday);
    coveragePeriodRepo.saveAndFlush(twoMonth);
    createEvent(currentMonth, CoverageJobStatus.SUCCESSFUL, previousSunday);
    createEvent(oneMonth, CoverageJobStatus.SUCCESSFUL, previousSunday);
    createEvent(twoMonth, CoverageJobStatus.SUCCESSFUL, previousSunday);
    driver.queueStaleCoveragePeriods();
    assertEquals(0, coverageSearchRepo.findAll().size());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with CoveragePeriod

use of gov.cms.ab2d.coverage.model.CoveragePeriod 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)

Example 14 with CoveragePeriod

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

the class CoverageServiceImplTest method getCoveragePeriod.

@DisplayName("Get a coverage period")
@Test
void getCoveragePeriod() {
    CoveragePeriod period = coverageService.getCoveragePeriod(contract1, JANUARY, YEAR);
    assertEquals(period1Jan, period);
}
Also used : CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with CoveragePeriod

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

the class CoverageServiceImplTest method getOrCreateInsertsNew.

@DisplayName("Get or create does not insert duplicate period")
@Test
void getOrCreateInsertsNew() {
    CoveragePeriod period = coverageService.getCreateIfAbsentCoveragePeriod(contract1, 12, 2020);
    coveragePeriodRepo.delete(period);
}
Also used : CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)62 Test (org.junit.jupiter.api.Test)40 DisplayName (org.junit.jupiter.api.DisplayName)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)22 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)20 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)19 OffsetDateTime (java.time.OffsetDateTime)18 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)15 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)15 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)14 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)12 Identifiers (gov.cms.ab2d.coverage.model.Identifiers)11 ZonedDateTime (java.time.ZonedDateTime)11 ArrayList (java.util.ArrayList)11 LinkedHashSet (java.util.LinkedHashSet)11 Job (gov.cms.ab2d.common.model.Job)10 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)9 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)9 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)9