Before adding workers
This commit is contained in:
+73
-60
@@ -7,48 +7,52 @@ namespace :employer do
|
||||
plan_headers = VhcsRecord.connection.select_all(sql_query)
|
||||
|
||||
plan_headers.each do |ph|
|
||||
import_employer = Employer.find_or_create_by!(pl_plan_key: ph['PLPlanKey']) do |em|
|
||||
puts "Importing #{ph['ShortDesc'].strip}"
|
||||
em.name = ph['ShortDesc'].strip.titleize
|
||||
em.plan_id = ph['PlanId'].strip.to_i
|
||||
plan_code = Vhcs::HlPlanCode.find_by(plan_key: ph['PLPlanKey'])
|
||||
if plan_code.present?
|
||||
import_employer = Employer.find_or_create_by!(pl_plan_key: ph['PLPlanKey']) do |em|
|
||||
puts "Importing #{ph['ShortDesc'].strip}"
|
||||
em.name = ph['ShortDesc'].strip.titleize
|
||||
em.plan_id = ph['PlanId'].strip.to_i
|
||||
|
||||
|
||||
id_card_templates = determine_id_card_templates(em.pl_plan_key)
|
||||
# em.single_card_template = id_card_templates[:single_card_template]
|
||||
# em.multiple_card_template = id_card_templates[:multiple_card_template]
|
||||
|
||||
id_card_templates = determine_id_card_templates(em.pl_plan_key)
|
||||
# em.single_card_template = id_card_templates[:single_card_template]
|
||||
# em.multiple_card_template = id_card_templates[:multiple_card_template]
|
||||
|
||||
id_card_configuration = em.build_id_card_configuration(pl_plan_key: em.pl_plan_key)
|
||||
|
||||
plan_code = Vhcs::HlPlanCode.find_by(plan_key: em.pl_plan_key)
|
||||
em.group_number = plan_code.group_number
|
||||
id_card_configuration.rx_group_number = plan_code.medical_number
|
||||
em.effective_date = plan_code.effect_date.strftime("%m/%d/%Y")
|
||||
|
||||
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: em.pl_plan_key)
|
||||
em.company_pb_entity_key = pb_company_plan.company_pb_entity_key
|
||||
|
||||
card_print_name = Vhcs::PbEntity.find_by(company_pb_entity_key: em.company_pb_entity_key).last_name
|
||||
id_card_configuration.print_name = em.employer_trim_name(card_print_name)
|
||||
id_card_setup = em.build_id_card_setup(pl_plan_key: em.pl_plan_key)
|
||||
|
||||
# plan_code = Vhcs::HlPlanCode.find_by(plan_key: em.pl_plan_key)
|
||||
em.group_number = plan_code.group_number
|
||||
id_card_setup.rx_group_number = plan_code.medical_number
|
||||
em.effective_date = plan_code.effect_date.strftime("%m/%d/%Y")
|
||||
|
||||
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: em.pl_plan_key)
|
||||
em.company_pb_entity_key = pb_company_plan.company_pb_entity_key
|
||||
|
||||
card_print_name = Vhcs::PbEntity.find_by(company_pb_entity_key: em.company_pb_entity_key).last_name
|
||||
id_card_setup.print_name = em.employer_trim_name(card_print_name)
|
||||
|
||||
em.active = true
|
||||
em.active = true
|
||||
|
||||
# em.default_network_logo = determine_network_logos(em.pl_plan_key)
|
||||
end
|
||||
# em.default_network_logo = determine_network_logos(em.pl_plan_key)
|
||||
end
|
||||
|
||||
vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: import_employer.company_pb_entity_key)
|
||||
vhcs_plans.each do |vp|
|
||||
puts "~~ Importing #{vp.short_description}"
|
||||
import_plan = import_employer.id_card_configuration.plans.find_or_create_by!(pb_product_key: vp.pb_product_key) do |pl|
|
||||
pl.title = vp.short_description
|
||||
pl.pl_plan_key = import_employer.pl_plan_key
|
||||
pl.template = false
|
||||
end
|
||||
#Find where benefits info comes from for plplankeys ["2", "3", "5", "13", "16", "19", "20", "21", "33", "49"]
|
||||
vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: import_plan.pb_product_key)
|
||||
vhcs_plan_benefits.each do |vb|
|
||||
import_benefit = import_plan.plan_benefits.find_by(sequence: vb.sequence)
|
||||
import_benefit.update(benefit: vb.benefit)
|
||||
end
|
||||
plan_codes = Vhcs::HlEgglestonCardBenefit.where(plan_key: import_employer.pl_plan_key).pluck(:plan_id).uniq
|
||||
vhcs_plans = Vhcs::PbProduct.where(pb_product_key: plan_codes, is_active: 255)
|
||||
vhcs_plans.each do |vp|
|
||||
puts "~~ Importing #{vp.short_description}"
|
||||
import_plan = import_employer.id_card_setup.plans.find_or_create_by!(pb_product_key: vp.pb_product_key) do |pl|
|
||||
pl.title = vp.short_description
|
||||
pl.pl_plan_key = import_employer.pl_plan_key
|
||||
pl.template = false
|
||||
end
|
||||
#Find where benefits info comes from for plplankeys ["2", "3", "5", "13", "16", "19", "20", "21", "33", "49"]
|
||||
vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: import_plan.pb_product_key)
|
||||
vhcs_plan_benefits.each do |vb|
|
||||
import_benefit = import_plan.plan_benefits.find_by(sequence: vb.sequence)
|
||||
import_benefit.update(benefit: vb.benefit)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -65,36 +69,45 @@ namespace :employer do
|
||||
vw_mb_members_count = vw_mb_members.length
|
||||
|
||||
vw_mb_members.each_with_index do |vwm, i|
|
||||
Member.find_or_create_by!(mb_member_key: vwm.mb_member_key) do |me|
|
||||
me.name = vwm.full_name_last_name_first.titleize
|
||||
me.pb_entity_key = vwm.pb_entity_key
|
||||
me.family_id = vwm.family_id
|
||||
me.pl_plan_key = vwm.pl_plan_key
|
||||
me.employer = employer
|
||||
|
||||
card_display_name = Vhcs::PbEntity.find_by(pb_entity_key: me.pb_entity_key).full_name
|
||||
me.id_card_display_name = card_display_name
|
||||
participation = Vhcs::PbProductParticipation.joins('INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', vwm.pb_entity_key).last
|
||||
|
||||
if participation.present?
|
||||
in_effect = participation.in_effect
|
||||
out_of_effect = participation.out_of_effect
|
||||
|
||||
if me.pl_plan_key == '16'
|
||||
division = Vhcs::PbEntity.joins('
|
||||
INNER JOIN "PBAffiliation" ON "PBAffiliation"."ParentPBEntityKey" = "PBEntity"."PBEntityKey"
|
||||
INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."PBAffiliationKey" = "PBAffiliation"."PBAffiliationKey"
|
||||
INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"
|
||||
').where('"PBCoveredEntities"."PBEntityKey" = ?', me.pb_entity_key).uniq.first.last_name
|
||||
me.division = division
|
||||
end
|
||||
if in_effect <= (Date.today + 90.days) && (out_of_effect - 1.day) > Date.today && out_of_effect > in_effect
|
||||
Member.find_or_create_by!(mb_member_key: vwm.mb_member_key) do |me|
|
||||
me.name = vwm.full_name_last_name_first.titleize
|
||||
me.pb_entity_key = vwm.pb_entity_key
|
||||
me.family_id = vwm.family_id
|
||||
me.pl_plan_key = vwm.pl_plan_key
|
||||
me.employer = employer
|
||||
|
||||
pb_product = Vhcs::PbProduct.joins('INNER JOIN "PBProductAvailability" ON "PBProductAvailability"."PBProductKey" = "PBProduct"."PBProductKey" INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."PBProductAvailabilityKey" = "PBProductAvailability"."PBProductAvailabilityKey" INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', me.pb_entity_key).first
|
||||
if pb_product
|
||||
plan_pb_product_key = pb_product.pb_product_key
|
||||
if plan = IdCard::Plan.find_by(pb_product_key: plan_pb_product_key)
|
||||
me.id_card_plan = plan
|
||||
card_display_name = Vhcs::PbEntity.find_by(pb_entity_key: me.pb_entity_key).full_name
|
||||
me.id_card_display_name = card_display_name
|
||||
|
||||
if employer.id_card_setup.has_divisions
|
||||
division = Vhcs::PbEntity.joins('
|
||||
INNER JOIN "PBAffiliation" ON "PBAffiliation"."ParentPBEntityKey" = "PBEntity"."PBEntityKey"
|
||||
INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."PBAffiliationKey" = "PBAffiliation"."PBAffiliationKey"
|
||||
INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"
|
||||
').where('"PBCoveredEntities"."PBEntityKey" = ?', me.pb_entity_key).uniq.first.last_name
|
||||
me.division = division
|
||||
end
|
||||
|
||||
pb_product = Vhcs::PbProduct.joins('INNER JOIN "PBProductAvailability" ON "PBProductAvailability"."PBProductKey" = "PBProduct"."PBProductKey" INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."PBProductAvailabilityKey" = "PBProductAvailability"."PBProductAvailabilityKey" INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', me.pb_entity_key).first
|
||||
if pb_product
|
||||
plan_pb_product_key = pb_product.pb_product_key
|
||||
if plan = IdCard::Plan.find_by(pb_product_key: plan_pb_product_key)
|
||||
me.id_card_plan = plan
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Employer #{employer.name} (#{i}/#{vw_mb_members_count}) members processed"
|
||||
end
|
||||
puts "Employer #{employer.name} (#{i}/#{vw_mb_members_count}) members imported"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user