Search in sources :

Example 1 with BeneficiaryMonthly

use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProvider method queryBeneCountByPartDContractCodeAndYearMonth.

/**
 * @param yearMonth the {@link BeneficiaryMonthly#getYearMonth()} value to match against
 * @param contractId the {@link BeneficiaryMonthly#getPartDContractNumberId()} value to match
 *     against
 * @return the count of matching {@link Beneficiary#getBeneficiaryId()} values
 */
@Trace
private long queryBeneCountByPartDContractCodeAndYearMonth(LocalDate yearMonth, String contractId) {
    // Create the query to run.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> beneCountCriteria = builder.createQuery(Long.class);
    Root<BeneficiaryMonthly> beneMonthlyRoot = beneCountCriteria.from(BeneficiaryMonthly.class);
    beneCountCriteria.select(builder.count(beneMonthlyRoot));
    beneCountCriteria.where(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.yearMonth), yearMonth), builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.partDContractNumberId), contractId));
    // Run the query and return the results.
    Optional<Long> matchingBeneCount = Optional.empty();
    Long beneHistoryMatchesTimerQueryNanoSeconds = null;
    Timer.Context matchingBeneCountTimer = metricRegistry.timer(MetricRegistry.name(getClass().getSimpleName(), "query", "bene_count_by_year_month_part_d_contract_id")).time();
    try {
        matchingBeneCount = Optional.of(entityManager.createQuery(beneCountCriteria).getSingleResult());
        return matchingBeneCount.get();
    } finally {
        beneHistoryMatchesTimerQueryNanoSeconds = matchingBeneCountTimer.stop();
        TransformerUtils.recordQueryInMdc("bene_count_by_year_month_part_d_contract_id", beneHistoryMatchesTimerQueryNanoSeconds, matchingBeneCount.isPresent() ? 1 : 0);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Timer(com.codahale.metrics.Timer) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Trace(com.newrelic.api.agent.Trace)

Example 2 with BeneficiaryMonthly

use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProvider method queryBeneCountByPartDContractCodeAndYearMonth.

/**
 * @param yearMonth the {@link BeneficiaryMonthly#getYearMonth()} value to match against
 * @param contractId the {@link BeneficiaryMonthly#getPartDContractNumberId()} value to match
 *     against
 * @return the count of matching {@link Beneficiary#getBeneficiaryId()} values
 */
@Trace
private long queryBeneCountByPartDContractCodeAndYearMonth(LocalDate yearMonth, String contractId) {
    // Create the query to run.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> beneCountCriteria = builder.createQuery(Long.class);
    Root<BeneficiaryMonthly> beneMonthlyRoot = beneCountCriteria.from(BeneficiaryMonthly.class);
    beneCountCriteria.select(builder.count(beneMonthlyRoot));
    beneCountCriteria.where(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.yearMonth), yearMonth), builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.partDContractNumberId), contractId));
    // Run the query and return the results.
    Optional<Long> matchingBeneCount = Optional.empty();
    Long beneHistoryMatchesTimerQueryNanoSeconds = null;
    Timer.Context matchingBeneCountTimer = metricRegistry.timer(MetricRegistry.name(getClass().getSimpleName(), "query", "bene_count_by_year_month_part_d_contract_id")).time();
    try {
        matchingBeneCount = Optional.of(entityManager.createQuery(beneCountCriteria).getSingleResult());
        return matchingBeneCount.get();
    } finally {
        beneHistoryMatchesTimerQueryNanoSeconds = matchingBeneCountTimer.stop();
        TransformerUtilsV2.recordQueryInMdc("bene_count_by_year_month_part_d_contract_id", beneHistoryMatchesTimerQueryNanoSeconds, matchingBeneCount.isPresent() ? 1 : 0);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Timer(com.codahale.metrics.Timer) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Trace(com.newrelic.api.agent.Trace)

Example 3 with BeneficiaryMonthly

use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.

the class RifLoaderIT method loadInitialEnrollmentShouldCount21SinceThereIsAUpdateOf8MonthsAndAUpdateOf9Months.

/*
   * This test checks that all enrollment data for month july in its 2 year is updated when there is data
   * for august that comes in.
   */
@Test
public void loadInitialEnrollmentShouldCount21SinceThereIsAUpdateOf8MonthsAndAUpdateOf9Months() {
    // Load first year of data
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    // Load 8 months of data in year two
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_U_BENES_CHANGED_WITH_8_MONTHS.getResources()));
    EntityManagerFactory entityManagerFactory = PipelineTestUtils.get().getPipelineApplicationState().getEntityManagerFactory();
    EntityManager entityManager = null;
    try {
        entityManager = entityManagerFactory.createEntityManager();
        Beneficiary beneficiaryFromDb = entityManager.find(Beneficiary.class, "567834");
        assertEquals(20, beneficiaryFromDb.getBeneficiaryMonthlys().size());
        BeneficiaryMonthly augustMonthly = beneficiaryFromDb.getBeneficiaryMonthlys().get(19);
        assertEquals("2019-08-01", augustMonthly.getYearMonth().toString());
        assertEquals("C", augustMonthly.getEntitlementBuyInInd().get().toString());
        assertEquals("AA", augustMonthly.getFipsStateCntyCode().get());
        assertFalse(augustMonthly.getHmoIndicatorInd().isPresent());
        assertEquals("AA", augustMonthly.getMedicaidDualEligibilityCode().get());
        assertEquals("AA", augustMonthly.getMedicareStatusCode().get());
        assertEquals("C", augustMonthly.getPartCContractNumberId().get());
        assertEquals("C", augustMonthly.getPartCPbpNumberId().get());
        assertEquals("C", augustMonthly.getPartCPlanTypeCode().get());
        assertEquals("C", augustMonthly.getPartDContractNumberId().get());
        assertEquals("AA", augustMonthly.getPartDLowIncomeCostShareGroupCode().get());
        assertFalse(augustMonthly.getPartDPbpNumberId().isPresent());
        assertEquals("C", augustMonthly.getPartDRetireeDrugSubsidyInd().get().toString());
        assertFalse(augustMonthly.getPartDSegmentNumberId().isPresent());
    } finally {
        if (entityManager != null)
            entityManager.close();
    }
    // Load 9 months of data in year two with some data updated in july
    loadSample(Arrays.asList(StaticRifResourceGroup.SAMPLE_U_BENES_CHANGED_WITH_9_MONTHS.getResources()));
    entityManager = null;
    try {
        entityManager = entityManagerFactory.createEntityManager();
        Beneficiary beneficiaryFromDb = entityManager.find(Beneficiary.class, "567834");
        assertEquals(21, beneficiaryFromDb.getBeneficiaryMonthlys().size());
        BeneficiaryMonthly augustMonthly = beneficiaryFromDb.getBeneficiaryMonthlys().get(19);
        assertEquals("2019-08-01", augustMonthly.getYearMonth().toString());
        assertEquals("C", augustMonthly.getEntitlementBuyInInd().get().toString());
        assertEquals("AA", augustMonthly.getFipsStateCntyCode().get());
        // Updated in file
        assertEquals("C", augustMonthly.getHmoIndicatorInd().get().toString());
        assertEquals("AA", augustMonthly.getMedicaidDualEligibilityCode().get());
        assertEquals("AA", augustMonthly.getMedicareStatusCode().get());
        assertEquals("C", augustMonthly.getPartCContractNumberId().get());
        assertEquals("C", augustMonthly.getPartCPbpNumberId().get());
        assertEquals("C", augustMonthly.getPartCPlanTypeCode().get());
        assertEquals("C", augustMonthly.getPartDContractNumberId().get());
        assertEquals("AA", augustMonthly.getPartDLowIncomeCostShareGroupCode().get());
        assertFalse(augustMonthly.getPartDPbpNumberId().isPresent());
        assertEquals("C", augustMonthly.getPartDRetireeDrugSubsidyInd().get().toString());
        assertFalse(augustMonthly.getPartDSegmentNumberId().isPresent());
        BeneficiaryMonthly septMonthly = beneficiaryFromDb.getBeneficiaryMonthlys().get(20);
        assertEquals("2019-09-01", septMonthly.getYearMonth().toString());
        assertFalse(septMonthly.getEntitlementBuyInInd().isPresent());
        assertFalse(septMonthly.getFipsStateCntyCode().isPresent());
        assertFalse(septMonthly.getHmoIndicatorInd().isPresent());
        assertEquals("AA", septMonthly.getMedicaidDualEligibilityCode().get());
        assertFalse(septMonthly.getMedicareStatusCode().isPresent());
        assertFalse(septMonthly.getPartCContractNumberId().isPresent());
        assertFalse(septMonthly.getPartCPbpNumberId().isPresent());
        assertFalse(septMonthly.getPartCPlanTypeCode().isPresent());
        assertFalse(septMonthly.getPartDContractNumberId().isPresent());
        assertFalse(septMonthly.getPartDLowIncomeCostShareGroupCode().isPresent());
        assertFalse(septMonthly.getPartDPbpNumberId().isPresent());
        assertEquals("C", septMonthly.getPartDRetireeDrugSubsidyInd().get().toString());
        assertFalse(septMonthly.getPartDSegmentNumberId().isPresent());
    } finally {
        if (entityManager != null)
            entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 4 with BeneficiaryMonthly

use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.

the class RifLoader method getBeneficiaryMonthly.

public static BeneficiaryMonthly getBeneficiaryMonthly(Beneficiary parentBeneficiary, LocalDate yearMonth, Optional<Character> entitlementBuyInInd, Optional<String> fipsStateCntyCode, Optional<Character> hmoIndicatorInd, Optional<String> medicaidDualEligibilityCode, Optional<String> medicareStatusCode, Optional<String> partCContractNumberId, Optional<String> partCPbpNumberId, Optional<String> partCPlanTypeCode, Optional<String> partDContractNumberId, Optional<String> partDLowIncomeCostShareGroupCode, Optional<String> partDPbpNumberId, Optional<Character> partDRetireeDrugSubsidyInd, Optional<String> partDSegmentNumberId) {
    BeneficiaryMonthly beneficiaryMonthly = null;
    if (entitlementBuyInInd.isPresent() || fipsStateCntyCode.isPresent() || hmoIndicatorInd.isPresent() || medicaidDualEligibilityCode.isPresent() || medicareStatusCode.isPresent() || partCContractNumberId.isPresent() || partCPbpNumberId.isPresent() || partCPlanTypeCode.isPresent() || partDContractNumberId.isPresent() || partDLowIncomeCostShareGroupCode.isPresent() || partDPbpNumberId.isPresent() || partDRetireeDrugSubsidyInd.isPresent() || partDSegmentNumberId.isPresent()) {
        beneficiaryMonthly = new BeneficiaryMonthly();
        beneficiaryMonthly.setParentBeneficiary(parentBeneficiary);
        beneficiaryMonthly.setYearMonth(yearMonth);
        beneficiaryMonthly.setEntitlementBuyInInd(entitlementBuyInInd);
        beneficiaryMonthly.setFipsStateCntyCode(fipsStateCntyCode);
        beneficiaryMonthly.setHmoIndicatorInd(hmoIndicatorInd);
        beneficiaryMonthly.setMedicaidDualEligibilityCode(medicaidDualEligibilityCode);
        beneficiaryMonthly.setMedicareStatusCode(medicareStatusCode);
        beneficiaryMonthly.setPartCContractNumberId(partCContractNumberId);
        beneficiaryMonthly.setPartCPbpNumberId(partCPbpNumberId);
        beneficiaryMonthly.setPartCPlanTypeCode(partCPlanTypeCode);
        beneficiaryMonthly.setPartDContractNumberId(partDContractNumberId);
        beneficiaryMonthly.setPartDLowIncomeCostShareGroupCode(partDLowIncomeCostShareGroupCode);
        beneficiaryMonthly.setPartDPbpNumberId(partDPbpNumberId);
        beneficiaryMonthly.setPartDRetireeDrugSubsidyInd(partDRetireeDrugSubsidyInd);
        beneficiaryMonthly.setPartDSegmentNumberId(partDSegmentNumberId);
    }
    return beneficiaryMonthly;
}
Also used : BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly)

Example 5 with BeneficiaryMonthly

use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProviderIT method searchByPartDContractWithoutYear.

/**
 * Verifies that {@link
 * PatientResourceProvider#searchByCoverageContract(ca.uhn.fhir.rest.param.TokenParam,
 * ca.uhn.fhir.rest.param.TokenParam, String, ca.uhn.fhir.rest.api.server.RequestDetails)} works
 * as expected, when no year is specified (hopefully causing it to substitute the current year).
 */
@Test
public void searchByPartDContractWithoutYear() {
    /*
     * TODO Once AB2D has switched to always specifying the year, this needs to become an invalid
     * request and this test will need to be updated to reflect that, then.
     */
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES));
    IGenericClient fhirClient = createFhirClientWithIncludeIdentifiersMbi();
    // First, adjust the bene's reference year in the DB.
    ServerTestUtils.get().doTransaction((entityManager) -> {
        CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        CriteriaQuery<BeneficiaryMonthly> select = builder.createQuery(BeneficiaryMonthly.class);
        select.from(BeneficiaryMonthly.class);
        List<BeneficiaryMonthly> beneMonthlys = entityManager.createQuery(select).getResultList();
        for (BeneficiaryMonthly beneMonthly : beneMonthlys) {
            LocalDate yearMonth = beneMonthly.getYearMonth();
            CriteriaUpdate<BeneficiaryMonthly> update = builder.createCriteriaUpdate(BeneficiaryMonthly.class);
            Root<BeneficiaryMonthly> beneMonthlyRoot = update.from(BeneficiaryMonthly.class);
            update.set(BeneficiaryMonthly_.yearMonth, LocalDate.of(Year.now().getValue(), yearMonth.getMonthValue(), yearMonth.getDayOfMonth()));
            update.where(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary), beneMonthly.getParentBeneficiary()), builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.yearMonth), yearMonth));
            entityManager.createQuery(update).executeUpdate();
        }
    });
    // Should return a single match
    Bundle searchResults = fhirClient.search().forResource(Patient.class).where(new TokenClientParam("_has:Coverage.extension").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.PTDCNTRCT01), "S4607")).returnBundle(Bundle.class).execute();
    // Verify that it found the expected bene.
    assertNotNull(searchResults);
    assertEquals(1, searchResults.getEntry().size());
    Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
    Beneficiary expectedBene = (Beneficiary) loadedRecords.get(0);
    assertEquals(expectedBene.getBeneficiaryId(), patientFromSearchResult.getIdElement().getIdPart());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle) Patient(org.hl7.fhir.dstu3.model.Patient) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) LocalDate(java.time.LocalDate) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Aggregations

BeneficiaryMonthly (gov.cms.bfd.model.rif.BeneficiaryMonthly)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 Timer (com.codahale.metrics.Timer)5 Trace (com.newrelic.api.agent.Trace)4 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)3 ArrayList (java.util.ArrayList)3 Predicate (javax.persistence.criteria.Predicate)2 Test (org.junit.jupiter.api.Test)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)1 Gauge (com.codahale.metrics.Gauge)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 HikariProxyConnection (com.zaxxer.hikari.pool.HikariProxyConnection)1 BeneficiaryCsvWriter (gov.cms.bfd.model.rif.BeneficiaryCsvWriter)1 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)1 Beneficiary_ (gov.cms.bfd.model.rif.Beneficiary_)1 CarrierClaim (gov.cms.bfd.model.rif.CarrierClaim)1 CarrierClaimCsvWriter (gov.cms.bfd.model.rif.CarrierClaimCsvWriter)1 CarrierClaimLine (gov.cms.bfd.model.rif.CarrierClaimLine)1 LoadedBatch (gov.cms.bfd.model.rif.LoadedBatch)1