Search in sources :

Example 1 with CoverageSearch

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

the class CoverageDriverTest method getNextSearchDefaultsToFirst.

/**
 * Verify that null is returned if there are no searches, a search there is one and verify that it
 * was deleted after it was searched.
 */
@DisplayName("Getting another search gets and removes a coverage search specification")
@Test
void getNextSearchDefaultsToFirst() {
    assertTrue(driver.getNextSearch().isEmpty());
    CoverageSearch search1 = new CoverageSearch(null, january, OffsetDateTime.now(), 0);
    CoverageSearch savedSearch1 = coverageSearchRepo.save(search1);
    Optional<CoverageSearch> returnedSearch = driver.getNextSearch();
    assertEquals(savedSearch1.getPeriod().getMonth(), returnedSearch.get().getPeriod().getMonth());
    assertEquals(savedSearch1.getPeriod().getYear(), returnedSearch.get().getPeriod().getYear());
    assertTrue(driver.getNextSearch().isEmpty());
}
Also used : CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with CoverageSearch

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

the class CoverageMappingCallableTest method filterYear.

@DisplayName("Filter out years that do not match the provided year")
@Test
void filterYear() {
    org.hl7.fhir.dstu3.model.Bundle bundle1 = buildBundle(0, 10, 2020);
    bundle1.setLink(singletonList(new org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent().setRelation(org.hl7.fhir.dstu3.model.Bundle.LINK_NEXT)));
    org.hl7.fhir.dstu3.model.Bundle bundle2 = buildBundle(10, 20, 2019);
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt(), anyInt())).thenReturn(bundle1);
    when(bfdClient.requestNextBundleFromServer(eq(STU3), any(org.hl7.fhir.dstu3.model.Bundle.class))).thenReturn(bundle2);
    ContractDTO contract = new ContractDTO("TESTING", "TESTING", null, null);
    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);
    CoverageMapping mapping = new CoverageMapping(cse, search);
    CoverageMappingCallable coverageCallable = new CoverageMappingCallable(STU3, mapping, bfdClient, mapping.getPeriod().getYear());
    try {
        mapping = coverageCallable.call();
        assertEquals(10, mapping.getBeneficiaryIds().size());
        int pastYear = (int) ReflectionTestUtils.getField(coverageCallable, "pastReferenceYear");
        assertEquals(10, pastYear);
    } catch (Exception exception) {
        fail("could not execute basic job with mock client", exception);
    }
}
Also used : ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) CoverageMapping(gov.cms.ab2d.coverage.model.CoverageMapping) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with CoverageSearch

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

the class CoverageMappingCallableTest method testNullMbi.

@Test
void testNullMbi() {
    ContractDTO contract = new ContractDTO("TESTING", "TESTING", null, null);
    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);
    CoverageMapping mapping = new CoverageMapping(cse, search);
    CoverageMappingCallable callable = new CoverageMappingCallable(STU3, mapping, bfdClient, mapping.getPeriod().getYear());
    Patient patient = new Patient();
    Identifiers ids = callable.extractPatientId(patient);
    assertNull(ids);
    Identifier beneId = new Identifier();
    beneId.setSystem(BENEFICIARY_ID);
    beneId.setValue("1");
    patient.getIdentifier().add(beneId);
    ids = callable.extractPatientId(patient);
    assertEquals(1L, ids.getBeneficiaryId());
    assertNull(ids.getCurrentMbi());
    assertEquals(0, ids.getHistoricMbis().size());
    Identifier mbiHist = new Identifier();
    mbiHist.setSystem(MBI_ID);
    mbiHist.setValue("HIST_MBI");
    Extension extension = new Extension();
    extension.setUrl(CURRENCY_IDENTIFIER);
    Coding code1 = new Coding();
    code1.setCode("historic");
    extension.setValue(code1);
    mbiHist.getExtension().add(extension);
    patient.getIdentifier().add(mbiHist);
    ids = callable.extractPatientId(patient);
    assertEquals(1L, ids.getBeneficiaryId());
    assertNull(ids.getCurrentMbi());
    assertEquals(1, ids.getHistoricMbis().size());
    assertEquals("HIST_MBI", ids.getHistoricMbis().stream().findAny().get());
    Identifier mbiCurrent = new Identifier();
    mbiCurrent.setSystem(MBI_ID);
    mbiCurrent.setValue("CURR_MBI");
    Extension extension2 = new Extension();
    extension2.setUrl(CURRENCY_IDENTIFIER);
    Coding code2 = new Coding();
    code2.setCode("current");
    extension2.setValue(code2);
    mbiCurrent.getExtension().add(extension2);
    patient.getIdentifier().add(mbiCurrent);
    ids = callable.extractPatientId(patient);
    assertEquals(1L, ids.getBeneficiaryId());
    assertEquals(1, ids.getHistoricMbis().size());
    assertEquals("CURR_MBI", ids.getCurrentMbi());
    assertEquals(1, ids.getHistoricMbis().size());
    assertEquals("HIST_MBI", ids.getHistoricMbis().stream().findAny().get());
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Identifier(org.hl7.fhir.dstu3.model.Identifier) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Coding(org.hl7.fhir.dstu3.model.Coding) 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) Patient(org.hl7.fhir.dstu3.model.Patient) BundleUtils.createPatient(gov.cms.ab2d.worker.processor.BundleUtils.createPatient) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) Test(org.junit.jupiter.api.Test)

Example 4 with CoverageSearch

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

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

the class CoverageServiceImplTest method findStuckJobs.

@DisplayName("Find all stuck jobs")
@Test
void findStuckJobs() {
    OffsetDateTime startTest = OffsetDateTime.now();
    coverageService.submitSearch(period1Jan.getId(), "testing");
    Optional<CoverageSearch> search1 = coverageSearchRepo.findFirstByOrderByCreatedAsc();
    coverageSearchRepo.delete(search1.get());
    coverageService.startSearch(search1.get(), "testing");
    coverageService.submitSearch(period2Jan.getId(), "testing");
    Optional<CoverageSearch> search2 = coverageSearchRepo.findFirstByOrderByCreatedAsc();
    coverageSearchRepo.delete(search2.get());
    Optional<CoverageMapping> coverageMapping = coverageService.startSearch(search2.get(), "testing");
    coverageService.completeSearch(coverageMapping.get().getPeriodId(), "testing");
    coverageService.submitSearch(period1Feb.getId(), "testing");
    Optional<CoverageSearch> search3 = coverageSearchRepo.findFirstByOrderByCreatedAsc();
    coverageSearchRepo.delete(search3.get());
    coverageService.startSearch(search3.get(), "testing");
    OffsetDateTime midTest = OffsetDateTime.now();
    coverageService.submitSearch(period1March.getId(), "testing");
    Optional<CoverageSearch> search4 = coverageSearchRepo.findFirstByOrderByCreatedAsc();
    coverageSearchRepo.delete(search4.get());
    coverageService.startSearch(search4.get(), "testing");
    coverageService.submitSearch(period1April.getId(), "testing");
    Optional<CoverageSearch> search5 = coverageSearchRepo.findFirstByOrderByCreatedAsc();
    coverageSearchRepo.delete(search5.get());
    coverageService.startSearch(search5.get(), "testing");
    OffsetDateTime afterTest = OffsetDateTime.now();
    List<CoveragePeriod> stuckJobs = coverageService.coveragePeriodStuckJobs(afterTest);
    assertEquals(4, stuckJobs.size());
    assertFalse(stuckJobs.stream().anyMatch(p -> p.getId().equals(period2Jan.getId())));
    assertTrue(stuckJobs.stream().anyMatch(p -> p.getId().equals(period1Jan.getId())));
    assertTrue(stuckJobs.stream().anyMatch(p -> p.getId().equals(period1Feb.getId())));
    assertTrue(stuckJobs.stream().anyMatch(p -> p.getId().equals(period1March.getId())));
    assertTrue(stuckJobs.stream().anyMatch(p -> p.getId().equals(period1April.getId())));
    stuckJobs = coverageService.coveragePeriodStuckJobs(midTest);
    assertEquals(2, stuckJobs.size());
    assertTrue(stuckJobs.stream().anyMatch(p -> p.equals(period1Jan)));
    assertTrue(stuckJobs.stream().anyMatch(p -> p.equals(period1Feb)));
    stuckJobs = coverageService.coveragePeriodStuckJobs(startTest);
    assertEquals(0, stuckJobs.size());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers(org.mockito.ArgumentMatchers) CoverageDeltaTestRepository(gov.cms.ab2d.coverage.repository.CoverageDeltaTestRepository) Date(java.util.Date) Collections.disjoint(java.util.Collections.disjoint) Autowired(org.springframework.beans.factory.annotation.Autowired) COVERAGE_ADDED(gov.cms.ab2d.coverage.repository.CoverageDeltaRepository.COVERAGE_ADDED) FilterOutByDate(gov.cms.ab2d.filter.FilterOutByDate) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) ZoneOffset(java.time.ZoneOffset) Collectors.toSet(java.util.stream.Collectors.toSet) CoverageDeltaRepository(gov.cms.ab2d.coverage.repository.CoverageDeltaRepository) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) CoverageSearchRepository(gov.cms.ab2d.coverage.repository.CoverageSearchRepository) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) Set(java.util.Set) TestPropertySource(org.springframework.test.context.TestPropertySource) AB2DCoveragePostgressqlContainer(gov.cms.ab2d.coverage.util.AB2DCoveragePostgressqlContainer) Collectors(java.util.stream.Collectors) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) AB2D_EPOCH(gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) CoveragePeriodRepository(gov.cms.ab2d.coverage.repository.CoveragePeriodRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CoverageMapping(gov.cms.ab2d.coverage.model.CoverageMapping) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Optional(java.util.Optional) CoverageDataSetup(gov.cms.ab2d.coverage.util.CoverageDataSetup) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) CoverageServiceRepository(gov.cms.ab2d.coverage.repository.CoverageServiceRepository) EntityScan(org.springframework.boot.autoconfigure.domain.EntityScan) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) PostgreSQLContainer(org.testcontainers.containers.PostgreSQLContainer) Function(java.util.function.Function) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) EntityNotFoundException(javax.persistence.EntityNotFoundException) DataSource(javax.sql.DataSource) CoverageSearchDiff(gov.cms.ab2d.coverage.model.CoverageSearchDiff) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedHashSet(java.util.LinkedHashSet) Container(org.testcontainers.junit.jupiter.Container) LogManager(gov.cms.ab2d.eventlogger.LogManager) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) COVERAGE_DELETED(gov.cms.ab2d.coverage.repository.CoverageDeltaRepository.COVERAGE_DELETED) CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) DisplayName(org.junit.jupiter.api.DisplayName) Coverage(gov.cms.ab2d.coverage.util.Coverage) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Collectors.toList(java.util.stream.Collectors.toList) CoverageDelta(gov.cms.ab2d.coverage.model.CoverageDelta) Assertions(org.junit.jupiter.api.Assertions) CoverageSearchEventRepository(gov.cms.ab2d.coverage.repository.CoverageSearchEventRepository) Comparator(java.util.Comparator) EnableJpaRepositories(org.springframework.data.jpa.repository.config.EnableJpaRepositories) OffsetDateTime(java.time.OffsetDateTime) CoverageMapping(gov.cms.ab2d.coverage.model.CoverageMapping) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) 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

CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)22 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)15 Test (org.junit.jupiter.api.Test)15 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)14 DisplayName (org.junit.jupiter.api.DisplayName)14 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)13 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)12 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Identifiers (gov.cms.ab2d.coverage.model.Identifiers)4 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)3 BundleUtils.createPatient (gov.cms.ab2d.worker.processor.BundleUtils.createPatient)3 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)2 Patient (org.hl7.fhir.dstu3.model.Patient)2 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)1 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)1 CoverageDelta (gov.cms.ab2d.coverage.model.CoverageDelta)1 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)1 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)1 CoverageSearchDiff (gov.cms.ab2d.coverage.model.CoverageSearchDiff)1