Search in sources :

Example 1 with Identifiers

use of gov.cms.ab2d.coverage.model.Identifiers 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());
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Identifier(org.hl7.fhir.dstu3.model.Identifier) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Coding(org.hl7.fhir.dstu3.model.Coding) 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) Patient(org.hl7.fhir.dstu3.model.Patient) BundleUtils.createPatient(gov.cms.ab2d.worker.processor.BundleUtils.createPatient) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) Test(org.junit.jupiter.api.Test)

Example 2 with Identifiers

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

the class FhirUtils method addMbiIdsToEobs.

public static void addMbiIdsToEobs(IBaseResource eob, CoverageSummary patient, FhirVersion version) {
    if (eob == null) {
        return;
    }
    // Add extesions only if beneficiary id is present and known to memberships
    Long benId = EobUtils.getPatientId(eob);
    if (benId != null && patient != null) {
        Identifiers identifiers = patient.getIdentifiers();
        // Add each mbi to each eob
        if (identifiers.getCurrentMbi() != null) {
            IBase currentMbiExtension = ExtensionUtils.createMbiExtension(identifiers.getCurrentMbi(), true, version);
            ExtensionUtils.addExtension(eob, currentMbiExtension, version);
        }
        for (String mbi : identifiers.getHistoricMbis()) {
            IBase mbiExtension = ExtensionUtils.createMbiExtension(mbi, false, version);
            ExtensionUtils.addExtension(eob, mbiExtension, version);
        }
    }
}
Also used : Identifiers(gov.cms.ab2d.coverage.model.Identifiers) IBase(org.hl7.fhir.instance.model.api.IBase)

Example 3 with Identifiers

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

the class CoverageServiceImplTest method countForContracts.

@DisplayName("Count coverage records for a group of contracts")
@Test
void countForContracts() {
    coverageService.submitSearch(period1Jan.getId(), "testing");
    coverageService.submitSearch(period1Feb.getId(), "testing");
    coverageService.submitSearch(period1March.getId(), "testing");
    coverageService.submitSearch(period1April.getId(), "testing");
    CoveragePeriod period2Feb = dataSetup.createCoveragePeriod("TST-34", 2, 2020);
    CoveragePeriod period2March = dataSetup.createCoveragePeriod("TST-34", 3, 2020);
    CoveragePeriod period2April = dataSetup.createCoveragePeriod("TST-34", 4, 2020);
    CoveragePeriod period2May = dataSetup.createCoveragePeriod("TST-34", 5, 2020);
    coverageService.submitSearch(period2Jan.getId(), "testing");
    coverageService.submitSearch(period2Feb.getId(), "testing");
    coverageService.submitSearch(period2March.getId(), "testing");
    coverageService.submitSearch(period2April.getId(), "testing");
    coverageService.submitSearch(period2May.getId(), "testing");
    CoverageSearchEvent jan1Progress = startSearchAndPullEvent();
    startSearchAndPullEvent();
    CoverageSearchEvent march1Progress = startSearchAndPullEvent();
    CoverageSearchEvent april1Progress = startSearchAndPullEvent();
    CoverageSearchEvent jan2Progress = startSearchAndPullEvent();
    startSearchAndPullEvent();
    CoverageSearchEvent march2Progress = startSearchAndPullEvent();
    startSearchAndPullEvent();
    CoverageSearchEvent may2Progress = startSearchAndPullEvent();
    // Number of beneficiaries shared between months
    // large number to attempt to trigger indexing
    // for more realistic results
    int sharedBeneficiaries = 10000;
    Set<Identifiers> fullIdentifiers = new LinkedHashSet<>();
    for (long idx = 0; idx < sharedBeneficiaries; idx++) {
        fullIdentifiers.add(createIdentifier(idx));
    }
    Set<Identifiers> halfIdentifiers = fullIdentifiers.stream().limit(5000).collect(toSet());
    // Save shared beneficiaries between months
    coverageService.insertCoverage(jan1Progress.getId(), fullIdentifiers);
    coverageService.insertCoverage(march1Progress.getId(), halfIdentifiers);
    coverageService.insertCoverage(april1Progress.getId(), fullIdentifiers);
    coverageService.completeSearch(period1Jan.getId(), "testing");
    coverageService.completeSearch(period1Feb.getId(), "testing");
    coverageService.completeSearch(period1March.getId(), "testing");
    coverageService.completeSearch(period1April.getId(), "testing");
    coverageService.insertCoverage(jan2Progress.getId(), halfIdentifiers);
    coverageService.insertCoverage(march2Progress.getId(), fullIdentifiers);
    coverageService.insertCoverage(may2Progress.getId(), halfIdentifiers);
    coverageService.completeSearch(period2Jan.getId(), "testing");
    coverageService.completeSearch(period2Feb.getId(), "testing");
    coverageService.completeSearch(period2March.getId(), "testing");
    coverageService.completeSearch(period2April.getId(), "testing");
    coverageService.completeSearch(period2May.getId(), "testing");
    List<CoverageCount> coverageCounts = coverageService.countBeneficiariesForContracts(List.of(contract1, contract2));
    assertNotNull(coverageCounts);
    assertEquals(6, coverageCounts.size());
    // No duplicate coverage periods or events
    assertEquals(coverageCounts.size(), coverageCounts.stream().map(CoverageCount::getCoveragePeriodId).collect(toSet()).size());
    assertEquals(coverageCounts.size(), coverageCounts.stream().map(CoverageCount::getCoverageEventId).collect(toSet()).size());
    Map<Integer, CoverageCount> coverageCountMap = coverageCounts.stream().collect(Collectors.toMap(CoverageCount::getCoveragePeriodId, Function.identity()));
    assertTrue(coverageCountMap.containsKey(period1Jan.getId()));
    assertEquals(fullIdentifiers.size(), coverageCountMap.get(period1Jan.getId()).getBeneficiaryCount());
    assertFalse(coverageCountMap.containsKey(period1Feb.getId()));
    assertTrue(coverageCountMap.containsKey(period1March.getId()));
    assertEquals(halfIdentifiers.size(), coverageCountMap.get(period1March.getId()).getBeneficiaryCount());
    assertTrue(coverageCountMap.containsKey(period1April.getId()));
    assertEquals(fullIdentifiers.size(), coverageCountMap.get(period1April.getId()).getBeneficiaryCount());
    assertTrue(coverageCountMap.containsKey(period2Jan.getId()));
    assertEquals(halfIdentifiers.size(), coverageCountMap.get(period2Jan.getId()).getBeneficiaryCount());
    assertFalse(coverageCountMap.containsKey(period2Feb.getId()));
    assertTrue(coverageCountMap.containsKey(period2March.getId()));
    assertEquals(fullIdentifiers.size(), coverageCountMap.get(period2March.getId()).getBeneficiaryCount());
    assertFalse(coverageCountMap.containsKey(period2April.getId()));
    assertTrue(coverageCountMap.containsKey(period2May.getId()));
    assertEquals(halfIdentifiers.size(), coverageCountMap.get(period2May.getId()).getBeneficiaryCount());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) Collections.disjoint(java.util.Collections.disjoint) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Identifiers

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

the class CoverageServiceImplTest method coverageSummaryWholePeriod.

@DisplayName("Coverage summary whole period or nothing")
@Test
void coverageSummaryWholePeriod() {
    /*
         * testing-1  is a member for all months (January to April)
         * testing-2 is a member for no periods
         */
    // Bootstrap coverage periods
    coverageService.submitSearch(period1Jan.getId(), "testing");
    CoverageSearchEvent inProgressJan = startSearchAndPullEvent();
    coverageService.submitSearch(period1Feb.getId(), "testing");
    CoverageSearchEvent inProgressFeb = startSearchAndPullEvent();
    coverageService.submitSearch(period1March.getId(), "testing");
    CoverageSearchEvent inProgressMarch = startSearchAndPullEvent();
    coverageService.submitSearch(period1April.getId(), "testing");
    CoverageSearchEvent inProgressApril = startSearchAndPullEvent();
    Identifiers testing1 = createIdentifier(1L);
    coverageService.insertCoverage(inProgressJan.getId(), Set.of(testing1));
    coverageService.insertCoverage(inProgressFeb.getId(), Set.of(testing1));
    coverageService.insertCoverage(inProgressMarch.getId(), Set.of(testing1));
    coverageService.insertCoverage(inProgressApril.getId(), Set.of(testing1));
    CoveragePagingRequest pagingRequest = new CoveragePagingRequest(2, null, contract1, jobStartTime);
    CoveragePagingResult pagingResult = coverageService.pageCoverage(pagingRequest);
    List<CoverageSummary> coverageSummaries = pagingResult.getCoverageSummaries();
    assertEquals(1, coverageSummaries.size());
    CoverageSummary summary = coverageSummaries.get(0);
    assertEquals(testing1.getBeneficiaryId(), summary.getIdentifiers().getBeneficiaryId());
    assertEquals(testing1.getCurrentMbi(), summary.getIdentifiers().getCurrentMbi());
    assertTrue(summary.getDateRanges().stream().anyMatch(dr -> dr.inRange(START_JAN)));
    assertFalse(summary.getDateRanges().stream().anyMatch(dr -> dr.inRange(END_DEC)));
    assertTrue(summary.getDateRanges().stream().anyMatch(dr -> dr.inRange(END_APRIL)));
    assertFalse(summary.getDateRanges().stream().anyMatch(dr -> dr.inRange(START_MAY)));
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers(org.mockito.ArgumentMatchers) CoverageDeltaTestRepository(gov.cms.ab2d.coverage.repository.CoverageDeltaTestRepository) Date(java.util.Date) Collections.disjoint(java.util.Collections.disjoint) Autowired(org.springframework.beans.factory.annotation.Autowired) COVERAGE_ADDED(gov.cms.ab2d.coverage.repository.CoverageDeltaRepository.COVERAGE_ADDED) FilterOutByDate(gov.cms.ab2d.filter.FilterOutByDate) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) ZoneOffset(java.time.ZoneOffset) Collectors.toSet(java.util.stream.Collectors.toSet) CoverageDeltaRepository(gov.cms.ab2d.coverage.repository.CoverageDeltaRepository) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) CoverageSearchRepository(gov.cms.ab2d.coverage.repository.CoverageSearchRepository) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) Set(java.util.Set) TestPropertySource(org.springframework.test.context.TestPropertySource) AB2DCoveragePostgressqlContainer(gov.cms.ab2d.coverage.util.AB2DCoveragePostgressqlContainer) Collectors(java.util.stream.Collectors) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) AB2D_EPOCH(gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) CoveragePeriodRepository(gov.cms.ab2d.coverage.repository.CoveragePeriodRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CoverageMapping(gov.cms.ab2d.coverage.model.CoverageMapping) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Optional(java.util.Optional) CoverageDataSetup(gov.cms.ab2d.coverage.util.CoverageDataSetup) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) CoverageServiceRepository(gov.cms.ab2d.coverage.repository.CoverageServiceRepository) EntityScan(org.springframework.boot.autoconfigure.domain.EntityScan) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) PostgreSQLContainer(org.testcontainers.containers.PostgreSQLContainer) Function(java.util.function.Function) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) EntityNotFoundException(javax.persistence.EntityNotFoundException) DataSource(javax.sql.DataSource) CoverageSearchDiff(gov.cms.ab2d.coverage.model.CoverageSearchDiff) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedHashSet(java.util.LinkedHashSet) Container(org.testcontainers.junit.jupiter.Container) LogManager(gov.cms.ab2d.eventlogger.LogManager) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) COVERAGE_DELETED(gov.cms.ab2d.coverage.repository.CoverageDeltaRepository.COVERAGE_DELETED) CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) DisplayName(org.junit.jupiter.api.DisplayName) Coverage(gov.cms.ab2d.coverage.util.Coverage) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Collectors.toList(java.util.stream.Collectors.toList) CoverageDelta(gov.cms.ab2d.coverage.model.CoverageDelta) Assertions(org.junit.jupiter.api.Assertions) CoverageSearchEventRepository(gov.cms.ab2d.coverage.repository.CoverageSearchEventRepository) Comparator(java.util.Comparator) EnableJpaRepositories(org.springframework.data.jpa.repository.config.EnableJpaRepositories) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) CoverageSummary(gov.cms.ab2d.coverage.model.CoverageSummary) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Identifiers

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

the class CoverageServiceImplTest method diffCoverageWhenFirstSearch.

@DisplayName("Get differences between first search and empty")
@Test
void diffCoverageWhenFirstSearch() {
    Set<Identifiers> results1 = Set.of(createIdentifier(1231L), createIdentifier(4561L), createIdentifier(7891L));
    coverageService.submitSearch(period1Jan.getId(), "testing");
    CoverageSearchEvent inProgress1 = startSearchAndPullEvent();
    CoverageSearchEvent savedTo1 = coverageService.insertCoverage(inProgress1.getId(), results1);
    assertEquals(inProgress1, savedTo1);
    CoverageSearchDiff searchDiff = coverageService.searchDiff(period1Jan.getId());
    List<CoverageDelta> deltas = coverageDeltaTestRepository.findAll();
    assertTrue(deltas.isEmpty());
    assertEquals(3, searchDiff.getCurrentCount());
    assertEquals(0, searchDiff.getPreviousCount());
    assertEquals(0, searchDiff.getUnchanged());
    assertEquals(0, searchDiff.getDeletions());
    assertEquals(3, searchDiff.getAdditions());
}
Also used : CoverageSearchDiff(gov.cms.ab2d.coverage.model.CoverageSearchDiff) CoverageDelta(gov.cms.ab2d.coverage.model.CoverageDelta) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Identifiers (gov.cms.ab2d.coverage.model.Identifiers)24 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)18 Test (org.junit.jupiter.api.Test)18 DisplayName (org.junit.jupiter.api.DisplayName)17 LinkedHashSet (java.util.LinkedHashSet)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)12 CoverageSummary (gov.cms.ab2d.coverage.model.CoverageSummary)10 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)9 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)9 Collections.disjoint (java.util.Collections.disjoint)9 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)8 CoverageDelta (gov.cms.ab2d.coverage.model.CoverageDelta)8 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)8 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)8 CoverageSearchDiff (gov.cms.ab2d.coverage.model.CoverageSearchDiff)8 FilterOutByDate (gov.cms.ab2d.filter.FilterOutByDate)8 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)7 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)7 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)7