Files
baclight/db/seeds.rb
T
2026-04-15 08:12:47 -04:00

348 lines
10 KiB
Ruby

require "vips"
require "image_processing/vips"
def determine_id_card_templates(pl_plan_key)
case pl_plan_key
when "2"
"SmartIDCard"
when "3"
"TandemlocIDCard"
when "56"
"QRCodeIDCard"
else
"FairosRxIDCard"
end
end
def determine_id_card_rx(pl_plan_key)
if pl_plan_key == "56"
"TheHealthBus"
else
"FairosRx"
end
end
def determine_id_card_network(pl_plan_key)
cigna_groups = ["13","20","39","48","49","51","53","54","56","58","60","61","62","65","67","68","69"]
medcost_groups = ["4","5","16","23","33","55","57","59","63","66"]
old_cigna_groups = ["19","21"]
smart_medcost = ["2"]
tan_medcost = ["3"]
case
when cigna_groups.include?(pl_plan_key) || pl_plan_key.blank?
{ provider: "Cigna", network_logo: "CignaLogo.png", provider_section: "Cigna" }
when medcost_groups.include?(pl_plan_key)
{ provider: "MedCost", network_logo: "MedcostLogo.png", provider_section: "MedCost" }
when old_cigna_groups.include?(pl_plan_key)
{ provider: "Cigna", network_logo: "CignaLogo.png", provider_section: "Cigna (Beam/Stevens)" }
when smart_medcost.include?(pl_plan_key)
{ provider: "MedCost", network_logo: "MedcostLogo.png", provider_section: "MedCost (smART)" }
when tan_medcost.include?(pl_plan_key)
{ provider: "MedCost", network_logo: "MedcostLogo.png", provider_section: "MedCost (Tandemloc)" }
end
end
def determine_divisions(pl_plan_key)
division_employers = ["2", "16"]
if division_employers.include?(pl_plan_key)
true
else
false
end
end
def determine_dental(pl_plan_key)
dental_employers = ["2", "3"]
if dental_employers.include?(pl_plan_key)
true
else
false
end
end
def determine_card_color(pl_plan_key)
if pl_plan_key == "3"
"blue"
else
"white"
end
end
def determine_field_exceptions(pl_plan_key)
exceptions_map = {
"3" => [{
exception_type: "state",
exception_values: ["AZ", "MO", "IL"],
field_exception_items_attributes: [
{field_name: "provider_section", provider_section_id: 3},
{field_name: "network_logo", network_logo_id: 8}
]
}],
"13" => [{
exception_type: "zipcode",
exception_values: ["14422", "14623", "14624"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 3}
]
}],
"16" => [{
exception_type: "state",
exception_values: ["VA"],
field_exception_items_attributes: [
{field_name: "medical_eff_date", field_value: "12/01/2025"},
{field_name: "provider_section", provider_section_id: 7},
{field_name: "network_logo", network_logo_id: 6}
]
}],
"21" => [{
exception_type: "state",
exception_values: ["VA"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 3}
]
}],
"51" => [{
exception_type: "zipcode",
exception_values: ["41456", "41149", "41124"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 4}
]
}],
"55" => [{
exception_type: "state",
exception_values: ["CA", "GA"],
field_exception_items_attributes: [
{field_name: "provider_section", provider_section_id: 8},
{field_name: "network_logo", network_logo_id: 5}
]
}],
"62" => [
{
exception_type: "zipcode",
exception_values: ["49420", "48167"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 2}
]
},
{
exception_type: "zipcode",
exception_values: ["55419", "55379"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 1}
]
}
],
"65" => [
{
exception_type: "zipcode",
exception_values: ["48430", "44842", "48649"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 2}
]
},
{
exception_type: "zipcode",
exception_values: ["55372", "55021"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 1}
]
},
{
exception_type: "zipcode",
exception_values: ["18042", "18080"],
field_exception_items_attributes: [
{field_name: "network_logo", network_logo_id: 10}
]
}
],
"66" => [{
exception_type: "state",
exception_values: ["GA"],
field_exception_items_attributes: [
{field_name: "provider_section", provider_section_id: 8},
{field_name: "network_logo", network_logo_id: 5}
]
}]
}
if exceptions_map[pl_plan_key].present?
exceptions_map[pl_plan_key]
else
nil
end
end
puts "[**** IMPORT ID CARD TABLES ****]"
## SET UP DEFAULT LEVEL360 PLANS FOR PLAN PICKER
# 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
##---------------- Provider/Claims Setup------------------------------------
puts "Importing Card Provider/Claims Information"
default_provider_codes = ["5", "2"]
needed_codes_mapping = {
"0": "MedCost VA Plus Network",
"2": "MedCost",
"3": "AHA Preferred",
"5": "Cigna",
"6": "Cigna (Beam/Stevens)",
A: "AHA",
M: "MedCost (smART)",
T: "MedCost (Tandemloc)"
}.stringify_keys
needed_codes = needed_codes_mapping.keys
vhcs_cp = Vhcs::HlidCardProvider.where(provider_code: needed_codes)
vhcs_cp.each do |vhcs|
attributes_hash = vhcs.attributes.except(:provider_code, :group_number)
attributes_hash.delete_if { |key, value| !key.to_s.include?("_") }
if default_provider_codes.include?(vhcs.provider_code)
attributes_hash[:default] = true
end
attributes_hash[:title] = needed_codes_mapping[vhcs.provider_code]
puts "-- #{attributes_hash[:title]}"
IdCard::ProviderSection.find_or_create_by(attributes_hash)
end
##---------------- Rx info Setup------------------------------------
puts "Importing Card Rx Information"
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
puts "-- #{title}"
rx.title = title
rx.save
end
##---------------- Network Logos Setup------------------------------------
puts "Importing Network Logos"
folder_path = Rails.root.join('logo_files', 'network')
file_names = Dir.children(folder_path)
default_network_logos = ["CignaLogo.png", "MedCostLogo.png"]
file_names.each do |logo_upload|
puts "-- #{logo_upload}"
new_logo = ImageProcessorService.new("logo_files/network/#{logo_upload}", "Network").call
if default_network_logos.include?(logo_upload)
new_logo.default = true
end
new_logo.active = true
new_logo.save
end
##---------------- Active Employer Logo Setup------------------------------------
puts "Importing Employer Logos"
folder_path = Rails.root.join('logo_files', 'employer')
file_names = Dir.children(folder_path)
file_names.each do |logo_upload|
puts "-- #{logo_upload}"
new_logo = ImageProcessorService.new("logo_files/employer/#{logo_upload}", "Employer").call
new_logo.active = true
new_logo.save
end
puts "[**** IMPORT EMPLOYERS ****]"
##---------------- Import Employer/Member (VHCS) ------------------------------------
puts "Importing Employers From VHCS"
Rake::Task["employer:vhcs_sync_all"].invoke
# 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
# use rake tasks
##---------------- Import Employers (Word Docs) ------------------------------------
# puts "Importing Employers From Word Docs"
# folder_path = Rails.root.join('employer_word_docs')
# file_names = Dir.children(folder_path)
# file_names.each do |word_doc|
# puts "-- Processing #{word_doc}"
# new_employer = BenefitsWordDocService::WordDocProcessor.new("employer_word_docs/#{word_doc}").call
# if new_employer.save
# puts "Imported #{new_employer.name}"
# end
# end
##---------------- Update ID Card Setups------------------------------------
puts "[**** UPDATE EMPLOYER ID CARD SETUPS ****]"
IdCard::Setup.all.each do |setup|
setup.card_template = determine_id_card_templates(setup.pl_plan_key)
setup.card_color = determine_card_color(setup.pl_plan_key)
setup.has_divisions = determine_divisions(setup.pl_plan_key)
setup.has_dental = determine_dental(setup.pl_plan_key)
network_information = determine_id_card_network(setup.pl_plan_key)
setup.network_provider = network_information[:provider]
ps = IdCard::ProviderSection.find_by(title: network_information[:provider_section])
setup.provider_section_id = ps.id
nl = IdCard::NetworkLogo.find_by(filename: network_information[:network_logo])
setup.network_logo_id = nl.id
rx_title = determine_id_card_rx(setup.pl_plan_key)
rs = IdCard::RxSection.find_by(title: rx_title)
setup.rx_section_id = rs.id
employer_name = Employer.employer_trim_name(setup.employer.name)
name_segments = employer_name.titleize.split
name_segments.each do |segment|
logo = IdCard::EmployerLogo.where("filename LIKE ?", "%#{segment}%")
if logo&.first
setup.employer_logo = logo.first
break
end
end
card_exceptions = determine_field_exceptions(setup.pl_plan_key)
if card_exceptions.present?
setup.field_exceptions.create(card_exceptions)
# card_exceptions.each do |exc|
# setup.field_exceptions.create(exc)
# end
end
if setup.pl_plan_key.present?
setup.active = true
end
setup.save
end
# 15, 18, 19, 20, 13, 21