Skip to content

Commit

Permalink
Merge branch 'trunk' into fix_gha
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumar9 authored Jan 17, 2025
2 parents df16345 + 4f5c06f commit 0ac3a7b
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ideacrew/aca_entities.git
revision: 065aaba30717a0f4cc93d25d0b0accf7f35f03d4
revision: c49743bb104bd3471a58c6ffc148283027f2af46
branch: trunk
specs:
aca_entities (0.10.0)
Expand Down
16 changes: 16 additions & 0 deletions app/helpers/date_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# Helper methods for date-related calculations
module DateHelper
def mid_month_end?(end_on, month)
ends_this_month = end_on.month == month
last_day_of_month = Date.new(end_on.year, month, -1)
(end_on.day != last_day_of_month.day) && ends_this_month
end

def eom_end?(end_on, month)
ends_this_month = end_on.month == month
last_day_of_month = Date.new(end_on.year, month, -1)
(end_on == last_day_of_month) && ends_this_month
end
end
9 changes: 6 additions & 3 deletions app/models/data_stores/contract_holder_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class ContractHolderSubject

index({ primary_person_hbx_id: 1 })
index({ status: 1 })
index({ 'request_event.timestamp': 1 }, { name: "request_event_timestamp_index" })
index({ 'response_event.timestamp': 1 }, { name: "response_event_timestamp_index" })
index({ 'transmit_events.timestamp': 1 }, { name: "transmit_events_timestamp_index" })
index({ request_event: 1 }, { name: "request_event" })
index({ response_event: 1 }, { name: "response_event" })
index({ transmit_events: 1 }, { name: "transmit_events" })
index({ "response_event.body" => 1 })
index({ "response_event.status" => 1 })
index({ contract_holder_sync_id: 1, "response_event.body" => 1, "response_event.status" => 1 })

scope :by_primary_hbx_id, ->(hbx_id) { where(primary_person_hbx_id: hbx_id) }

Expand Down
19 changes: 11 additions & 8 deletions app/models/insurance_policies/aca_individuals/enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Enrollment
include Mongoid::Document
include Mongoid::Timestamps
include DomainModels::Domainable
include ::DateHelper

has_many :enrollments_tax_households,
class_name: 'InsurancePolicies::AcaIndividuals::EnrollmentsTaxHouseholds',
Expand Down Expand Up @@ -59,15 +60,18 @@ def enrollment_end_on
end_on.present? ? end_on : insurance_policy.start_on.end_of_year
end

# rubocop:disable Metrics/AbcSize
def pre_amt_tot_values(enrolled_thh_people, calendar_month)
if insurance_policy.term_for_np && insurance_policy.policy_end_on.month == calendar_month
format('%.2f', 0.0)
else
pre_amt_tot_month = enrolled_thh_people.map { |mem| mem.premium_schedule.premium_amount.to_f }.sum
pre_amt_tot_month = (pre_amt_tot_month * insurance_policy.insurance_product.ehb).to_f.round(2)
format('%.2f', pre_amt_tot_month)
if insurance_policy.term_for_np
end_on = insurance_policy.end_on
next_month = calendar_month == 12 ? 1 : calendar_month + 1
# if npt policy ends on the last day of the month or mid month next month
# set to 0 as we are in the first or second (for uqhp) grace period month
gpm = eom_end?(end_on, calendar_month) || mid_month_end?(end_on, next_month) || mid_month_end?(end_on, calendar_month)
return format('%.2f', 0.0) if gpm
end
pre_amt_tot_month = enrolled_thh_people.sum { |mem| mem.premium_schedule.premium_amount.to_f }
pre_amt_tot_month = (pre_amt_tot_month * insurance_policy.insurance_product.ehb).to_f.round(2)
format('%.2f', pre_amt_tot_month)
end

# Fetch eligible enrollees based on tax household members.
Expand Down Expand Up @@ -99,7 +103,6 @@ def pediatric_dental_premium(enrollments_for_month, tax_household_members, calen
health_enrolled_people: eligible_enrollees,
month: calendar_month }).value!.to_f
end
# rubocop:enable Metrics/AbcSize

def enrolled_member_by_hbx_id(hbx_id)
[[subscriber] + dependents].flatten.detect do |enrollee|
Expand Down
15 changes: 12 additions & 3 deletions app/models/insurance_policies/aca_individuals/insurance_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class InsurancePolicy
include Mongoid::Document
include Mongoid::Timestamps
include DomainModels::Domainable
include ::DateHelper

has_many :enrollments, class_name: 'InsurancePolicies::AcaIndividuals::Enrollment'

Expand Down Expand Up @@ -187,8 +188,16 @@ def fetch_enrollments_tax_households(enrs_for_month)
end

def fetch_slcsp_premium(enrs_for_month, calendar_month, tax_household = nil, aptc_tax_credit = nil)
if term_for_np
end_on = policy_end_on
next_month = calendar_month == 12 ? 1 : calendar_month + 1
# if npt policy ends on the last day of the month or mid month next month
# set to 0 as we are in the first or second (for uqhp) grace period month
gpm = eom_end?(end_on, calendar_month) || mid_month_end?(end_on, next_month) || mid_month_end?(end_on, calendar_month)
return format('%.2f', 0.0) if gpm
end

return format('%.2f', 0.0) if aptc_tax_credit.blank? || aptc_tax_credit.to_f.zero?
return format('%.2f', 0.0) if term_for_np && policy_end_on.month == calendar_month

enr_thhs = fetch_enrollments_tax_households(enrs_for_month)
slcsp_premium = enr_thhs.map(&:household_benchmark_ehb_premium).compact.sum
Expand All @@ -202,10 +211,10 @@ def fetch_slcsp_from_tax_household(tax_household, enr_thhs)
return 0.0 unless enr_thhs.any? { |enr_thh| enr_thh.tax_household.is_aqhp == true }

tax_filer = fetch_tax_filer(tax_household)
enr_thh_for_month = enr_thhs.detect do |enr_thh|
enr_thh_for_month = enr_thhs.select do |enr_thh|
enr_thh.tax_household.is_aqhp &&
enr_thh.tax_household.tax_household_members.map(&:person_id).include?(tax_filer&.person_id)
end
end.max_by { |enr_thh| enr_thh.enrolled_members_tax_household_members.count }

return 0.0 if enr_thh_for_month.blank?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module InsurancePolicies
# Operation to create insurance policy
class ConstructCv3Payload
include ::FloatHelper
include ::DateHelper
send(:include, Dry::Monads[:result, :do])

def call(params)
Expand Down Expand Up @@ -414,6 +415,7 @@ def construct_annual_premiums(months_of_year)
end

def construct_coverage_information(insurance_policy, covered_individuals, tax_household)
has_applied_aptc = false
(1..12).collect do |month|
enrollments_for_month = insurance_policy.enrollments_for_month(month, insurance_policy.start_on.year)
if insurance_policy.aasm_state == "canceled"
Expand All @@ -430,6 +432,12 @@ def construct_coverage_information(insurance_policy, covered_individuals, tax_ho
next unless any_thh_members_enrolled?(tax_household, enrollments_for_month)
next if enrollments_tax_household_for_month_empty?(enrollments_for_month, tax_household)

aptc_tax_credit = insurance_policy.applied_aptc_amount_for(enrollments_for_month, month, tax_household)
has_applied_aptc = true if aptc_tax_credit.to_f > 0.0

# if npt and mid month end date, do not include that month if aqhp
next if insurance_policy.term_for_np && mid_month_end?(insurance_policy.end_on, month) && has_applied_aptc

if tax_household.is_aqhp && covered_individuals.present?
update_covered_individuals_end_date(covered_individuals, enrollments_for_month, tax_household)
end
Expand All @@ -438,7 +446,6 @@ def construct_coverage_information(insurance_policy, covered_individuals, tax_ho
pediatric_dental_pre = enrollments_for_month.first
&.pediatric_dental_premium(enrollments_for_month, thh_members, month)
pre_amt_tot = calculate_ehb_premium_for(insurance_policy, tax_household, enrollments_for_month, month)
aptc_tax_credit = insurance_policy.applied_aptc_amount_for(enrollments_for_month, month, tax_household)

slcsp = insurance_policy.fetch_slcsp_premium(enrollments_for_month, month, tax_household, aptc_tax_credit)
total_premium = format('%.2f', (pre_amt_tot.to_f + pediatric_dental_pre))
Expand All @@ -455,7 +462,15 @@ def construct_coverage_information(insurance_policy, covered_individuals, tax_ho
end

def calculate_ehb_premium_for(insurance_policy, tax_household, enrollments_for_month, calendar_month)
return format('%.2f', 0.0) if insurance_policy.term_for_np && insurance_policy.policy_end_on.month == calendar_month

if insurance_policy.term_for_np
end_on = insurance_policy.end_on
next_month = calendar_month == 12 ? 1 : calendar_month + 1
# if npt policy ends on the last day of the month or mid month next month
# set to 0 as we are in the first or second (for uqhp) grace period month
gpm = eom_end?(end_on, calendar_month) || mid_month_end?(end_on, next_month) || mid_month_end?(end_on, calendar_month)
return format('%.2f', 0.0) if gpm
end

calender_month_begin = Date.new(insurance_policy.start_on.year, calendar_month, 1)
calender_month_end = calender_month_begin.end_of_month
Expand Down Expand Up @@ -498,7 +513,7 @@ def fetch_member_ehb_premium(enrolled_member, premium_schedule, insurance_policy

def get_enrolled_members_by_tax_household_for(enrollments_for_month, tax_household)
enrs_thhs = fetch_enrollments_tax_households(enrollments_for_month)
valid_enr_thh = if enrs_thhs.size > 1
valid_enr_thh = if enrs_thhs.size > 1 && tax_household.is_aqhp
enrs_thhs.select do |enr_thh|
valid_enrollment_tax_household?(enr_thh, tax_household) && enr_thh.tax_household.is_aqhp
end
Expand Down Expand Up @@ -563,7 +578,7 @@ def fetch_thh_members_from_enr_thhs(enr_thhs, tax_household)
return tax_household.tax_household_members unless tax_household.is_aqhp

enr_thhs_for_month = enr_thhs.select do |enr_thh|
enr_thh.tax_household.is_aqhp && valid_enrollment_tax_household?(enr_thh, tax_household)
valid_enrollment_tax_household?(enr_thh, tax_household)
end
enrolled_thh_members_person_ids = enr_thhs_for_month&.flat_map(&:tax_household)
&.flat_map(&:tax_household_members)&.uniq(&:person_id)
Expand Down
48 changes: 48 additions & 0 deletions spec/models/insurance_policies/aca_individuals/enrollment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
let(:insurance_policy) do
FactoryBot.create(:insurance_policy, start_on: Date.new(year, 1, 1), end_on: Date.new(year, 12, 31))
end
let(:insurance_policy_npt_eom) do
FactoryBot.create(:insurance_policy, start_on: Date.new(year, 1, 1),
end_on: Date.new(year, 5, 31),
term_for_np: true)
end
let(:insurance_policy_npt_mid_month) do
FactoryBot.create(:insurance_policy, start_on: Date.new(year, 1, 1),
end_on: Date.new(year, 3, 3),
term_for_np: true)
end
let(:subscriber) { FactoryBot.build(:enrolled_member, person: subscriber_person) }
let(:dependents) do
[
Expand All @@ -29,6 +39,24 @@
dependents: dependents)
end

let(:enrollment_npt_eom) do
FactoryBot.create(:enrollment, start_on: Date.new(year, 1, 1),
effectuated_on: Date.new(year, 1, 1),
end_on: Date.new(year, 5, 31),
insurance_policy: insurance_policy_npt_eom,
subscriber: subscriber,
dependents: dependents)
end

let(:enrollment_npt_mid_month) do
FactoryBot.create(:enrollment, start_on: Date.new(year, 1, 1),
effectuated_on: Date.new(year, 1, 1),
end_on: Date.new(year, 5, 31),
insurance_policy: insurance_policy_npt_mid_month,
subscriber: subscriber,
dependents: dependents)
end

let(:tax_household_members) do
[
double('InsurancePolicies::AcaIndividuals::TaxHouseholdMember', is_medicaid_chip_eligible: true, person: subscriber_person),
Expand Down Expand Up @@ -91,4 +119,24 @@
end
end
end

describe '#pre_amt_tot_values' do
context 'insurance_policy term_for_np is true and eom end date' do
it 'returns 0.00' do
expect(enrollment_npt_eom.pre_amt_tot_values([subscriber], 5)).to eq('0.00')
end
end

context 'insurance_policy term_for_np is true and next month mid month end date' do
it 'returns 0.00' do
expect(enrollment_npt_mid_month.pre_amt_tot_values([subscriber], 2)).to eq('0.00')
end
end

context 'insurance_policy term_for_np is true and mid month end date' do
it 'returns 0.00' do
expect(enrollment_npt_mid_month.pre_amt_tot_values([subscriber], 3)).to eq('0.00')
end
end
end
end
Loading

0 comments on commit 0ac3a7b

Please sign in to comment.