Files
baclight/app/models/id_card/setup.rb
T

96 lines
3.9 KiB
Ruby
Raw Normal View History

module IdCard
2026-03-20 10:46:53 -04:00
class Setup < ApplicationRecord
belongs_to :employer, class_name: 'Employer'
belongs_to :employer_logo, optional: true
belongs_to :network_logo, optional: true
belongs_to :provider_section, optional: true
belongs_to :rx_section, optional: true
has_many :plans, dependent: :destroy
2026-03-13 08:47:13 -04:00
has_many :field_exceptions, dependent: :destroy
2026-03-13 08:47:13 -04:00
accepts_nested_attributes_for :plans, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :field_exceptions, allow_destroy: true, reject_if: :all_blank
attribute :queued_card_count, :integer, default: 0
scope :active, -> { where(active: true) }
FORM_COLORS = ['atmosphere', 'verdigris', 'bluemana', 'cobalt']
MODULE_COLOR = 'atmosphere'
# def employer_logo_filename
# self.employer_logo.filename
# end
# def network_logo_filename
# self.network_logo.filename
# end
2026-03-13 08:47:13 -04:00
def build_plan_with_default_benefits(attributes = {})
plan = plans.new(attributes)
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
plan.plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
end
plan
end
2026-03-27 08:04:37 -04:00
def has_field_exceptions?
self.field_exceptions.present?
end
2026-04-15 08:12:47 -04:00
def field_exceptions_card_attributes_by_member_id(member_array = nil)
unless member_array.present?
member_array = self.employer.members.pluck(:pb_entity_key)
end
card_fes = self.field_exceptions.includes(:field_exception_items).in_order_of(:exception_type, IdCard::FieldException::VALID_TYPES)
# fe_by_value = card_fes.in_order_of(:exception_type, IdCard::FieldException::VALID_TYPES).group_by(&:exception_type)
# .transform_values { |fes| fes.map { |fe| [fe.id, fe.exception_values] }.to_h }
# .compact_blank
# field_exception_types = card_fes.pluck(:exception_type).uniq
# if field_exception_types.include?("family_id")
# members = Member.where(pb_entity_key: member_array)
# end
# if field_exception_types.intersect?(["state", "zipcode"])
# member_addresses = Vhcs::PbEntityAddress.where(pb_entity_key: member_array)
# end
card_exceptions_map = {}
card_fes.each do |fe|
if fe.exception_type == "family_id"
matches = Member.where(pb_entity_key: member_array, family_id: fe.exception_values).pluck(:pb_entity_key)
elsif fe.exception_type == "zipcode"
matches = Vhcs::PbEntityAddress.where(pb_entity_key: member_array, zip: fe.exception_values).pluck(:pb_entity_key)
elsif fe.exception_type == "state"
matches = Vhcs::PbEntityAddress.where(pb_entity_key: member_array, state: fe.exception_values).pluck(:pb_entity_key)
end
if matches.present?
card_exceptions_map[fe.id] = fe.to_card_attrs
matches.each do |match|
unless card_exceptions_map[match].present?
card_exceptions_map[match] = fe.id
end
end
end
end
card_exceptions_map
end
def self.permitted_params(params)
2026-03-20 10:46:53 -04:00
params.require(:id_card_setup).permit(
:print_name,
:network_provider,
:card_template,
:rx_group_number,
2026-03-13 08:47:13 -04:00
:employer_logo_id,
:network_logo_id,
:rx_section_id,
:provider_section_id
)
end
end
end