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