2026-03-06 10:56:20 -05:00
|
|
|
module IdCard
|
|
|
|
|
class Plan < ApplicationRecord
|
2026-03-20 10:46:53 -04:00
|
|
|
belongs_to :setup, optional: true
|
2026-03-06 10:56:20 -05:00
|
|
|
has_many :plan_benefits, dependent: :destroy
|
|
|
|
|
accepts_nested_attributes_for :plan_benefits, allow_destroy: true, reject_if: :all_blank
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-13 08:47:13 -04:00
|
|
|
scope :templates, -> { where(template: true) }
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-13 08:47:13 -04:00
|
|
|
BENEFIT_FIELDS = ["Primary Visit",
|
|
|
|
|
"Specialist Visit",
|
|
|
|
|
"Urgent Care",
|
|
|
|
|
"INN-Ind Ded",
|
|
|
|
|
"INN-Family Ded",
|
|
|
|
|
"OON-Ind Ded",
|
|
|
|
|
"OON-Family Ded",
|
|
|
|
|
"Co-Insurance",
|
|
|
|
|
"INN-Ind OOP",
|
|
|
|
|
"INN-Family OOP",
|
|
|
|
|
"OON-Ind OOP",
|
|
|
|
|
"OON-Family OOP",
|
|
|
|
|
"Emergency Room",
|
|
|
|
|
"Preventive Care"].freeze
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-13 08:47:13 -04:00
|
|
|
after_initialize :build_plan_benefits, if: :new_record?
|
|
|
|
|
|
|
|
|
|
def build_plan_benefits
|
|
|
|
|
BENEFIT_FIELDS.each_with_index do |bene, i|
|
|
|
|
|
self.plan_benefits.build(benefit_desc: bene, sequence: (i + 1))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_template
|
|
|
|
|
formatted_title = title
|
|
|
|
|
if pl_plan_key.present?
|
|
|
|
|
employer_name = Employer.find_by(pl_plan_key: pl_plan_key).pluck(:name)
|
|
|
|
|
formatted_title.concat( " (#{employer_name})" )
|
|
|
|
|
end
|
|
|
|
|
{ id: id, title: formatted_title }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
|
|
# def templates
|
|
|
|
|
# active_templates.map(&:format_template)
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
def permitted_params(params)
|
2026-03-20 10:46:53 -04:00
|
|
|
params.require(:id_card_setup).permit(
|
2026-03-13 08:47:13 -04:00
|
|
|
plans_attributes: [
|
2026-03-19 00:42:27 -04:00
|
|
|
:id,
|
2026-03-13 08:47:13 -04:00
|
|
|
:title,
|
|
|
|
|
:pb_product_key,
|
|
|
|
|
:pl_plan_key,
|
2026-03-06 10:56:20 -05:00
|
|
|
:_destroy,
|
2026-03-13 08:47:13 -04:00
|
|
|
plan_benefits_attributes: [
|
|
|
|
|
:id,
|
|
|
|
|
:benefit_desc,
|
|
|
|
|
:benefit,
|
|
|
|
|
:sequence,
|
|
|
|
|
:_destroy,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
)
|
2026-03-06 10:56:20 -05:00
|
|
|
end
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-13 08:47:13 -04:00
|
|
|
end
|
|
|
|
|
|
2026-03-06 10:56:20 -05:00
|
|
|
private
|
2026-03-05 11:30:24 -05:00
|
|
|
|
2026-03-06 10:56:20 -05:00
|
|
|
def build_and_create_default_benefits
|
|
|
|
|
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
|
|
|
|
|
benefits.each do |ben|
|
|
|
|
|
id_card_plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
|
|
|
|
|
end
|
2026-03-05 11:30:24 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|