Files
baclight/app/services/id_card_printer/employer_data_formatter.rb
T
2026-03-19 00:42:27 -04:00

169 lines
7.1 KiB
Ruby

module IdCardPrinter
class EmployerDataFormatter
def initialize(employer, member_keys = nil)
@employer = employer
@card_config = @employer.id_card_configuration
if member_keys
@members = @employer.members.where(pb_entity_key: member_keys).order(:name)
else
@members = @employer.members.order(:name)
end
end
def call
@base_card = IdCard::PrintData.new()
@employer_cards = []
set_common_fields
set_member_fields
set_plan_fields
@employer_cards.each(&:save!)
end
private
def set_common_fields
employer_attributes = {
employer_name: @card_config.print_name,
pl_plan_key: @card_config.pl_plan_key,
group_number: @employer.group_number,
rx_group: @card_config.rx_group_number,
network_provider: @card_config.network_provider
}
rx_attributes = @card_config.rx_section.attributes.with_indifferent_access.slice(
:customer_service,
:web_url
)
provider_attributes = @card_config.provider_section.attributes.with_indifferent_access.slice(
:provider_line_1, :provider_line_2, :provider_line_3, :provider_line_4, :provider_line_5, :provider_line_6,
:provider_line_7, :provider_line_8, :provider_line_9, :provider_line_10, :provider_line_11, :provider_line_12,
:claim_to_1, :claim_to_2, :claim_to_3, :claim_to_4, :claim_to_5, :claim_to_6,
:claim_to_7, :claim_to_8, :claim_to_9, :claim_to_10, :claim_to_11, :claim_to_12
)
selected_attributes = employer_attributes.merge(rx_attributes).merge(provider_attributes)
@base_card.assign_attributes(selected_attributes)
end
def set_common_fields_old
employer_attributes = {
employer_name: @card_config.print_name,
group_number: @employer.group_number,
rx_group: @card_config.rx_group_number
}
rx_attributes = @card_config.rx_section.attributes.with_indifferent_access.slice(
:customer_service,
:web_url
)
provider_attributes = @card_config.provider_section.attributes.with_indifferent_access.slice(
:provider_code, :provider_line_1, :provider_line_2, :provider_line_3, :provider_line_4, :provider_line_5, :provider_line_6,
:provider_line_7, :provider_line_8, :provider_line_9, :provider_line_10, :provider_line_11, :provider_line_12,
:claim_to_1, :claim_to_2, :claim_to_3, :claim_to_4, :claim_to_5, :claim_to_6,
:claim_to_7, :claim_to_8, :claim_to_9, :claim_to_10, :claim_to_11, :claim_to_12
)
selected_attributes = employer_attributes.merge(rx_attributes).merge(provider_attributes)
@employer_cards.each do |card|
card.assign_attributes(selected_attributes)
end
end
def set_plan_fields
@card_config.plans.each do |plan|
selected_attributes = {}
plan.plan_benefits.each do |bene|
selected_attributes["benefit_desc_#{bene.sequence}".to_sym] = bene.benefit_desc
selected_attributes["benefit_#{bene.sequence}".to_sym] = bene.benefit
end
@employer_cards.find_all { |card| card.plan_id == plan.id.to_s }.each do |card|
card.assign_attributes(selected_attributes)
end
end
end
def set_member_fields
@group_dependents = Vhcs::VwmbMember.where(pl_plan_key: @employer.pl_plan_key)
@members.each do |me|
effect_date = determine_eff_date(me)
if effect_date
member_card = @base_card.dup
member_attributes = {
full_name: me.id_card_display_name,
full_name_last_name_first: me.name,
primary_mb_member_key: me.pb_entity_key,
family_id: me.family_id,
plan_id: me.id_card_plan_id,
medical_eff_date: effect_date.strftime("%m/%d/%Y")
}
dependent_attributes = get_dependent_fields(me)
if dependent_attributes.present?
selected_attributes = member_attributes.merge(dependent_attributes)
else
selected_attributes = member_attributes
end
member_card.assign_attributes(selected_attributes)
@employer_cards.push(member_card)
end
end
end
# def set_network_fields
# selected_attributes = @employer.card_provider.attributes.with_indifferent_access.slice(
# :provider_line_1, :provider_line_2, :provider_line_3, :provider_line_4, :provider_line_5, :provider_line_6,
# :provider_line_7, :provider_line_8, :provider_line_9, :provider_line_10, :provider_line_11, :provider_line_12,
# :claim_to_1, :claim_to_2, :claim_to_3, :claim_to_4, :claim_to_5, :claim_to_6,
# :claim_to_7, :claim_to_8, :claim_to_9, :claim_to_10, :claim_to_11, :claim_to_12
# )
# @employer_cards.all do |card|
# card.assign_attributes(selected_attributes)
# end
# end
# def set_rx_fields
# # fairos_information = Vhcs::HlrxCrosRef.where(pl_plan_key: 52).first
# selected_attributes = @employer.card_rx.attributes.with_indifferent_access.slice(
# :customer_service,
# :web_url
# )
# @employer_cards.all do |card|
# card.assign_attributes(selected_attributes)
# end
# end
def determine_eff_date(member)
participation = Vhcs::PbProductParticipation.joins('INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', member.pb_entity_key).last
in_effect = participation.in_effect
out_of_effect = participation.out_of_effect
if in_effect <= (Date.today + 90.days) && (out_of_effect - 1.day) > Date.today && out_of_effect > in_effect
in_effect
else
false
end
end
def get_dependent_fields(member)
dependent_attributes = {}
dependents = @group_dependents.where(family_id: member.family_id).where.not(pb_entity_key: member.pb_entity_key)
dependents.each do |dep|
dependent_name = dep.first_name + ' ' + dep.last_name
dependent_attributes["dependent_#{dep.sequence_number - 1}".to_sym] = dependent_name
end
dependent_attributes
end
end
end