use of gov.cms.ab2d.coverage.model.CoverageMapping 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);
}
}
use of gov.cms.ab2d.coverage.model.CoverageMapping 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());
}
use of gov.cms.ab2d.coverage.model.CoverageMapping 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.CoverageMapping 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());
}
use of gov.cms.ab2d.coverage.model.CoverageMapping in project ab2d by CMSgov.
the class CoverageProcessorImpl method shutdown.
@PreDestroy
public void shutdown() {
log.warn("shutting down coverage processor");
// Notify all threads that we are shutting down and that work should not progress through pipeline
synchronized (inProgressMappings) {
inShutdown.set(true);
}
Collection<CoverageMapping> inserting = new ArrayList<>();
coverageInsertionQueue.drainTo(inserting);
coverageInsertionQueue.clear();
for (CoverageMapping insertedMapping : inserting) {
String message = String.format("shutting down before inserting for contract %s during %d-%d, will re-attempt", insertedMapping.getContractNumber(), insertedMapping.getPeriod().getMonth(), insertedMapping.getPeriod().getYear());
log.info(message);
resubmitMapping(insertedMapping, message, message, false);
}
synchronized (inProgressMappings) {
executor.setWaitForTasksToCompleteOnShutdown(false);
executor.shutdown();
inProgressMappings.forEach(callable -> {
CoverageMapping mapping = callable.getCoverageMapping();
String message = String.format("shutting down in progress search for contract %s during %d-%d", mapping.getContractNumber(), mapping.getPeriod().getMonth(), mapping.getPeriod().getYear());
log.info(message);
resubmitMapping(mapping, message, message, false);
});
}
}
Aggregations