use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProvider method queryBeneficiaryIdsByPartDContractCodeAndYearMonth.
/**
* @param yearMonth the {@link BeneficiaryMonthly#getYearMonth()} value to match against
* @param contractId the {@link BeneficiaryMonthly#getPartDContractNumberId()} value to match
* against
* @param paging the {@link PatientLinkBuilder} being used for paging
* @return the {@link List} of matching {@link Beneficiary#getBeneficiaryId()} values
*/
@Trace
private List<String> queryBeneficiaryIdsByPartDContractCodeAndYearMonth(LocalDate yearMonth, String contractId, PatientLinkBuilder paging) {
// Create the query to run.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> beneIdCriteria = builder.createQuery(String.class);
Root<BeneficiaryMonthly> beneMonthlyRoot = beneIdCriteria.from(BeneficiaryMonthly.class);
beneIdCriteria.select(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary).get(Beneficiary_.beneficiaryId));
List<Predicate> wherePredicates = new ArrayList<>();
wherePredicates.add(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.yearMonth), yearMonth));
wherePredicates.add(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.partDContractNumberId), contractId));
if (paging.isPagingRequested() && !paging.isFirstPage()) {
wherePredicates.add(builder.greaterThan(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary).get(Beneficiary_.beneficiaryId), paging.getCursor()));
}
beneIdCriteria.where(builder.and(wherePredicates.toArray(new Predicate[wherePredicates.size()])));
beneIdCriteria.orderBy(builder.asc(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary)));
// Run the query and return the results.
List<String> matchingBeneIds = null;
Long beneHistoryMatchesTimerQueryNanoSeconds = null;
Timer.Context beneIdMatchesTimer = metricRegistry.timer(MetricRegistry.name(getClass().getSimpleName(), "query", "bene_ids_by_year_month_part_d_contract_id")).time();
try {
matchingBeneIds = entityManager.createQuery(beneIdCriteria).setMaxResults(paging.getQueryMaxSize()).getResultList();
return matchingBeneIds;
} finally {
beneHistoryMatchesTimerQueryNanoSeconds = beneIdMatchesTimer.stop();
TransformerUtils.recordQueryInMdc("bene_ids_by_year_month_part_d_contract_id", beneHistoryMatchesTimerQueryNanoSeconds, matchingBeneIds == null ? 0 : matchingBeneIds.size());
}
}
use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.
the class RifLoader method updateBeneficiaryMonthly.
/**
* Ensures that a {@link BeneficiaryMonthly} record is created or updated for the specified {@link
* Beneficiary}, if that {@link Beneficiary} already exists and is just being updated.
*
* @param newBeneficiaryRecord the {@link Beneficiary} record being processed
* @param oldBeneficiaryRecord the previous/current version of the {@link Beneficiary} (as it
* exists in the database before applying the specified {@link RifRecordEvent})
*/
private static void updateBeneficiaryMonthly(Beneficiary newBeneficiaryRecord, Optional<Beneficiary> oldBeneficiaryRecord) {
if (newBeneficiaryRecord.getBeneEnrollmentReferenceYear().isPresent()) {
int year = newBeneficiaryRecord.getBeneEnrollmentReferenceYear().get().intValue();
List<BeneficiaryMonthly> currentYearBeneficiaryMonthly = new ArrayList<BeneficiaryMonthly>();
BeneficiaryMonthly beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 1, 1), newBeneficiaryRecord.getEntitlementBuyInJanInd(), newBeneficiaryRecord.getFipsStateCntyJanCode(), newBeneficiaryRecord.getHmoIndicatorJanInd(), newBeneficiaryRecord.getMedicaidDualEligibilityJanCode(), newBeneficiaryRecord.getMedicareStatusJanCode(), newBeneficiaryRecord.getPartCContractNumberJanId(), newBeneficiaryRecord.getPartCPbpNumberJanId(), newBeneficiaryRecord.getPartCPlanTypeJanCode(), newBeneficiaryRecord.getPartDContractNumberJanId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupJanCode(), newBeneficiaryRecord.getPartDPbpNumberJanId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyJanInd(), newBeneficiaryRecord.getPartDSegmentNumberJanId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 2, 1), newBeneficiaryRecord.getEntitlementBuyInFebInd(), newBeneficiaryRecord.getFipsStateCntyFebCode(), newBeneficiaryRecord.getHmoIndicatorFebInd(), newBeneficiaryRecord.getMedicaidDualEligibilityFebCode(), newBeneficiaryRecord.getMedicareStatusFebCode(), newBeneficiaryRecord.getPartCContractNumberFebId(), newBeneficiaryRecord.getPartCPbpNumberFebId(), newBeneficiaryRecord.getPartCPlanTypeFebCode(), newBeneficiaryRecord.getPartDContractNumberFebId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupFebCode(), newBeneficiaryRecord.getPartDPbpNumberFebId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyFebInd(), newBeneficiaryRecord.getPartDSegmentNumberFebId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 3, 1), newBeneficiaryRecord.getEntitlementBuyInMarInd(), newBeneficiaryRecord.getFipsStateCntyMarCode(), newBeneficiaryRecord.getHmoIndicatorMarInd(), newBeneficiaryRecord.getMedicaidDualEligibilityMarCode(), newBeneficiaryRecord.getMedicareStatusMarCode(), newBeneficiaryRecord.getPartCContractNumberMarId(), newBeneficiaryRecord.getPartCPbpNumberMarId(), newBeneficiaryRecord.getPartCPlanTypeMarCode(), newBeneficiaryRecord.getPartDContractNumberMarId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupMarCode(), newBeneficiaryRecord.getPartDPbpNumberMarId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyMarInd(), newBeneficiaryRecord.getPartDSegmentNumberMarId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 4, 1), newBeneficiaryRecord.getEntitlementBuyInAprInd(), newBeneficiaryRecord.getFipsStateCntyAprCode(), newBeneficiaryRecord.getHmoIndicatorAprInd(), newBeneficiaryRecord.getMedicaidDualEligibilityAprCode(), newBeneficiaryRecord.getMedicareStatusAprCode(), newBeneficiaryRecord.getPartCContractNumberAprId(), newBeneficiaryRecord.getPartCPbpNumberAprId(), newBeneficiaryRecord.getPartCPlanTypeAprCode(), newBeneficiaryRecord.getPartDContractNumberAprId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupAprCode(), newBeneficiaryRecord.getPartDPbpNumberAprId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyAprInd(), newBeneficiaryRecord.getPartDSegmentNumberAprId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 5, 1), newBeneficiaryRecord.getEntitlementBuyInMayInd(), newBeneficiaryRecord.getFipsStateCntyMayCode(), newBeneficiaryRecord.getHmoIndicatorMayInd(), newBeneficiaryRecord.getMedicaidDualEligibilityMayCode(), newBeneficiaryRecord.getMedicareStatusMayCode(), newBeneficiaryRecord.getPartCContractNumberMayId(), newBeneficiaryRecord.getPartCPbpNumberMayId(), newBeneficiaryRecord.getPartCPlanTypeMayCode(), newBeneficiaryRecord.getPartDContractNumberMayId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupMayCode(), newBeneficiaryRecord.getPartDPbpNumberMayId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyMayInd(), newBeneficiaryRecord.getPartDSegmentNumberMayId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 6, 1), newBeneficiaryRecord.getEntitlementBuyInJunInd(), newBeneficiaryRecord.getFipsStateCntyJunCode(), newBeneficiaryRecord.getHmoIndicatorJunInd(), newBeneficiaryRecord.getMedicaidDualEligibilityJunCode(), newBeneficiaryRecord.getMedicareStatusJunCode(), newBeneficiaryRecord.getPartCContractNumberJunId(), newBeneficiaryRecord.getPartCPbpNumberJunId(), newBeneficiaryRecord.getPartCPlanTypeJunCode(), newBeneficiaryRecord.getPartDContractNumberJunId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupJunCode(), newBeneficiaryRecord.getPartDPbpNumberJunId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyJunInd(), newBeneficiaryRecord.getPartDSegmentNumberJunId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 7, 1), newBeneficiaryRecord.getEntitlementBuyInJulInd(), newBeneficiaryRecord.getFipsStateCntyJulCode(), newBeneficiaryRecord.getHmoIndicatorJulInd(), newBeneficiaryRecord.getMedicaidDualEligibilityJulCode(), newBeneficiaryRecord.getMedicareStatusJulCode(), newBeneficiaryRecord.getPartCContractNumberJulId(), newBeneficiaryRecord.getPartCPbpNumberJulId(), newBeneficiaryRecord.getPartCPlanTypeJulCode(), newBeneficiaryRecord.getPartDContractNumberJulId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupJulCode(), newBeneficiaryRecord.getPartDPbpNumberJulId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyJulInd(), newBeneficiaryRecord.getPartDSegmentNumberJulId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 8, 1), newBeneficiaryRecord.getEntitlementBuyInAugInd(), newBeneficiaryRecord.getFipsStateCntyAugCode(), newBeneficiaryRecord.getHmoIndicatorAugInd(), newBeneficiaryRecord.getMedicaidDualEligibilityAugCode(), newBeneficiaryRecord.getMedicareStatusAugCode(), newBeneficiaryRecord.getPartCContractNumberAugId(), newBeneficiaryRecord.getPartCPbpNumberAugId(), newBeneficiaryRecord.getPartCPlanTypeAugCode(), newBeneficiaryRecord.getPartDContractNumberAugId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupAugCode(), newBeneficiaryRecord.getPartDPbpNumberAugId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyAugInd(), newBeneficiaryRecord.getPartDSegmentNumberAugId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 9, 1), newBeneficiaryRecord.getEntitlementBuyInSeptInd(), newBeneficiaryRecord.getFipsStateCntySeptCode(), newBeneficiaryRecord.getHmoIndicatorSeptInd(), newBeneficiaryRecord.getMedicaidDualEligibilitySeptCode(), newBeneficiaryRecord.getMedicareStatusSeptCode(), newBeneficiaryRecord.getPartCContractNumberSeptId(), newBeneficiaryRecord.getPartCPbpNumberSeptId(), newBeneficiaryRecord.getPartCPlanTypeSeptCode(), newBeneficiaryRecord.getPartDContractNumberSeptId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupSeptCode(), newBeneficiaryRecord.getPartDPbpNumberSeptId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidySeptInd(), newBeneficiaryRecord.getPartDSegmentNumberSeptId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 10, 1), newBeneficiaryRecord.getEntitlementBuyInOctInd(), newBeneficiaryRecord.getFipsStateCntyOctCode(), newBeneficiaryRecord.getHmoIndicatorOctInd(), newBeneficiaryRecord.getMedicaidDualEligibilityOctCode(), newBeneficiaryRecord.getMedicareStatusOctCode(), newBeneficiaryRecord.getPartCContractNumberOctId(), newBeneficiaryRecord.getPartCPbpNumberOctId(), newBeneficiaryRecord.getPartCPlanTypeOctCode(), newBeneficiaryRecord.getPartDContractNumberOctId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupOctCode(), newBeneficiaryRecord.getPartDPbpNumberOctId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyOctInd(), newBeneficiaryRecord.getPartDSegmentNumberOctId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 11, 1), newBeneficiaryRecord.getEntitlementBuyInNovInd(), newBeneficiaryRecord.getFipsStateCntyNovCode(), newBeneficiaryRecord.getHmoIndicatorNovInd(), newBeneficiaryRecord.getMedicaidDualEligibilityNovCode(), newBeneficiaryRecord.getMedicareStatusNovCode(), newBeneficiaryRecord.getPartCContractNumberNovId(), newBeneficiaryRecord.getPartCPbpNumberNovId(), newBeneficiaryRecord.getPartCPlanTypeNovCode(), newBeneficiaryRecord.getPartDContractNumberNovId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupNovCode(), newBeneficiaryRecord.getPartDPbpNumberNovId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyNovInd(), newBeneficiaryRecord.getPartDSegmentNumberNovId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
beneficiaryMonthly = getBeneficiaryMonthly(newBeneficiaryRecord, LocalDate.of(year, 12, 1), newBeneficiaryRecord.getEntitlementBuyInDecInd(), newBeneficiaryRecord.getFipsStateCntyDecCode(), newBeneficiaryRecord.getHmoIndicatorDecInd(), newBeneficiaryRecord.getMedicaidDualEligibilityDecCode(), newBeneficiaryRecord.getMedicareStatusDecCode(), newBeneficiaryRecord.getPartCContractNumberDecId(), newBeneficiaryRecord.getPartCPbpNumberDecId(), newBeneficiaryRecord.getPartCPlanTypeDecCode(), newBeneficiaryRecord.getPartDContractNumberDecId(), newBeneficiaryRecord.getPartDLowIncomeCostShareGroupDecCode(), newBeneficiaryRecord.getPartDPbpNumberDecId(), newBeneficiaryRecord.getPartDRetireeDrugSubsidyDecInd(), newBeneficiaryRecord.getPartDSegmentNumberDecId());
if (beneficiaryMonthly != null) {
currentYearBeneficiaryMonthly.add(beneficiaryMonthly);
}
if (currentYearBeneficiaryMonthly.size() > 0) {
List<BeneficiaryMonthly> currentBeneficiaryMonthlyWithUpdates;
if (oldBeneficiaryRecord.isPresent() && oldBeneficiaryRecord.get().getBeneficiaryMonthlys().size() > 0) {
currentBeneficiaryMonthlyWithUpdates = oldBeneficiaryRecord.get().getBeneficiaryMonthlys();
List<BeneficiaryMonthly> currentYearBeneficiaryMonthlyPrevious = oldBeneficiaryRecord.get().getBeneficiaryMonthlys().stream().filter(e -> year == e.getYearMonth().getYear()).collect(Collectors.toList());
for (BeneficiaryMonthly previousEnrollment : currentYearBeneficiaryMonthlyPrevious) {
currentBeneficiaryMonthlyWithUpdates.remove(previousEnrollment);
}
} else {
currentBeneficiaryMonthlyWithUpdates = new LinkedList<BeneficiaryMonthly>();
}
currentBeneficiaryMonthlyWithUpdates.addAll(currentYearBeneficiaryMonthly);
newBeneficiaryRecord.setBeneficiaryMonthlys(currentBeneficiaryMonthlyWithUpdates);
}
}
}
use of gov.cms.bfd.model.rif.BeneficiaryMonthly in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProvider method queryBeneficiaryIdsByPartDContractCodeAndYearMonth.
/**
* @param yearMonth the {@link BeneficiaryMonthly#getYearMonth()} value to match against
* @param contractId the {@link BeneficiaryMonthly#getPartDContractNumberId()} value to match
* against
* @param paging the {@link PatientLinkBuilder} being used for paging
* @return the {@link List} of matching {@link Beneficiary#getBeneficiaryId()} values
*/
@Trace
private List<String> queryBeneficiaryIdsByPartDContractCodeAndYearMonth(LocalDate yearMonth, String contractId, PatientLinkBuilder paging) {
// Create the query to run.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> beneIdCriteria = builder.createQuery(String.class);
Root<BeneficiaryMonthly> beneMonthlyRoot = beneIdCriteria.from(BeneficiaryMonthly.class);
beneIdCriteria.select(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary).get(Beneficiary_.beneficiaryId));
List<Predicate> wherePredicates = new ArrayList<>();
wherePredicates.add(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.yearMonth), yearMonth));
wherePredicates.add(builder.equal(beneMonthlyRoot.get(BeneficiaryMonthly_.partDContractNumberId), contractId));
if (paging.isPagingRequested() && !paging.isFirstPage()) {
wherePredicates.add(builder.greaterThan(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary).get(Beneficiary_.beneficiaryId), paging.getCursor()));
}
beneIdCriteria.where(builder.and(wherePredicates.toArray(new Predicate[wherePredicates.size()])));
beneIdCriteria.orderBy(builder.asc(beneMonthlyRoot.get(BeneficiaryMonthly_.parentBeneficiary)));
// Run the query and return the results.
List<String> matchingBeneIds = null;
Long beneHistoryMatchesTimerQueryNanoSeconds = null;
Timer.Context beneIdMatchesTimer = metricRegistry.timer(MetricRegistry.name(getClass().getSimpleName(), "query", "bene_ids_by_year_month_part_d_contract_id")).time();
try {
matchingBeneIds = entityManager.createQuery(beneIdCriteria).setMaxResults(paging.getQueryMaxSize()).getResultList();
return matchingBeneIds;
} finally {
beneHistoryMatchesTimerQueryNanoSeconds = beneIdMatchesTimer.stop();
TransformerUtilsV2.recordQueryInMdc("bene_ids_by_year_month_part_d_contract_id", beneHistoryMatchesTimerQueryNanoSeconds, matchingBeneIds == null ? 0 : matchingBeneIds.size());
}
}
Aggregations