Search in sources :

Example 1 with CoveragePagingResult

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

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

the class JobProcessorIntegrationTest method setUp.

@BeforeEach
void setUp() {
    MockitoAnnotations.openMocks(this);
    LogManager logManager = new LogManager(sqlEventLogger, kinesisEventLogger, slackLogger);
    PdpClient pdpClient = createClient();
    contract = createContract();
    contractForCoverageDTO = mapping.map(contract);
    fail = new RuntimeException("TEST EXCEPTION");
    job = createJob(pdpClient);
    job.setContractNumber(contract.getContractNumber());
    job.setStatus(JobStatus.IN_PROGRESS);
    jobRepository.saveAndFlush(job);
    when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong())).thenAnswer((args) -> {
        ExplanationOfBenefit copy = EOB.copy();
        copy.getPatient().setReference("Patient/" + args.getArgument(1));
        return EobTestDataUtil.createBundle(copy);
    });
    when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong(), any())).thenAnswer((args) -> {
        ExplanationOfBenefit copy = EOB.copy();
        copy.getPatient().setReference("Patient/" + args.getArgument(1));
        return EobTestDataUtil.createBundle(copy);
    });
    when(mockCoverageDriver.numberOfBeneficiariesToProcess(any(Job.class), any(ContractDTO.class))).thenReturn(100);
    when(mockCoverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(loadFauxMetadata(contractForCoverageDTO, 99), null));
    SearchConfig searchConfig = new SearchConfig(tmpEfsMountDir.getAbsolutePath(), STREAMING_DIR, FINISHED_DIR, 0, 0, MULTIPLIER, NUMBER_PATIENT_REQUESTS_PER_THREAD);
    PatientClaimsProcessor patientClaimsProcessor = new PatientClaimsProcessorImpl(mockBfdClient, logManager, searchConfig);
    ReflectionTestUtils.setField(patientClaimsProcessor, "earliestDataDate", "01/01/1900");
    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.initialize();
    ContractProcessor contractProcessor = new ContractProcessorImpl(contractWorkerClient, jobRepository, mockCoverageDriver, patientClaimsProcessor, logManager, eobClaimRequestsQueue, jobChannelService, jobProgressService, mapping, pool, searchConfig);
    cut = new JobProcessorImpl(fileService, jobChannelService, jobProgressService, jobProgressUpdateService, jobRepository, jobOutputRepository, contractProcessor, logManager);
    ReflectionTestUtils.setField(cut, "efsMount", tmpEfsMountDir.toString());
    ReflectionTestUtils.setField(cut, "failureThreshold", 10);
}
Also used : SearchConfig(gov.cms.ab2d.worker.config.SearchConfig) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) PdpClient(gov.cms.ab2d.common.model.PdpClient) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Job(gov.cms.ab2d.common.model.Job) LogManager(gov.cms.ab2d.eventlogger.LogManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CoveragePagingResult

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

the class CoverageDriverStub method pageCoverage.

@Override
public CoveragePagingResult pageCoverage(CoveragePagingRequest request) {
    CoveragePagingRequest nextRequest = getNextRequest(request, null, request.getContract());
    List<CoverageSummary> results = getSummaries(request);
    return new CoveragePagingResult(results, nextRequest);
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult)

Example 4 with CoveragePagingResult

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

Example 5 with CoveragePagingResult

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

the class ContractProcessorUnitTest method whenExpectedPatientsNotMatchActualPatientsFail.

@Test
@DisplayName("When a job is cancelled while it is being processed, then attempt to stop the job gracefully without completing it")
void whenExpectedPatientsNotMatchActualPatientsFail() {
    when(coverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(createPatientsByContractResponse(contractForCoverageDTO, 1), null));
    when(coverageDriver.numberOfBeneficiariesToProcess(any(Job.class), any(ContractDTO.class))).thenReturn(3);
    ContractProcessingException exception = assertThrows(ContractProcessingException.class, () -> cut.process(job));
    assertTrue(exception.getMessage().contains("from database but retrieved"));
}
Also used : 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) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)22 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)22 Test (org.junit.jupiter.api.Test)16 DisplayName (org.junit.jupiter.api.DisplayName)15 CoverageSummary (gov.cms.ab2d.coverage.model.CoverageSummary)14 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)12 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)11 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)10 Identifiers (gov.cms.ab2d.coverage.model.Identifiers)10 LinkedHashSet (java.util.LinkedHashSet)10 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)9 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)9 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)9 LogManager (gov.cms.ab2d.eventlogger.LogManager)9 FilterOutByDate (gov.cms.ab2d.filter.FilterOutByDate)9 OffsetDateTime (java.time.OffsetDateTime)9 List (java.util.List)9 Map (java.util.Map)9 Optional (java.util.Optional)9 CoverageDelta (gov.cms.ab2d.coverage.model.CoverageDelta)8