Init dump

This commit is contained in:
Jason Jordan
2025-11-24 08:22:44 -05:00
parent d48bb96791
commit 3fbece7da6
73 changed files with 1747 additions and 121 deletions
+57
View File
@@ -0,0 +1,57 @@
class EmployerSetupForm
include ActiveModel::Model
include ActiveModel::Attributes
FIRST_STEP = "general_information"
attribute :current_step, :string, default: FIRST_STEP
attribute :general_information_data
attribute :plans_data
attribute :network_exceptions_data
def initialize(params = {})
unless self.steps.first == FIRST_STEP
raise StepMisalignmentError, "FIRST_STEP does not match first entry in steps"
end
@general_information_data = EmployerSetupGeneralInformationForm.new(attributes[:general_information_data])
@plans_data = EmployerSetupPlansForm.new(attributes[:plans_data])
@network_exceptions_data = EmployerSetupNetworkExceptionsForm.new(attributes[:network_exceptions_data])
end
def steps
%w[general_information plans network_exceptions summary]
end
def current_step_view
"employer_setup/#{self.current_step}"
end
def next_step
index = steps.index(current_step)
if index && index < steps.length - 1
if steps[index + 1] == 'network_exceptions' && general_information_data.number_of_additional_network_logos == 0
steps[index + 2]
else
steps[index + 1]
end
end
end
def previous_step
index = steps.index(current_step)
steps[index - 1] if index && index > 0
end
def save
if valid?
pl_plan_key = attributes[:general_information_data][:pl_plan_key]
EmployerSetupGeneralInformationForm.new(attributes[:general_information_data]).save
EmployerSetupPlansForm.new(attributes[:plans_data]).save(pl_plan_key)
EmployerSetupNetworkExceptionsForm.new(attributes[:network_exceptions_data]).save(pl_plan_key)
true
else
false
end
end
end
@@ -0,0 +1,62 @@
class EmployerSetupForm
include ActiveModel::Model
include ActiveModel::Attributes
attribute :current_step, :string, default: "general"
attribute :name, :string
attribute :employer_logo
attribute :group_number, :string
attribute :pl_plan_key, :string
attribute :effect_date, :string
attribute :number_of_plans, :integer
attribute :network, :string
attribute :number_of_additional_network_logos, :integer
attribute :plans, array: true, default: -> { [] }
# attribute :benefit_descs, :hash, default: -> { {} }
attribute :network_exceptions, array: true, default: -> { [] }
attr_accessor :benefit_descs
# Define validations based on the current step
with_options on: :general_info do
validates :name, presence: true
validates :employer_logo, presence: true
validates :group_number, presence: true
validates :pl_plan_key, presence: true
validates :effect_date, presence: true
validates :number_of_plans, presence: true
validates :network, presence: true
# validates :number_of_additional_network_logos, presence: true if network = "cigna+"
end
with_options on: :plan_info do
validates :plans, presence: true
# validates :benefit_descs, presence: true
end
with_options on: :network_info do
# validates :network_exceptions, presence: true if number_of_additional_network_logos > 0
end
# def initialize(params = {})
# super(params)
# # Ensure the attribute is a hash after initialization
# @benefit_descs = params[:benefit_descs].to_h if params[:benefit_descs]
# end
def benefit_descs
@benefit_descs ||= {}
end
def save
# Implement logic to save data to models after all steps are complete
# For example, create a User record with the collected data
if valid? && step == total_steps
# User.create!(name: name, email: email, password: password)
true
else
false
end
end
end
@@ -0,0 +1,72 @@
class EmployerSetupGeneralInformationForm
include ActiveModel::Model
include ActiveModel::Attributes
attribute :name, :string
attribute :employer_logo
attribute :group_number, :string
attribute :dental, :boolean
attribute :pl_plan_key, :string
attribute :effect_date, :string
attribute :number_of_plans, :integer
attribute :network, :string
attribute :number_of_additional_network_logos, :integer
validates :name, presence: true
validates :employer_logo, presence: true
validates :group_number, presence: true
validates :pl_plan_key, presence: true
validates :effect_date, presence: true
validates :number_of_plans, presence: true
validates :network, presence: true
# validates :number_of_additional_network_logos, presence: true if network = "cigna+"
# def initialize(params = {})
# super(params)
# # Ensure the attribute is a hash after initialization
# @benefit_descs = params[:benefit_descs].to_h if params[:benefit_descs]
# end
def save
# Implement logic to save data to models after all steps are complete
# For example, create a User record with the collected data
if valid?
hl_plan_code = Vhcs::HlPlanCode.create!(
group_number: group_number,
medical_number: group_number,
dental_number: '',
plan_key: pl_plan_key,
effect_date: effect_date
)
# Replace fairos_info with template like for benefits
fairos_info = Vhcs::HLRXCrosRef.where(pl_plan_key: 52).first
hlrx_cros_ref = Vhcs::HLRXCrosRef.create!(
group_no: group_number,
rx_group_id: group_number,
help_desk: fairos_info.help_desk,
customer_service: fairos_info.customer_service,
web_url: fairos_info.web_url,
pl_plan_key: pl_plan_key
)
web_employer = BrittonWeb::Employers.create!(
pl_plan_key: pl_plan_key,
dental_plan: dental,
single_card_template: 'FairosRxIDCard',
logo: employer_logo.filename
)
BrittonWeb::NetworkLogos.create!(
employer: web_employer,
net_logo: network,
default: true
)
true
else
false
end
end
end
@@ -0,0 +1,46 @@
class EmployerSetupNetworkExceptionsForm
include ActiveModel::Model
include ActiveModel::Attributes
Network_exception = Struct.new(:network_logo, :exceptions)
attribute :network_exceptions, :array_of_items, default: -> { [] }
# validates :network_exceptions, presence: true if number_of_additional_network_logos > 0
# def initialize(params = {})
# super(params)
# # Ensure the attribute is a hash after initialization
# @benefit_descs = params[:benefit_descs].to_h if params[:benefit_descs]
# end
def save(pl_plan_key)
# Implement logic to save data to models after all steps are complete
# For example, create a User record with the collected data
if valid?
employer = BrittonWeb::Employers.find_by(pl_plan_key: pl_plan_key)
network_exceptions.each do |ne|
BrittonWeb::NetworkLogos.create!(
employer: employer,
net_logo: ne.network_logo,
exception_type: ne.type,
exception_value: ne.value,
default: false
)
end
true
else
false
end
end
end
class NetworkException
include ActiveModel::Model
include ActiveModel::Attributes
attribute :network_logo
attribute :exceptions, array: true, default: -> { [] }
end
+49
View File
@@ -0,0 +1,49 @@
class EmployerSetupPlansForm
include ActiveModel::Model
include ActiveModel::Attributes
attribute :plans, array: true, default: -> { [] }
# attribute :benefit_descs, :hash, default: -> { {} }
attr_accessor :id_card_templates
attr_accessor :id_card_template_benefits
attr_accessor :benefit_descs
validates :plans, presence: true
# validates :benefit_descs, presence: true
def initialize(params = {})
super(params)
@id_card_templates = IdCardBenefitsTemplate.where.not(title: "BLANK")
@id_card_template_benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
end
# def benefit_descs
# @benefit_descs ||= {}
# end
def save(pl_plan_key)
# Implement logic to save data to models after all steps are complete
# For example, create a User record with the collected data
if valid?
plans.each do |plan|
plan_id = plan.delete(:plan_id)
plan.each do |key, value|
Vhcs::HLEgglestonCardBenefit.create(
plan_id: plan_id,
benefit_desc: benefit_descs["#{key}"],
benefit: value,
sequence: key,
plan_key: pl_plan_key
)
end
end
true
else
false
end
end
end