Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #MemberEligibility: fix calculate_tax_household_income to includ… #46

Merged
merged 3 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,35 @@ def calculate_eligibility_date
end

def calculate_member_income(applicant, income_threshold)
return BigDecimal('0') unless applicant.incomes.present?
applicant.incomes.inject(BigDecimal('0')) do |annual_total, income|
annual_total + eligible_earned_annual_income(applicant, income, income_threshold)
end
member_income =
if applicant.incomes.present?
applicant.incomes.inject(BigDecimal('0')) do |annual_total, income|
annual_total + eligible_earned_annual_income(applicant, income, income_threshold)
end
else
BigDecimal('0')
end

member_deduction =
if applicant.deductions.present?
applicant.deductions.inject(BigDecimal('0')) do |annual_total, deduction|
annual_total + eligible_annual_deduction(deduction)
end
else
BigDecimal('0')
end

member_income - member_deduction
end

def eligible_annual_deduction(deduction)
return BigDecimal('0') unless amount_for_current_year?(deduction)
compute_annual_amount(deduction)
end

def eligible_earned_annual_income(applicant, income, income_threshold)
return BigDecimal('0') unless income_for_current_year?(income)
annual_tot = compute_annual_income(income)
return BigDecimal('0') unless amount_for_current_year?(income)
annual_tot = compute_annual_amount(income)
return annual_tot unless applicant.is_claimed_as_tax_dependent

if income.earned?
Expand All @@ -81,47 +101,47 @@ def eligible_earned_annual_income(applicant, income, income_threshold)
end
end

def compute_annual_income(income)
income_end_date = calculate_end_date(income)
income_start_date = calculate_start_date(income)
income_per_day = calculate_income_per_day(income)
def compute_annual_amount(evidence)
evidence_end_date = calculate_end_date(evidence)
evidence_start_date = calculate_start_date(evidence)
evidence_per_day = calculate_amount_per_day(evidence)

((income_end_date.yday - income_start_date.yday + 1) * income_per_day).round(2)
((evidence_end_date.yday - evidence_start_date.yday + 1) * evidence_per_day).round(2)
end

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
def calculate_income_per_day(income)
def calculate_amount_per_day(evidence)
no_of_days = @assistance_year_end.yday
annual_amnt = case income.frequency_kind.downcase
annual_amnt = case evidence.frequency_kind.downcase
when 'weekly'
income.amount * 52
evidence.amount * 52
when 'monthly'
income.amount * 12
evidence.amount * 12
when 'annually', 'once'
income.amount
evidence.amount
when 'biweekly'
income.amount * 26
evidence.amount * 26
when 'quarterly'
income.amount * 4
evidence.amount * 4
when 'semimonthly'
income.amount * 24
evidence.amount * 24
when 'hourly'
income.amount * 40 * 52
evidence.amount * 40 * 52
when 'daily'
income.amount * 5 * 52
evidence.amount * 5 * 52
when 'semiannually'
income.amount * 2
evidence.amount * 2
when '13xperyear'
income.amount * 13
evidence.amount * 13
when '11xperyear'
income.amount * 11
evidence.amount * 11
when '10xperyear'
income.amount * 10
evidence.amount * 10
else
0
end
income_per_day = annual_amnt / no_of_days
BigDecimal(income_per_day.to_s)
amount_per_day = annual_amnt / no_of_days
BigDecimal(amount_per_day.to_s)
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength

Expand All @@ -138,13 +158,13 @@ def calculate_end_date(income)
@assistance_year_end
end

def income_for_current_year?(income)
def amount_for_current_year?(evidence)
@assistance_year_start = Date.new(@application.assistance_year)
@assistance_year_end = @assistance_year_start.end_of_year
income_end = income.end_on || @assistance_year_end
income_date_range = (income.start_on)..income_end
evidence_end = evidence.end_on || @assistance_year_end
evidence_date_range = (evidence.start_on)..evidence_end
year_date_range = @assistance_year_start..@assistance_year_end
date_ranges_overlap?(income_date_range, year_date_range)
date_ranges_overlap?(evidence_date_range, year_date_range)
end

def date_ranges_overlap?(range_a, range_b)
Expand Down
13 changes: 0 additions & 13 deletions app/operations/eligibilities/determine_full_eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ class DetermineFullEligibility
# @option opts [Hash] :medicaid_response_payload
# @return [Dry::Monads::Result]
def call(params)
# { medicaid_application_id: '200000123',
# medicaid_response_payload: medicaid_response_payload }
medicaid_application = yield find_medicaid_application(params)
mm_application_entity = yield get_magi_medicaid_application(medicaid_application)
mm_app_with_medicaid_determination = yield add_medicaid_determination_to_mm_application(mm_application_entity)
mm_app_with_full_determination = yield determine_all_eligibilities_except_medicaid(mm_app_with_medicaid_determination)
result = yield determine_event_name_and_publish_payload(mm_app_with_full_determination)

# { event: event_name, payload: mm_app_with_full_determination }
Success(result)
end

Expand Down Expand Up @@ -109,7 +106,6 @@ def init_ahms(aptc_household_entity)

# rubocop:disable Metrics/CyclomaticComplexity
def determine_event_name_and_publish_payload(mm_application)
# TODO: determine the event name
peds = mm_application.tax_households.flat_map(&:tax_household_members).map(&:product_eligibility_determination)
event_name =
if peds.all?(&:is_ia_eligible)
Expand All @@ -133,12 +129,3 @@ def determine_event_name_and_publish_payload(mm_application)
# rubocop:enable Metrics/CyclomaticComplexity
end
end

# TODO
# 1. Store magi_medicaid_request_payload, mitc_request_payload, mitc_response_payload and magi_medicaid_request_payload
# 2. Send out an event.
# 3. Log all Failure moands for finding failure cases.
# 4. Resource Registry configurations.
# 5. Member Level Determinations.
# 6. Correct MagiMedicaid/MedicaidChip Determinations.

86 changes: 86 additions & 0 deletions spec/operations/eligibilities/determine_full_eligibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,92 @@
end
end

# This test is to make sure the deduction amounts are reduced from annual_tax_household_income
context 'cms me_test_scenarios test_six state ME' do
include_context 'cms ME me_test_scenarios test_six'

before do
@result = subject.call(input_params)
@application = @result.success[:payload]
@new_thhms = @application.tax_households.flat_map(&:tax_household_members)
@thh = @application.tax_households.first
end

it 'should return application' do
expect(@application).to be_a(::AcaEntities::MagiMedicaid::Application)
end

it 'should return tax households with correct effective dates' do
expect(@thh.effective_on.year).to eq(@application.assistance_year)
expect(@thh.effective_on.year).to eq(Date.today.year.next)
end

context 'for tax_household_members' do
let(:kyle_ped) do
@new_thhms.detect do |thhm|
thhm.applicant_reference.person_hbx_id.to_s == '1000590'
end.product_eligibility_determination
end

let(:austin_ped) do
@new_thhms.detect do |thhm|
thhm.applicant_reference.person_hbx_id.to_s == '1000602'
end.product_eligibility_determination
end

it 'should return aqhp, csr result for kyle' do
expect(kyle_ped.is_ia_eligible).to eq(true)
expect(kyle_ped.is_csr_eligible).to eq(true)
expect(kyle_ped.csr).to eq('87')
end

it 'should not return any member determinations for austin' do
expect(austin_ped.to_h.values).not_to include(true)
end
end

context 'for persistence' do
before do
medicaid_app.reload
end

it 'should match with hbx_id' do
expect(medicaid_app.application_identifier).to eq(application_entity.hbx_id)
end

it 'should match with application request payload' do
expect(medicaid_app.application_request_payload).to eq(input_application.to_json)
end

it 'should match with application response payload' do
expect(medicaid_app.application_response_payload).to eq(@application.to_json)
end

it 'should match with medicaid request payload' do
expect(medicaid_app.medicaid_request_payload).to eq(medicaid_request_payload.to_json)
end

it 'should match with medicaid response payload' do
expect(medicaid_app.medicaid_response_payload).to eq(mitc_response.to_json)
end

it 'should match with medicaid response payload' do
expect(medicaid_app.medicaid_response_payload).to eq(mitc_response.to_json)
end

it 'should store annual_tax_household_income' do
expect(medicaid_app.aptc_households.first.annual_tax_household_income).to eq(33_600.0)
end

it 'should return annual_tax_household_income matching with calculated income' do
annual_income = @application.applicants.first.incomes.first.amount.to_f * 12
annual_deduction = @application.applicants.first.deductions.first.amount.to_f * 12
calculated_annual_income = annual_income - annual_deduction
expect(medicaid_app.aptc_households.first.annual_tax_household_income).to eq(calculated_annual_income)
end
end
end

# Parent is getting APTC/CSR as expected. Child is getting UQHP instead of APTC/CSR
# when a person answered 'yes' to Will this person file taxes for 2021? *
# And answered 'no' to Will this person be claimed as a tax dependent for 2021? *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,45 @@
expect(@application.medicaid_request_payload).to eq(medicaid_request_payload.to_json)
end
end

# This test is to make sure the deduction amounts are reduced from total income
context 'cms me_test_scenarios test_six state ME' do
include_context 'cms ME me_test_scenarios test_six'

before do
@result = subject.call(input_application)
@application = @result.success
end

let(:medicaid_request_payload) do
::AcaEntities::MagiMedicaid::Operations::Mitc::GenerateRequestPayload.new.call(application_entity).success
end

it 'should create only one Medicaid::Application object with given hbx_id' do
expect(::Medicaid::Application.where(application_identifier: application_entity.hbx_id).count).to eq(1)
end

it 'should return success' do
expect(@result).to be_success
end

it 'should return Medicaid::Application persistence object' do
expect(@application).to be_a(::Medicaid::Application)
end

it 'should create Medicaid::Application persistence object' do
expect(@application.persisted?).to be_truthy
end

it 'should store application_request_payload' do
expect(@application.application_request_payload).to eq(input_application.to_json)
end

it 'should store medicaid_request_payload' do
expect(@application.medicaid_request_payload).not_to be_nil
expect(@application.medicaid_request_payload).to eq(medicaid_request_payload.to_json)
end
end
end

context 'for failure' do
Expand Down
Loading