Skip to content

Commit

Permalink
plan shopping options (#4255)
Browse files Browse the repository at this point in the history
* 107 plan shopping flow

* missing if

* rubocop

* started fixing cucumbers
  • Loading branch information
kristinmerbach authored and bbodine1 committed Aug 15, 2024
1 parent 489bf5d commit 2eaa7ca
Show file tree
Hide file tree
Showing 25 changed files with 271 additions and 61 deletions.
8 changes: 4 additions & 4 deletions app/assets/javascripts/plan_shopping.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ $(function() {
var max = parseFloat($('input#elected_aptc_value').attr('max'));
var elected_pct = $("input[name='elected_aptc_pct']").val() / 100;
var elected_amount = parseFloat($('#max_aptc').attr('value')).toFixed(2) * parseFloat(elected_pct).toFixed(2);
if (elected_amount <= 1) {
elected_amount = 1.00;
if (elected_amount <= 0) {
elected_amount = 0;
}
if (elected_amount > max) {
elected_amount = max;
Expand All @@ -272,13 +272,13 @@ $(function() {
var elected_aptc = $(this).val();
var max = $('input#elected_aptc_value').attr('max');
var max_aptc = $('input#max_aptc').val();
elected_pct = (elected_aptc/max_aptc).toFixed(2) * 100;
elected_pct = (elected_aptc/max_aptc).toFixed(1) * 100;
if (elected_pct <= 0) {
elected_amount = 0;
}
if (elected_pct > 100) {
elected_pct = 100;
$('#elected_aptc_value').val(max);
$('#elected_aptc_value').val(max_aptc);
}
$("input[name='elected_aptc_pct']").val(elected_pct);
});
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/insured/group_selection_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,19 @@ def create
hbx_enrollment.update_osse_childcare_subsidy
redirect_to thankyou_insured_plan_shopping_path(change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, id: hbx_enrollment.id, plan_id: @adapter.previous_hbx_enrollment.product_id)
elsif @change_plan.present?
redirect_to insured_plan_shopping_path(:id => hbx_enrollment.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, enrollment_kind: @adapter.enrollment_kind)
if EnrollRegistry.feature_enabled?(:choose_shopping_method)
redirect_to choose_shopping_method_insured_plan_shopping_path(:id => hbx_enrollment.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, enrollment_kind: @adapter.enrollment_kind)
else
redirect_to insured_plan_shopping_path(:id => hbx_enrollment.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, enrollment_kind: @adapter.enrollment_kind)
end
else
# FIXME: models should update relationships, not the controller
hbx_enrollment.benefit_group_assignment.update(hbx_enrollment_id: hbx_enrollment.id) if hbx_enrollment.benefit_group_assignment.present?
redirect_to insured_plan_shopping_path(:id => hbx_enrollment.id, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, enrollment_kind: @adapter.enrollment_kind)
if EnrollRegistry.feature_enabled?(:choose_shopping_method)
redirect_to choose_shopping_method_insured_plan_shopping_path(:id => hbx_enrollment.id, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, enrollment_kind: @adapter.enrollment_kind)
else
redirect_to insured_plan_shopping_path(:id => hbx_enrollment.id, market_kind: @market_kind, coverage_kind: @adapter.coverage_kind, enrollment_kind: @adapter.enrollment_kind)
end
end
else
raise "You must select the primary applicant to enroll in the healthcare plan"
Expand Down
54 changes: 36 additions & 18 deletions app/controllers/insured/plan_shoppings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class Insured::PlanShoppingsController < ApplicationController
include L10nHelper

before_action :find_hbx_enrollment
before_action :set_current_person, :only => [:receipt, :thankyou, :waive, :show, :plans, :checkout, :terminate, :plan_selection_callback]
before_action :set_kind_for_market_and_coverage, only: [:thankyou, :show, :plans, :checkout, :receipt, :set_elected_aptc, :plan_selection_callback]
before_action :validate_rating_address, only: [:show]
before_action :check_enrollment_state, only: [:show, :thankyou]
before_action :set_cache_headers, only: [:show, :thankyou]
before_action :enable_bs4_layout, only: [:show, :plans, :receipt, :thankyou] if EnrollRegistry.feature_enabled?(:bs4_consumer_flow)
before_action :set_current_person, :only => [:receipt, :thankyou, :waive, :show, :plans, :checkout, :terminate, :plan_selection_callback, :choose_shopping_method]
before_action :set_kind_for_market_and_coverage, only: [:thankyou, :show, :plans, :checkout, :receipt, :set_elected_aptc, :plan_selection_callback, :choose_shopping_method]
before_action :validate_rating_address, only: [:show, :choose_shopping_method]
before_action :check_enrollment_state, only: [:show, :thankyou, :choose_shopping_method]
before_action :set_cache_headers, only: [:show, :thankyou, :choose_shopping_method]
before_action :enable_bs4_layout, only: [:show, :plans, :receipt, :thankyou, :choose_shopping_method] if EnrollRegistry.feature_enabled?(:bs4_consumer_flow)

layout :resolve_layout

Expand All @@ -37,11 +37,9 @@ def checkout

qle = (plan_selection.hbx_enrollment.enrollment_kind == "special_enrollment")

if !plan_selection.hbx_enrollment.can_select_coverage?(qle: qle)
if plan_selection.hbx_enrollment.errors.present?
flash[:error] = plan_selection.hbx_enrollment.errors.full_messages
end
redirect_back(fallback_location: :back)
unless plan_selection.hbx_enrollment.can_select_coverage?(qle: qle)
flash[:error] = plan_selection.hbx_enrollment.errors.full_messages if plan_selection.hbx_enrollment.errors.present?
redirect_back(fallback_location: :back)
return
end

Expand Down Expand Up @@ -97,7 +95,7 @@ def thankyou
get_aptc_info_from_session(@enrollment)
end

# TODO Fix this stub
# TODO: Fix this stub
if @enrollment.is_shop?
@member_group = HbxEnrollmentSponsoredCostCalculator.new(@enrollment).groups_for_products([@plan]).first
@enrollment.verify_and_reset_osse_subsidy_amount(@member_group)
Expand All @@ -111,7 +109,7 @@ def thankyou

@family = @person.primary_family

#FIXME need to implement can_complete_shopping? for individual
#FIXME: need to implement can_complete_shopping? for individual
@enrollable = @market_kind == 'individual' ? true : @enrollment.can_complete_shopping?(qle: @enrollment.is_special_enrollment?)
@waivable = @enrollment.can_complete_shopping?
@change_plan =
Expand Down Expand Up @@ -293,6 +291,21 @@ def plans
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity

def choose_shopping_method
authorize @hbx_enrollment, :show?

set_consumer_bookmark_url(family_account_path)
set_admin_bookmark_url(family_account_path)

hbx_enrollment_id = params.require(:id)
@change_plan = params[:change_plan].present? ? params[:change_plan] : ''
@enrollment_kind = params[:enrollment_kind].present? ? params[:enrollment_kind] : ''

set_plans_by(hbx_enrollment_id: hbx_enrollment_id)
generate_eligibility_data
generate_checkbook_service
end

private


Expand Down Expand Up @@ -363,7 +376,8 @@ def show_ivl(hbx_enrollment_id)
@max_deductible = thousand_ceil(@plans.map(&:deductible).map {|d| d.is_a?(String) ? d.gsub(/[$,]/, '').to_i : 0}.max)
end

def show_shop(hbx_enrollment_id)
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
def show_shop(_hbx_enrollment_id)
set_employee_bookmark_url(family_account_path) if params[:market_kind] == 'shop' || params[:market_kind] == 'fehb'
@hbx_enrollment.update_osse_childcare_subsidy
sponsored_cost_calculator = HbxEnrollmentSponsoredCostCalculator.new(@hbx_enrollment)
Expand Down Expand Up @@ -400,6 +414,7 @@ def show_shop(hbx_enrollment_id)
render "show"
::Caches::CustomCache.release(::BenefitSponsors::Organizations::Organization, :plan_shopping)
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity

def fix_member_dates(enrollment, plan)
return if enrollment.parent_enrollment.present? && plan.id == enrollment.parent_enrollment.product_id
Expand Down Expand Up @@ -443,7 +458,7 @@ def generate_eligibility_data
end

def generate_checkbook_service
plan_comparision_obj = ::Services::CheckbookServices::PlanComparision.new(@hbx_enrollment)
plan_comparision_obj = ::Services::CheckbookServices::PlanComparision.new(@hbx_enrollment, @plans)
plan_comparision_obj.elected_aptc = session[:elected_aptc]
@dc_individual_checkbook_url = plan_comparision_obj.generate_url
end
Expand Down Expand Up @@ -514,7 +529,10 @@ def collect_shopping_filters

# no dental as of now
def sort_member_groups(products)
products.select { |prod| prod.group_enrollment.product.id.to_s == @enrolled_hbx_enrollment_plan_ids.first.to_s } + products.select { |prod| prod.group_enrollment.product.id.to_s != @enrolled_hbx_enrollment_plan_ids.first.to_s }.sort_by { |mg| (mg.group_enrollment.product_cost_total - mg.group_enrollment.sponsor_contribution_total) }
unsorted = products.select { |prod| prod.group_enrollment.product.id.to_s == @enrolled_hbx_enrollment_plan_ids.first.to_s } + products.reject do |prod|
prod.group_enrollment.product.id.to_s == @enrolled_hbx_enrollment_plan_ids.first.to_s
end
unsorted.sort_by { |mg| (mg.group_enrollment.product_cost_total - mg.group_enrollment.sponsor_contribution_total) }
end

def sort_by_standard_plans(plans)
Expand Down Expand Up @@ -621,9 +639,9 @@ def build_same_plan_premiums
if @hbx_enrollment.is_shop?
ref_plan = (@hbx_enrollment.coverage_kind == "health" ? @benefit_group.reference_plan : @benefit_group.dental_reference_plan)

@enrolled_plans = enrolled_plans.collect{|plan|
@enrolled_plans = enrolled_plans.collect do |plan|
@benefit_group.decorated_plan(plan, same_plan_enrollment, ref_plan)
}
end
else
@enrolled_plans = same_plan_enrollment.calculate_costs_for_plans(enrolled_plans)
end
Expand Down
43 changes: 30 additions & 13 deletions app/models/services/checkbook_services/plan_comparision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class PlanComparision
CONGRESS_URL = Rails.application.config.checkbook_services_congress_url
IVL_PATH = Rails.application.config.checkbook_services_ivl_path
SHOP_PATH = Rails.application.config.checkbook_services_shop_path
REMOTE_ACCESS_KEY = Rails.application.config.checkbook_services_remote_access_key
CS_REFERENCE_ID = Rails.application.config.checkbook_services_reference_id

def initialize(hbx_enrollment, is_congress=false)
def initialize(hbx_enrollment, plans = nil, is_congress = nil)
is_congress ||= false
@plans = plans
@hbx_enrollment = hbx_enrollment
if @hbx_enrollment.kind.downcase == "individual"
@person = @hbx_enrollment.consumer_role.person
Expand All @@ -26,7 +30,6 @@ def initialize(hbx_enrollment, is_congress=false)
def generate_url
#return @url if is_congress
return "http://checkbook_url" if Rails.env.test?

begin
construct_body =
if is_congress
Expand All @@ -35,24 +38,22 @@ def generate_url
@hbx_enrollment.kind.downcase == "individual" ? construct_body_ivl : construct_body_shop
end

@result = HTTParty.post(@url,
:body => construct_body.to_json,
:headers => { 'Content-Type' => 'application/json' } )
@result = HTTParty.post(@url, :body => construct_body.to_json, :headers => { 'Content-Type' => 'application/json' })
uri =
if @result.parsed_response.is_a?(String)
JSON.parse(@result.parsed_response)["URL"]
else
@result.parsed_response["URL"] || @result.parsed_response["url"]
end
if uri.present?
return uri
uri
else
raise "Unable to generate url"
end
rescue Exception => e
Rails.logger.error { "Unable to generate url for hbx_enrollment_id #{@hbx_enrollment.id} due to #{e.backtrace}" }
# redirects to plan shopping show page if url generation is failed.
return "/insured/plan_shoppings/#{@hbx_enrollment.id}?market_kind=#{@hbx_enrollment.kind}&coverage_kind=#{@hbx_enrollment.coverage_kind}"
"/insured/plan_shoppings/#{@hbx_enrollment.id}?market_kind=#{@hbx_enrollment.kind}&coverage_kind=#{@hbx_enrollment.coverage_kind}"
end
end

Expand Down Expand Up @@ -93,7 +94,7 @@ def construct_body_shop
"employer":
{
"state": 11,
"county": 001
"county": 0o01
},
"family": build_family,
"contribution": employer_contributions,
Expand All @@ -106,18 +107,26 @@ def construct_body_shop

def construct_body_ivl
address = @person&.rating_address

{
ivl_body = {
"county": address&.county,
"zipcode": address&.zip,
"remote_access_key": Rails.application.config.checkbook_services_remote_access_key,
"reference_id": Rails.application.config.checkbook_services_reference_id,
"remote_access_key": REMOTE_ACCESS_KEY,
"reference_id": CS_REFERENCE_ID,
"enrollment_year": enrollment_year,
"family": consumer_build_family,
"aptc": elected_aptc.to_s,
"csr": csr_value,
"enrollmentId": @hbx_enrollment.id.to_s # Host Name will be static as Checkbook suports static URL's and hostname should be changed before going to production.
}
ivl_body.merge!(extra_ivl_body) if EnrollRegistry.feature_enabled?(:send_extra_fields_to_checkbook)
end

def extra_ivl_body
current_plan = build_current_plan(@hbx_enrollment)
{
"coverageStartDate": @hbx_enrollment.effective_on.strftime("%m-%d-%Y"),
"currentPlan": current_plan
}
end

def construct_body_congress
Expand Down Expand Up @@ -219,13 +228,21 @@ def build_congress_employee_age
family
end

def build_current_plan(enrollment)
return "" unless @plans
available_plans = @plans.map(&:hios_id)
enrolled_plan = enrollment.family.current_enrolled_or_termed_products_by_subscriber(enrollment)&.map(&:hios_id)&.first
return "" unless available_plans&.include?(enrolled_plan)
enrolled_plan
end

def build_family
family = []
# family = [{'dob': @census_employee.dob.strftime("%Y-%m-%d") ,'relationship': 'self'}]
# @census_employee.census_dependents.each do |dependent|
@hbx_enrollment.hbx_enrollment_members.each do |dependent|
next if dependent.primary_relationship == "nephew_or_niece"
family << {'dob': dependent.family_member.person.dob.strftime("%Y-%m-%d") ,'relationship': dependent.primary_relationship}
family << {'dob': dependent.family_member.person.dob.strftime("%Y-%m-%d"),'relationship': dependent.primary_relationship}
end
family
end
Expand Down
11 changes: 7 additions & 4 deletions app/views/insured/plan_shoppings/_plan_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
<%= plan.standard_plan_label.titleize %>
</span>
<% end %>
<% current_plans = @hbx_enrollment.family.current_enrolled_or_termed_coverages(@hbx_enrollment, true).collect(&:product_id) %>
<% if current_plans.present? && current_plans.include?(plan.id) %>
<% if @person.primary_family.enrolled_hbx_enrollments.map(&:product).map(&:id).include?(plan.id) %>
<span class="badge badge-pill badge-lg badge-current-plan ml-2 d-flex align-items-center">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<title>Star</title>
Expand Down Expand Up @@ -89,7 +88,7 @@
<div class="price-wrapper text-right">
<strong class="text-secondary"><%= l10n("premium") %></strong>
<% if session[:elected_aptc] && session[:elected_aptc] != 0 %>
<% premium = min_premium_with_aptc(plan.total_employee_cost, plan.total_ehb_premium, plan.total_childcare_subsidy_amount, plan.can_use_aptc?) %>
<% premium = shopping_group_premium(plan.total_employee_cost, plan.total_ehb_premium, plan.total_childcare_subsidy_amount, plan.can_use_aptc?) %>
<p class="bold beta m-0"><%= number_to_currency(premium) %></p>
<% else %>
<p class="bold beta m-0"><%= number_to_currency(plan.total_employee_cost - plan.total_childcare_subsidy_amount) %></p>
Expand Down Expand Up @@ -136,6 +135,9 @@
<%= link_to l10n("see_details"), summary_products_plans_path({plan_id: plan.id, :standard_component_id => plan.hios_id, hbx_enrollment_id: @hbx_enrollment.id, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind, active_year: plan.try(:active_year), bs4: @bs4}), {:class => "primary-text ml-4", :remote => true} %>
<% end %>
</div>
<% if details_page %>
<%= render partial: "shared/plan_shoppings/select_plan_button", locals: { plan: plan } %>
<% else %>
<% if (@tax_household || @aptc_grants) && params[:market_kind]=='individual' && params[:coverage_kind] == 'health' %>
<% if @csr_available && plan.metal_level != "silver" %>
<%= link_to l10n("select_plan"), "javascript:void(0)", class: 'btn btn-default btn-right', data: {'toggle': 'modal', 'target': "#csrEligibleReminder-#{plan.id}"} %>
Expand All @@ -147,6 +149,7 @@
<% else %>
<%= link_to(l10n("select_plan"), "javascript:void(0)", {class: 'btn btn-default btn-right plan-select select', data: {url: thankyou_insured_plan_shopping_path(@hbx_enrollment, plan_id: plan.id, change_plan: @change_plan, market_kind: @market_kind, coverage_kind: @coverage_kind, enrollment_kind: @enrollment_kind)}}) %>
<% end %>
<% end %>
</div>

</div>
Expand All @@ -172,7 +175,7 @@
</div>
<div class="row">
<% if @enrolled_hbx_enrollment_plan_ids.include?(plan.id) %>
<h5 class="col-md-12 current bg-title"><i class="fa fa-star fa-lg enrolling"></i><%= l10n("your_current_plan", year: plan.try(:active_year)).to_s.upcase %></h5>
<h5 class="col-md-12 current bg-title"><i class="fa fa-star fa-lg enrolling"></i><%= l10n("your_current_plan", year: plan.try(:active_year)).to_s.upcase %></h5>
<% end %>
</div>
<div class="row">
Expand Down
Loading

0 comments on commit 2eaa7ca

Please sign in to comment.