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