Search in sources :

Example 1 with ContractForCoverageDTO

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

the class CoverageDriverTest method before.

@BeforeEach
void before() {
    mapping = new ContractToContractCoverageMapping();
    // Set properties values in database
    addPropertiesTableValues();
    contract = dataSetup.setupContract("TST-12", AB2D_EPOCH.toOffsetDateTime());
    contract1 = dataSetup.setupContract("TST-45", AB2D_EPOCH.toOffsetDateTime());
    contractForCoverageDTO = new ContractForCoverageDTO("TST-12", AB2D_EPOCH.toOffsetDateTime(), ContractForCoverageDTO.ContractType.NORMAL);
    contractForCoverageDTO1 = new ContractForCoverageDTO("TST-45", AB2D_EPOCH.toOffsetDateTime(), ContractForCoverageDTO.ContractType.NORMAL);
    contractRepo.saveAndFlush(contract);
    january = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 1, 2020);
    february = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 2, 2020);
    march = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 3, 2020);
    PdpClientDTO contractPdpClient = createClient(contract, "TST-12", SPONSOR_ROLE);
    pdpClientService.createClient(contractPdpClient);
    dataSetup.queueForCleanup(pdpClientService.getClientById("TST-12"));
    PdpClient pdpClient = dataSetup.setupPdpClient(List.of());
    job = new Job();
    job.setContractNumber(contract.getContractNumber());
    job.setJobUuid("unique");
    job.setOrganization(pdpClient.getOrganization());
    job.setStatus(gov.cms.ab2d.common.model.JobStatus.SUBMITTED);
    job.setCreatedAt(OffsetDateTime.now());
    job.setFhirVersion(STU3);
    jobRepo.saveAndFlush(job);
    dataSetup.queueForCleanup(job);
    bfdClient = mock(BFDClient.class);
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(6);
    taskExecutor.setCorePoolSize(3);
    taskExecutor.initialize();
    processor = new CoverageProcessorImpl(coverageService, bfdClient, taskExecutor, MAX_ATTEMPTS, contractWorkerClient);
    driver = new CoverageDriverImpl(coverageSearchRepo, pdpClientService, coverageService, propertiesService, processor, searchLock, contractToContractCoverageMapping);
}
Also used : ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Job(gov.cms.ab2d.common.model.Job) PdpClient(gov.cms.ab2d.common.model.PdpClient) BFDClient(gov.cms.ab2d.bfd.client.BFDClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ContractForCoverageDTO

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

the class CoverageDriverUnitTest method beginPagingWhenCoveragePeriodsPresent.

@DisplayName("Paging coverage periods")
@Test
void beginPagingWhenCoveragePeriodsPresent() {
    when(coverageService.getCoveragePeriod(any(ContractForCoverageDTO.class), anyInt(), anyInt())).thenAnswer((invocationOnMock) -> {
        CoveragePeriod period = new CoveragePeriod();
        period.setContractNumber((invocationOnMock.getArgument(0).toString()));
        period.setMonth(invocationOnMock.getArgument(1));
        period.setYear(invocationOnMock.getArgument(2));
        return period;
    });
    int pagingSize = (int) ReflectionTestUtils.getField(driver, "PAGING_SIZE");
    when(coverageService.pageCoverage(any(CoveragePagingRequest.class))).thenAnswer((invocationMock) -> {
        CoveragePagingRequest request = invocationMock.getArgument(0);
        Optional<Long> cursor = request.getCursor();
        CoveragePagingRequest nextRequest = null;
        if (cursor.isPresent()) {
            long cursorValue = cursor.get();
            nextRequest = new CoveragePagingRequest(pagingSize, (cursorValue + pagingSize), request.getContract(), request.getJobStartTime());
        } else {
            nextRequest = new CoveragePagingRequest(pagingSize, (long) pagingSize, request.getContract(), request.getJobStartTime());
        }
        return new CoveragePagingResult(List.of(), nextRequest);
    });
    Job job = new Job();
    ContractDTO contract = new ContractDTO("Contract-0", null, AB2D_EPOCH.toOffsetDateTime(), null);
    when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO("Contract-0", contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));
    CoveragePagingResult firstCall = driver.pageCoverage(job, contract);
    assertNotNull(firstCall);
    assertTrue(firstCall.getNextRequest().isPresent());
    CoveragePagingRequest firstNextRequest = firstCall.getNextRequest().get();
    assertTrue(firstNextRequest.getCursor().isPresent());
    assertEquals(pagingSize, firstNextRequest.getCursor().get());
    CoveragePagingResult secondCall = driver.pageCoverage(firstNextRequest);
    assertNotNull(secondCall);
    assertTrue(secondCall.getNextRequest().isPresent());
    CoveragePagingRequest secondNextRequest = secondCall.getNextRequest().get();
    assertTrue(secondNextRequest.getCursor().isPresent());
    assertEquals((2L * pagingSize), secondNextRequest.getCursor().get());
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with ContractForCoverageDTO

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

the class CoverageDriverUnitTest method failureToPageCausesExceptions.

@DisplayName("When paging coverage fails throw coverage driver exception")
@Test
void failureToPageCausesExceptions() {
    when(coverageService.pageCoverage(any())).thenThrow(RuntimeException.class);
    CoverageDriver driver = new CoverageDriverImpl(null, null, coverageService, null, null, null, null);
    ContractForCoverageDTO contract = new ContractForCoverageDTO();
    contract.setContractNumber("contractNum");
    CoverageDriverException exception = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(new CoveragePagingRequest(1000, null, contract, OffsetDateTime.now())));
    assertTrue(exception.getMessage().contains("coverage driver failing preconditions"));
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with ContractForCoverageDTO

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

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

the class ContractProcessorInvalidPatientTest method testInvalidBenes.

@Test
void testInvalidBenes() throws IOException {
    when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO(contract.getContractNumber(), contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));
    org.hl7.fhir.dstu3.model.Bundle b1 = BundleUtils.createBundle(createBundleEntry("1"));
    org.hl7.fhir.dstu3.model.Bundle b2 = BundleUtils.createBundle(createBundleEntry("2"));
    org.hl7.fhir.dstu3.model.Bundle b4 = BundleUtils.createBundle(createBundleEntry("4"));
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(1L), any())).thenReturn(b1);
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(2L), any())).thenReturn(b2);
    when(bfdClient.requestEOBFromServer(eq(STU3), eq(3L), any())).thenReturn(b4);
    when(coverageDriver.numberOfBeneficiariesToProcess(any(Job.class), any(ContractDTO.class))).thenReturn(3);
    List<FilterOutByDate.DateRange> dates = singletonList(TestUtil.getOpenRange());
    List<CoverageSummary> summaries = List.of(new CoverageSummary(createIdentifierWithoutMbi(1L), null, dates), new CoverageSummary(createIdentifierWithoutMbi(2L), null, dates), new CoverageSummary(createIdentifierWithoutMbi(3L), null, dates));
    when(coverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(summaries, null));
    List<JobOutput> outputs = cut.process(job);
    assertNotNull(outputs);
    assertEquals(1, outputs.size());
    String fileName1 = contractId + "_0001.ndjson";
    String output1 = outputs.get(0).getFilePath();
    assertTrue(output1.equalsIgnoreCase(fileName1));
    String actual1 = Files.readString(Path.of(tmpDirFolder.getAbsolutePath() + File.separator + job.getJobUuid() + "/" + output1));
    assertTrue(actual1.contains("Patient/1") && actual1.contains("Patient/2"));
    assertFalse(actual1.contains("Patient/3") || actual1.contains("Patient/4"));
}
Also used : CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput) Test(org.junit.jupiter.api.Test)

Aggregations

ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)11 Test (org.junit.jupiter.api.Test)6 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)5 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)5 Job (gov.cms.ab2d.common.model.Job)4 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)4 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)4 DisplayName (org.junit.jupiter.api.DisplayName)4 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)2 CoverageSummary (gov.cms.ab2d.coverage.model.CoverageSummary)2 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Token (com.newrelic.api.agent.Token)1 Trace (com.newrelic.api.agent.Trace)1 BFDClient (gov.cms.ab2d.bfd.client.BFDClient)1 PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)1 Contract (gov.cms.ab2d.common.model.Contract)1 JobOutput (gov.cms.ab2d.common.model.JobOutput)1 PdpClient (gov.cms.ab2d.common.model.PdpClient)1 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)1