Skip to content

Commit

Permalink
Optimization for Employer Page Load (#2491)
Browse files Browse the repository at this point in the history
* refactors progressbar covered count

* quick view file refactoring

* adds specs

* fixes spec failures
  • Loading branch information
utkarsh7989 authored Dec 11, 2023
1 parent 76b8dd0 commit d1f8c88
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 11 deletions.
15 changes: 15 additions & 0 deletions app/models/benefit_group_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ def active_enrollments
end
end

def covered_families_with_benefit_assignemnt
Family.where(
{
"households.hbx_enrollments" => {
:"$elemMatch" => {
:"$and" => [
{ :employee_role_id => employee_role_id },
{ :benefit_group_assignment_id => BSON::ObjectId.from_string(id) }
]
}
}
}
)
end

def hbx_enrollment
return @hbx_enrollment if defined? @hbx_enrollment

Expand Down
5 changes: 5 additions & 0 deletions app/models/census_employee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,11 @@ def is_enrolled_or_renewed?
bga.active_enrollments.present?
end

def is_employee_covered?
bga = renewal_benefit_group_assignment || active_benefit_group_assignment
bga.covered_families_with_benefit_assignemnt.present?
end

# Enrollments with current active and renewal benefit applications
def active_benefit_group_enrollments(coverage_date = TimeKeeper.date_of_record)
return nil if employee_role.blank?
Expand Down
22 changes: 12 additions & 10 deletions app/views/ui-components/v1/cards/_employee_enrollments.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
i.fa.fa-question-circle.pl-1 data-toggle="tooltip" title="At least #{(Settings.aca.shop_market.employee_participation_ratio_minimum * 100).to_i} percent of your eligible employees must enroll or waive coverage during the open enrollment period in order to establish your Health Benefits Program. One of your enrollees must also be a non-owner"
.panel-body
= render 'employers/employer_profiles/my_account/enrollment_progress_bar'
- total_enrolled_count = @current_plan_year.total_enrolled_count
- eligible_to_enroll_count = @current_plan_year.eligible_to_enroll_count
.information
strong = @current_plan_year.total_enrolled_count
| out of
strong = @current_plan_year.eligible_to_enroll_count
strong = total_enrolled_count
| out of
strong = eligible_to_enroll_count
| have enrolled or waived coverage
- if @current_plan_year.employee_participation_ratio_minimum != 0
- if TimeKeeper.date_of_record.to_date <= @current_plan_year.open_enrollment_end_on.to_date
br
strong = @current_plan_year.additional_required_participants_count.to_i
| or more needed by
= @current_plan_year.open_enrollment_end_on.to_date.to_formatted_s :long_ordinal
| or more needed by
= @current_plan_year.open_enrollment_end_on.to_date.to_formatted_s :long_ordinal
| to meet minimum requirement
- if @current_plan_year.total_enrolled_count != @current_plan_year.eligible_to_enroll_count
- if total_enrolled_count != eligible_to_enroll_count
br
br
.alert.alert-warning role="alert"
i.fa.fa-flag
span
strong Important:
| You have until
= @current_plan_year.open_enrollment_end_on.to_date.to_formatted_s :long_ordinal
| for your employees to sign up, or waive coverage.
strong Important:
| You have until
= @current_plan_year.open_enrollment_end_on.to_date.to_formatted_s :long_ordinal
| for your employees to sign up, or waive coverage.
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def covered
def progressbar_covered_count
return @progressbar_covered_count if defined? @progressbar_covered_count

@progressbar_covered_count = active_census_employees.select(&:is_enrolled_or_renewed?).count
@progressbar_covered_count = active_census_employees.select(&:is_employee_covered?).count
end

def progressbar_enrolled_non_business_owner_members
Expand Down
24 changes: 24 additions & 0 deletions spec/models/benefit_group_assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,30 @@
it_behaves_like "active enrollments", "coverage_selected", "", [], false, false
end

describe '#covered_families_with_benefit_assignemnt', dbclean: :after_each do

let!(:household) { FactoryGirl.create(:household, family: family)}
let(:family) { FactoryGirl.create(:family, :with_primary_family_member)}
let(:hbx_enrollment) { FactoryGirl.create(:hbx_enrollment, household: household, aasm_state: 'coverage_selected', benefit_group_assignment_id: benefit_group_assignment.id, employee_role_id: employee_role.id) }
let!(:benefit_group_assignment) { FactoryGirl.create(:benefit_group_assignment, census_employee: census_employee)}
let!(:employee_role) do
ee = FactoryGirl.create(:employee_role, person: family.primary_person, employer_profile: employer_profile, census_employee: census_employee)
census_employee.update_attributes!(employee_role_id: ee.id)
ee
end

before do
family.active_household.hbx_enrollments = [hbx_enrollment]
family.save!
allow(census_employee).to receive(:active_benefit_group_assignment).and_return(benefit_group_assignment)
end

it "should return the covered families" do
expect(census_employee.active_benefit_group_assignment.covered_families_with_benefit_assignemnt.count).to eq 1
expect(census_employee.active_benefit_group_assignment.covered_families_with_benefit_assignemnt.first).to eq family
end
end

describe '.make_active' do
let!(:census_employee) do
FactoryGirl.create(
Expand Down
28 changes: 28 additions & 0 deletions spec/models/census_employee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,34 @@
end
end

context ".is_employee_covered?" do
let(:benefit_group_assignment) {build(:benefit_sponsors_benefit_group_assignment, benefit_group: benefit_group)}
let(:census_employee) do
FactoryGirl.create(
:benefit_sponsors_census_employee,
employer_profile: employer_profile,
benefit_sponsorship: organization.active_benefit_sponsorship,
benefit_group_assignments: [benefit_group_assignment]
)
end

let(:enrolled_family_double) { double('EnrolledFamily', id: '1') }

before do
allow(census_employee).to receive(:employee_role).and_return double("EmployeeRole")
allow(census_employee).to receive(:family).and_return enrolled_family_double
end

it "returns false when no covered employee present" do
expect(census_employee.is_employee_covered?).to be_falsey
end

it "returns true with covered employee" do
allow(benefit_group_assignment).to receive(:covered_families_with_benefit_assignemnt).and_return([enrolled_family_double])
expect(census_employee.is_employee_covered?).to be_truthy
end
end

context "expected to enroll" do

let!(:valid_waived_employee) {FactoryGirl.create :benefit_sponsors_census_employee,
Expand Down

0 comments on commit d1f8c88

Please sign in to comment.