Employers working - onboarding to card print
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
module EmployerCards
|
||||
class DataFormatter
|
||||
|
||||
def initialize(employer)
|
||||
@employer = employer
|
||||
end
|
||||
|
||||
def call
|
||||
@members = @employer.members
|
||||
@employer_cards = []
|
||||
|
||||
init_cards_and_set_member_fields
|
||||
set_plan_fields
|
||||
set_common_fields
|
||||
|
||||
@employer_cards.each(&:save!)
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_common_fields
|
||||
employer_attributes = {
|
||||
employer_name: @employer.id_card_display_name,
|
||||
group_number: @employer.group_number,
|
||||
rx_group: @employer.rx_group_number
|
||||
}
|
||||
|
||||
rx_attributes = @employer.card_rx.attributes.with_indifferent_access.slice(
|
||||
:customer_service,
|
||||
:web_url
|
||||
)
|
||||
|
||||
provider_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
|
||||
)
|
||||
|
||||
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
|
||||
@employer.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 init_cards_and_set_member_fields
|
||||
@members.each do |me|
|
||||
effect_date = determine_eff_date(me)
|
||||
if effect_date
|
||||
member_card = SampleIdCard.new()
|
||||
selected_attributes = {
|
||||
full_name: me.id_card_display_name,
|
||||
primary_mb_member_key: me.mb_member_key,
|
||||
family_id: me.family_id,
|
||||
plan_id: me.plan_id,
|
||||
medical_eff_date: effect_date.strftime("%m/%d/%Y")
|
||||
|
||||
}
|
||||
|
||||
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).first
|
||||
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 set_dependent_fields
|
||||
# Not needed for sample card
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user