285 lines
11 KiB
Ruby
285 lines
11 KiB
Ruby
def determine_id_card_templates(pl_plan_key)
|
||
pl_plan_key = pl_plan_key.to_i
|
||
if [13, 19, 20, 48, 49, 50, 51, 52, 53, 54, 58, 59, 61].include?(pl_plan_key)
|
||
single_card_template = 'CignaFairosIDCard'
|
||
elsif [39].include?(pl_plan_key)
|
||
single_card_template = 'CignaFairosIDCard-HALF'
|
||
elsif [4, 5, 16, 23, 33, 55, 57, 63].include?(pl_plan_key)
|
||
single_card_template = 'MedCostFairosIDCard'
|
||
elsif [1, 2].include?(pl_plan_key)
|
||
single_card_template = 'SmartIDCard'
|
||
elsif [10, 17].include?(pl_plan_key)
|
||
single_card_template = 'FirstCallTPAIDCard'
|
||
elsif [15, 18].include?(pl_plan_key)
|
||
single_card_template = 'SRIIDCARD'
|
||
elsif [21].include?(pl_plan_key)
|
||
single_card_template = 'SRIIDCARDFairosRx'
|
||
elsif [3].include?(pl_plan_key)
|
||
single_card_template = 'TPAIDCardTan'
|
||
elsif [56].include?(pl_plan_key)
|
||
single_card_template = 'CignaHealthBusIDCard'
|
||
else
|
||
single_card_template = 'TPAIDCard'
|
||
end
|
||
|
||
if [4, 5, 16, 21, 33, 55, 57, 58, 59, 61].include?(pl_plan_key)
|
||
multiple_card_template = 'AllTPAIDCardFairosRx'
|
||
elsif [13, 19, 20, 39, 48, 49, 50, 52, 53, 54].include?(pl_plan_key)
|
||
multiple_card_template = 'AllHerritageIdCards'
|
||
elsif [15, 18].include?(pl_plan_key)
|
||
multiple_card_template = 'ALLSRIIDCARD'
|
||
elsif [10, 17].include?(pl_plan_key)
|
||
multiple_card_template = 'AllFirstCallTPAIDCard'
|
||
elsif [3].include?(pl_plan_key)
|
||
multiple_card_template = 'AllTPAIDCardTan'
|
||
elsif [56].include?(pl_plan_key)
|
||
multiple_card_template = 'AllCignaHealthBusIDCard'
|
||
else
|
||
multiple_card_template = 'AllTPAIDCard'
|
||
end
|
||
|
||
{
|
||
single_card_template: single_card_template,
|
||
multiple_card_template: multiple_card_template
|
||
}
|
||
end
|
||
|
||
def determine_network_logos(pl_plan_key)
|
||
pl_plan_key = pl_plan_key.to_i
|
||
exception_logos = []
|
||
if [4, 5, 16, 23, 33, 55, 57, 63].include?(pl_plan_key)
|
||
default_net_logo_image = 'Logo_MC_PMS.png'
|
||
elsif [15, 18, 19, 20, 13, 21].include?(pl_plan_key)
|
||
default_net_logo_image = 'CignaLogo.png'
|
||
elsif [62].include?(pl_plan_key)
|
||
default_net_logo_image = 'CignaLogo.png'
|
||
else
|
||
default_net_logo_image = 'CignaLogo.png'
|
||
|
||
|
||
# exception_logos << ProviderNetworkLogo.new(
|
||
# exception_type: 'zip',
|
||
# exception_value: '49420',
|
||
# net_logo: 'CignaPHLogo.jpg'
|
||
# )
|
||
|
||
# exception_logos << ProviderNetworkLogo.new(
|
||
# exception_type: 'zip',
|
||
# exception_value: '48167',
|
||
# net_logo: 'CignaPHLogo.jpg'
|
||
# )
|
||
|
||
# exception_logos << ProviderNetworkLogo.new(
|
||
# exception_type: 'zip',
|
||
# exception_value: '55419',
|
||
# net_logo: 'CignaHPLogo.jpg'
|
||
# )
|
||
|
||
# exception_logos << ProviderNetworkLogo.new(
|
||
# exception_type: 'zip',
|
||
# exception_value: '55379',
|
||
# net_logo: 'CignaHPLogo.jpg'
|
||
# )
|
||
end
|
||
end
|
||
|
||
# benefit_descriptions = ["Primary Visit",
|
||
# "Specialist Visit",
|
||
# "Urgent Care",
|
||
# "INN–Ind Ded",
|
||
# "INN–Family Ded",
|
||
# "OON–Ind Ded",
|
||
# "OON–Family Ded",
|
||
# "Co-Insurance",
|
||
# "INN–Ind OOP",
|
||
# "INN–Family OOP",
|
||
# "OON–Ind OOP",
|
||
# "OON–Family OOP",
|
||
# "Emergency Room",
|
||
# "Preventive Care"]
|
||
|
||
# default = IdCardBenefitsTemplate.create(title: "BLANK")
|
||
# benefit_descriptions.each_with_index do |bene, i|
|
||
# IdCardBenefit.create(sequence: i + 1, benefit_desc: bene, id_card_benefits_template: default)
|
||
# end
|
||
|
||
# temp_2 = IdCard::Plan.create(title: "Jason's Template", template: true)
|
||
# temp_2.plan_benefits.each do |bene|
|
||
# bene.benefit = "#{bene.sequence} hit wonder"
|
||
# bene.save
|
||
# end
|
||
|
||
# temp_1 = IdCardBenefitsTemplate.create(title: "Rebekah's Template")
|
||
# (1..14).each do |seq|
|
||
# IdCardBenefit.create(sequence: seq, benefit: "greatest hits vol #{seq}", id_card_benefits_template: temp_1)
|
||
# end
|
||
|
||
|
||
# historical_id_card_docs = Dir['tmp/*.docx']
|
||
# historical_id_card_docs.each do |card_doc|
|
||
# puts card_doc
|
||
# BenefitsWordDocProcessor.new(card_doc).call
|
||
# end
|
||
|
||
# acentria = Carrier.find_or_create_by!(name: 'Acentria')
|
||
|
||
# mcswain_broker = Broker.find_or_create_by!(name: 'Tom McSwain') do |mc|
|
||
# mc.carrier = acentria
|
||
# end
|
||
|
||
# mcswain_employers = HebWeb::BrokerXRef.where(pl_plan_key: 99).pluck(:employer_pl_plan_key)
|
||
|
||
|
||
# Imports employers and members from VHCS
|
||
sql_query = "SELECT PLPlanKey, PlanId, ShortDesc FROM PLPlanHeader WHERE ActiveInactive = 'Active' AND PLPlanKey = 65"
|
||
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
|
||
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]
|
||
|
||
plan_code = Vhcs::HlPlanCode.find_by(plan_key: em.pl_plan_key)
|
||
em.group_number = plan_code.group_number
|
||
em.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_display_name = Vhcs::PbEntity.find_by(company_pb_entity_key: em.company_pb_entity_key).last_name
|
||
em.id_card_display_name = em.employer_trim_name(card_display_name)
|
||
|
||
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.plans.find_or_create_by!(pb_product_key: vp.pb_product_key) do |pl|
|
||
pl.title = vp.short_description
|
||
end
|
||
vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: import_plan.pb_product_key)
|
||
vhcs_plan_benefits.each do |vb|
|
||
import_plan.plan_benefits.find_or_create_by!(benefit_desc: vb.benefit_desc) do |pb|
|
||
pb.sequence = vb.sequence
|
||
pb.benefit = vb.benefit
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
|
||
# if mcswain_employers.include?(ph['PLPlanKey'])
|
||
# em.broker = mcswain_broker
|
||
# end
|
||
|
||
vw_mb_members = Vhcs::VwmbMember.where(enrollee_type_value_id: 1, pl_plan_key: ph['PLPlanKey']).select(:mb_member_key, :pb_entity_key, :pl_plan_key, :family_id, :full_name_last_name_first)
|
||
vw_mb_members_count = vw_mb_members.length
|
||
|
||
vw_mb_members.each_with_index do |vwm, i|
|
||
import_member = 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 = import_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
|
||
|
||
plan_pb_product_key = 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.pb_product_key
|
||
if plan = Plan.find_by(pb_product_key: plan_pb_product_key)
|
||
me.plan = plan
|
||
end
|
||
end
|
||
puts "Employer #{import_employer.name} (#{i}/#{vw_mb_members_count}) members imported"
|
||
end
|
||
end
|
||
|
||
base_cp_provider_codes = ["5", "2"]
|
||
needed_codes = %w(M T A I 8 7 1 6 3 P C V Y Z)
|
||
# provider_code_map = {}
|
||
vhcs_cp = Vhcs::HlidCardProvider.where(provider_code: base_cp_provider_codes).to_a + Vhcs::HlidCardProvider.where(provider_code: needed_codes).order(:provider_code).to_a
|
||
vhcs_cp.each do |vhcs|
|
||
attributes_hash = vhcs.attributes.except(:provider_code, :group_number)
|
||
attributes_hash.delete_if { |key, value| !key.to_s.include?("_") }
|
||
existing_cp = IdCard::ProviderSection.find_by(attributes_hash)
|
||
|
||
if existing_cp
|
||
existing_cp.title = existing_cp.title.concat(vhcs.provider_code)
|
||
existing_cp.save
|
||
else
|
||
title = case
|
||
when vhcs.provider_line_1 == "PO Box 188061"
|
||
"Cigna #{vhcs.provider_code}"
|
||
when vhcs.provider_line_1.present?
|
||
"#{vhcs.provider_line_1} #{vhcs.provider_code}"
|
||
else
|
||
"Medcost #{vhcs.provider_code}"
|
||
end
|
||
|
||
if base_cp_provider_codes.include?(vhcs.provider_code)
|
||
attributes_hash[:default] = true
|
||
end
|
||
attributes_hash[:title] = title
|
||
attributes_hash[:provider_code] = vhcs.provider_code
|
||
|
||
IdCard::ProviderSection.find_or_create_by(attributes_hash)
|
||
end
|
||
|
||
end
|
||
|
||
base_cp_provider_codes = ["5", "2"]
|
||
needed_codes = %w(M T A I 8 7 1 6 3 P C V Y Z)
|
||
# provider_code_map = {}
|
||
vhcs_cp = Vhcs::HlidCardProvider.where(provider_code: base_cp_provider_codes).to_a + Vhcs::HlidCardProvider.where(provider_code: needed_codes).order(:provider_code).to_a
|
||
vhcs_cp.each do |vhcs|
|
||
attributes_hash = vhcs.attributes.except(:provider_code)
|
||
attributes_hash.delete_if { |key, value| !key.to_s.include?("_") }
|
||
existing_cp = IdCard::ProviderSection.find_by(attributes_hash)
|
||
|
||
if existing_cp
|
||
existing_cp
|
||
# if provider_code_map[existing_cp.provider_code]
|
||
# provider_code_map[existing_cp.provider_code].push(vhcs.provider_code)
|
||
# else
|
||
# provider_code_map[existing_cp.provider_code] = [vhcs.provider_code]
|
||
# end
|
||
else
|
||
attributes_hash[:provider_code] = vhcs.provider_code
|
||
IdCard::ProviderSection.find_or_create_by(attributes_hash)
|
||
end
|
||
end
|
||
|
||
Vhcs::HlrxCrosRef.all.each do |vhcs|
|
||
rx = IdCard::RxSection.find_or_create_by(help_desk: vhcs.help_desk, customer_service: vhcs.customer_service, web_url: vhcs.web_url)
|
||
title = rx.web_url.gsub(/^www\./, '').gsub(/\.com\Z/, '')
|
||
unless title.match?(/\A[A-Z]/)
|
||
title = title.capitalize
|
||
end
|
||
|
||
rx.title = title
|
||
rx.save
|
||
end
|
||
|
||
["CignaLogo.png", "MedCostLogo.png"].each do |logo_upload|
|
||
new_logo = ImageProcessor.new("logo_files/network/#{logo_upload}", "Network").call
|
||
new_logo.default = true
|
||
new_logo.active = true
|
||
new_logo.save
|
||
end
|
||
|
||
|
||
# 15, 18, 19, 20, 13, 21
|
||
|
||
|
||
|
||
|