automate employer setup import from word and manual entry working
This commit is contained in:
@@ -5,19 +5,33 @@ class EmployerSetupForm
|
||||
FIRST_STEP = "general_information"
|
||||
|
||||
attribute :current_step, :string, default: FIRST_STEP
|
||||
attribute :general_information_data
|
||||
attribute :plans_data
|
||||
attribute :network_exceptions_data
|
||||
attribute :pl_plan_key, :string
|
||||
|
||||
def initialize(params = {})
|
||||
# if params.present?
|
||||
# params = permitted_params(params)
|
||||
# end
|
||||
super(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])
|
||||
# @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 self.form_session_init
|
||||
# {
|
||||
# general_information_data: {},
|
||||
# plans_data: {},
|
||||
# network_exceptions_data: {}
|
||||
# }
|
||||
# end
|
||||
|
||||
# def steps
|
||||
# %w[general_information plans network_exceptions summary]
|
||||
# end
|
||||
|
||||
def steps
|
||||
%w[general_information plans network_exceptions summary]
|
||||
end
|
||||
@@ -29,11 +43,7 @@ class EmployerSetupForm
|
||||
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
|
||||
steps[index + 1]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,16 +52,29 @@ class EmployerSetupForm
|
||||
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
|
||||
def permitted_params(params)
|
||||
params.require(:employer_setup_data).permit(
|
||||
:pl_plan_key,
|
||||
:current_step
|
||||
)
|
||||
end
|
||||
|
||||
def self.permitted_params
|
||||
[
|
||||
:pl_plan_key,
|
||||
:current_step
|
||||
]
|
||||
end
|
||||
|
||||
# def save
|
||||
# if valid?
|
||||
# EmployerSetupGeneralInformationForm.new(attributes[:general_information_data]).save
|
||||
# EmployerSetupPlansForm.new(attributes[:plans_data]).save
|
||||
# EmployerSetupNetworkExceptionsForm.new(attributes[:network_exceptions_data]).save
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
@@ -5,27 +5,48 @@ class EmployerSetupGeneralInformationForm
|
||||
attribute :name, :string
|
||||
attribute :employer_logo
|
||||
attribute :group_number, :string
|
||||
attribute :dental, :boolean
|
||||
attribute :dental, :boolean, default: false
|
||||
attribute :pl_plan_key, :string
|
||||
attribute :effect_date, :string
|
||||
attribute :number_of_plans, :integer
|
||||
# attribute :number_of_plans, :integer
|
||||
attribute :network, :string
|
||||
attribute :number_of_additional_network_logos, :integer
|
||||
# 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 :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 initialize(attributes = {})
|
||||
# if attributes
|
||||
# permitted_attributes = form_strong_params(attributes)
|
||||
# super(permitted_attributes)
|
||||
# end
|
||||
|
||||
def initialize(params = {})
|
||||
if params.present?
|
||||
params = permitted_params(params)
|
||||
end
|
||||
super(params)
|
||||
end
|
||||
|
||||
def permitted_params(params)
|
||||
params.require(:employer_setup_general_information_form).permit(
|
||||
:name,
|
||||
:employer_logo,
|
||||
:group_number,
|
||||
:dental,
|
||||
:pl_plan_key,
|
||||
:effect_date,
|
||||
:number_of_plans,
|
||||
:network,
|
||||
:number_of_additional_network_logos
|
||||
)
|
||||
end
|
||||
|
||||
def save
|
||||
# Implement logic to save data to models after all steps are complete
|
||||
@@ -40,8 +61,8 @@ class EmployerSetupGeneralInformationForm
|
||||
)
|
||||
|
||||
# Replace fairos_info with template like for benefits
|
||||
fairos_info = Vhcs::HLRXCrosRef.where(pl_plan_key: 52).first
|
||||
hlrx_cros_ref = Vhcs::HLRXCrosRef.create!(
|
||||
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,
|
||||
@@ -51,15 +72,26 @@ class EmployerSetupGeneralInformationForm
|
||||
)
|
||||
|
||||
web_employer = BrittonWeb::Employers.create!(
|
||||
name: name,
|
||||
pl_plan_key: pl_plan_key,
|
||||
dental_plan: dental,
|
||||
single_card_template: 'FairosRxIDCard',
|
||||
logo: employer_logo.filename
|
||||
logo: employer_logo.original_filename
|
||||
)
|
||||
|
||||
default_network_logo =
|
||||
case
|
||||
when network.include?("cig")
|
||||
"CignaLogo.png"
|
||||
when network.include?("med")
|
||||
"Logo_MC_PMS.png"
|
||||
else
|
||||
"CignaLogo.png"
|
||||
end
|
||||
|
||||
BrittonWeb::NetworkLogos.create!(
|
||||
employer: web_employer,
|
||||
net_logo: network,
|
||||
employer_id: web_employer.id,
|
||||
net_logo: default_network_logo,
|
||||
default: true
|
||||
)
|
||||
|
||||
|
||||
@@ -4,29 +4,82 @@ class EmployerSetupNetworkExceptionsForm
|
||||
|
||||
Network_exception = Struct.new(:network_logo, :exceptions)
|
||||
attribute :network_exceptions, :array_of_items, default: -> { [] }
|
||||
attribute :pl_plan_key, :string
|
||||
attribute :number_of_additional_network_logos, :integer
|
||||
|
||||
# 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 initialize(params = {})
|
||||
if params.present? && params[:employer_setup_network_exceptions_form].is_a?(ActionController::Parameters)
|
||||
params = permitted_params(params)
|
||||
end
|
||||
super(params)
|
||||
end
|
||||
|
||||
def save(pl_plan_key)
|
||||
def permitted_params(params)
|
||||
params.require(:employer_setup_network_exceptions_form).permit(
|
||||
network_exceptions: [
|
||||
:network_logo,
|
||||
exceptions: [
|
||||
:type,
|
||||
:value
|
||||
]
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
# def self.permitted_params
|
||||
# [
|
||||
# network_exceptions: [
|
||||
# :network_logo,
|
||||
# exceptions: [
|
||||
# :type,
|
||||
# :value
|
||||
# ]
|
||||
# ]
|
||||
# ]
|
||||
# end
|
||||
|
||||
def pull_from_employer_setup_form(attributes = {})
|
||||
if attributes['pl_plan_key']
|
||||
self.pl_plan_key = attributes['pl_plan_key']
|
||||
end
|
||||
if attributes['number_of_additional_network_logos']
|
||||
self.number_of_additional_network_logos = attributes['number_of_additional_network_logos']
|
||||
end
|
||||
end
|
||||
|
||||
def process_for_save(network_exceptions)
|
||||
ne_array = []
|
||||
network_exceptions.first.each do |ne|
|
||||
processed_ne = ne.last
|
||||
exceptions_array = []
|
||||
processed_ne['exceptions'].each do |e|
|
||||
exceptions_array.push(e.last)
|
||||
end
|
||||
processed_ne['exceptions'] = exceptions_array
|
||||
ne_array.push(processed_ne)
|
||||
end
|
||||
ne_array
|
||||
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?
|
||||
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
|
||||
)
|
||||
network_exceptions_data = process_for_save(network_exceptions)
|
||||
network_exceptions_data.each do |ne|
|
||||
ne['exceptions'].each do |ex|
|
||||
BrittonWeb::NetworkLogos.create!(
|
||||
employer_id: employer.id,
|
||||
net_logo: ne['network_logo'].original_filename,
|
||||
exception_type: ex['type'].downcase,
|
||||
exception_value: ex['value'],
|
||||
default: false
|
||||
)
|
||||
end
|
||||
end
|
||||
true
|
||||
else
|
||||
|
||||
@@ -2,40 +2,111 @@ class EmployerSetupPlansForm
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Attributes
|
||||
|
||||
attribute :plans, array: true, default: -> { [] }
|
||||
# attribute :benefit_descs, :hash, default: -> { {} }
|
||||
PLAN_COLORS = ['atmosphere', 'copper', 'bluemana', 'bronze', 'cobalt', 'verdigris']
|
||||
|
||||
attr_accessor :id_card_templates
|
||||
attr_accessor :id_card_template_benefits
|
||||
attr_accessor :benefit_descs
|
||||
# attribute :plans, array: true, default: []
|
||||
attribute :plans, array: true, default: -> { [new_plan] }
|
||||
attribute :pl_plan_key, :string
|
||||
attribute :number_of_plans, :integer
|
||||
attribute :benefit_descs, hash: true, default: -> { new_plan }
|
||||
|
||||
attr_accessor :plan_templates
|
||||
attr_accessor :benefits_template
|
||||
|
||||
validates :plans, presence: true
|
||||
# validates :benefit_descs, presence: true
|
||||
|
||||
validates :benefit_descs, presence: true
|
||||
|
||||
def initialize(params = {})
|
||||
if params.present?
|
||||
params = permitted_params(params)
|
||||
end
|
||||
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)
|
||||
|
||||
@plan_templates = IdCardBenefitsTemplate.where.not(title: "BLANK")
|
||||
@benefits_template = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
|
||||
|
||||
# if attributes.present? && attributes[:plans].present?
|
||||
# self.plans = Array(attributes[:plans])
|
||||
# else
|
||||
# self.plans = [new_plan]
|
||||
# end
|
||||
end
|
||||
|
||||
# def benefit_descs
|
||||
# @benefit_descs ||= {}
|
||||
# def plans_attributes=(attributes)
|
||||
# self.plans = attributes.values.map { |plan_attrs| Plan.new(plan_attrs) }
|
||||
# end
|
||||
|
||||
def save(pl_plan_key)
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
# The core method to initialize the array with a single blank item.
|
||||
def ensure_one_plan_exists
|
||||
if plans.empty?
|
||||
self.plans << PlanForm.new
|
||||
self.plans << PlanForm.new
|
||||
end
|
||||
end
|
||||
|
||||
def bulild_descs_plan
|
||||
self.benefit_descs = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
|
||||
end
|
||||
|
||||
def self.new_plan
|
||||
plan = {}
|
||||
self.permited_plans_keys.each do |key|
|
||||
plan[key] = ""
|
||||
end
|
||||
plan
|
||||
end
|
||||
|
||||
def permitted_params(params)
|
||||
params.require(:employer_setup_plans_form).permit(
|
||||
:pl_plan_key,
|
||||
plans: self.permited_plans_keys,
|
||||
benefit_descs: self.permited_plans_keys
|
||||
)
|
||||
end
|
||||
|
||||
def pull_from_employer_setup_form(attributes = {})
|
||||
if attributes['pl_plan_key']
|
||||
self.pl_plan_key = attributes['pl_plan_key']
|
||||
end
|
||||
if attributes['number_of_plans']
|
||||
self.number_of_plans = attributes['number_of_plans']
|
||||
end
|
||||
end
|
||||
|
||||
# def form_strong_params(attributes)
|
||||
# attributes.require(:employer_setup_plans_form).permit(
|
||||
# plans: permited_plans_keys,
|
||||
# benefit_descs: benefit_sequence_keys
|
||||
# )
|
||||
# end
|
||||
|
||||
def self.permited_plans_keys
|
||||
(1..14).map { |i| "benefit_#{i}".to_sym }.push(:plan_id)
|
||||
end
|
||||
|
||||
def permited_plans_keys
|
||||
(1..14).map { |i| "benefit_#{i}".to_sym }.push(:plan_id)
|
||||
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?
|
||||
plans.each do |plan|
|
||||
plan_id = plan.delete(:plan_id)
|
||||
plan.each do |key, value|
|
||||
Vhcs::HLEgglestonCardBenefit.create(
|
||||
plan_info = plan.last
|
||||
plan_id = plan_info.delete(:plan_id).to_i
|
||||
plan_info.each do |key, value|
|
||||
sequence = key.delete_prefix("benefit_").to_i
|
||||
Vhcs::HlEgglestonCardBenefit.create(
|
||||
plan_id: plan_id,
|
||||
benefit_desc: benefit_descs["#{key}"],
|
||||
benefit: value,
|
||||
sequence: key,
|
||||
sequence: sequence,
|
||||
plan_key: pl_plan_key
|
||||
)
|
||||
end
|
||||
@@ -46,4 +117,32 @@ class EmployerSetupPlansForm
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class PlanForm
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Attributes
|
||||
|
||||
attribute :plan_id, :string
|
||||
|
||||
def initialize(attributes = {})
|
||||
self.generate_attributes(14, "benefit_")
|
||||
super(attributes)
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
def generate_attributes(count, prefix)
|
||||
count.times do |i|
|
||||
# attr_accessor :"#{prefix}#{i + 1}"
|
||||
self.class.attribute "#{prefix}#{i + 1}".to_sym, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# dynamic_attribute_names.each do |attr_name|
|
||||
# # Define each attribute as a String type (you can customize the type)
|
||||
# self.class.attribute attr_name.to_sym, :string
|
||||
# end
|
||||
Reference in New Issue
Block a user