automation and view updates
This commit is contained in:
+111
-100
@@ -1,112 +1,123 @@
|
||||
class UpdateEmployerJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(pl_plan_key, plan_header = {}, full_sync = false)
|
||||
def perform(employer_identifier: {}, employer_plan_header: {}, full_sync: false)
|
||||
|
||||
unless plan_header.present?
|
||||
sql_query = "SELECT PLPlanKey, PlanId, ShortDesc FROM PLPlanHeader WHERE PLPlanKey = #{pl_plan_key}"
|
||||
plan_header = VhcsRecord.connection.select_all(sql_query).first
|
||||
if employer_plan_header.present?
|
||||
pl_plan_key = employer_plan_header['PLPlanKey'].to_s
|
||||
elsif employer_identifier[:group_number]
|
||||
group_number = employer_identifier[:group_number]
|
||||
pl_plan_key = Vhcs::PlPlanGroupCode.find_by(group_code: group_number).pl_plan_key
|
||||
elsif employer_identifier[:pl_plan_key]
|
||||
pl_plan_key = employer_identifier[:pl_plan_key]
|
||||
end
|
||||
|
||||
puts "== Updating #{plan_header['ShortDesc'].strip.titleize} =="
|
||||
if pl_plan_key.present?
|
||||
|
||||
plan_code = Vhcs::HlPlanCode.find_by(plan_key: plan_header['PLPlanKey'])
|
||||
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: plan_header['PLPlanKey'])
|
||||
employer = Employer.find_or_create_by!(pl_plan_key: plan_header['PLPlanKey'])
|
||||
full_sync = employer.previously_new_record? || full_sync
|
||||
# id_card_setup = employer.id_card_setup || employer.create_id_card_setup(pl_plan_key: employer.pl_plan_key)
|
||||
# id_card_setup = employer.id_card_setup.find_or_create_by(pl_plan_key: employer.pl_plan_key)
|
||||
|
||||
employer_update_attrs = {}
|
||||
setup_update_attrs = {}
|
||||
|
||||
employer_update_attrs.merge!({
|
||||
plan_id: plan_header['PlanId'].strip.to_i,
|
||||
company_pb_entity_key: pb_company_plan.company_pb_entity_key
|
||||
})
|
||||
|
||||
if plan_code.present?
|
||||
employer_update_attrs.merge!({
|
||||
group_number: plan_code.group_number,
|
||||
effective_date: plan_code.effect_date.strftime("%m/%d/%Y")
|
||||
})
|
||||
setup_update_attrs.merge!({
|
||||
rx_group_number: plan_code.medical_number
|
||||
})
|
||||
end
|
||||
|
||||
# id_card_setup = employer.id_card_setup.find_or_create_by(pl_plan_key: employer.pl_plan_key)
|
||||
# employer.name = plan_header['ShortDesc'].strip.titleize
|
||||
# employer.plan_id = plan_header['PlanId'].strip.to_i
|
||||
|
||||
|
||||
# id_card_templates = determine_id_card_templates(employer.pl_plan_key)
|
||||
# employer.single_card_template = id_card_templates[:single_card_template]
|
||||
# employer.multiple_card_template = id_card_templates[:multiple_card_template]
|
||||
|
||||
if full_sync
|
||||
employer_update_attrs.merge!({
|
||||
name: plan_header['ShortDesc'].strip.titleize
|
||||
})
|
||||
setup_update_attrs.merge!({
|
||||
print_name: determine_card_print_name(pb_company_plan.company_pb_entity_key, @pl_plan_key)
|
||||
})
|
||||
end
|
||||
employer.update(employer_update_attrs)
|
||||
# if full_sync
|
||||
# setup_update_attrs.merge!{
|
||||
# print_name: card_print_name
|
||||
# }
|
||||
# end
|
||||
id_card_setup = employer.id_card_setup || employer.create_id_card_setup!(pl_plan_key: employer.pl_plan_key)
|
||||
id_card_setup.update(setup_update_attrs)
|
||||
|
||||
# plan_code = Vhcs::HlPlanCode.find_by(plan_key: employer.pl_plan_key)
|
||||
# employer.group_number = plan_code.group_number
|
||||
# id_card_setup.rx_group_number = plan_code.medical_number
|
||||
# employer.effective_date = plan_code.effect_date.strftime("%m/%d/%Y")
|
||||
|
||||
# pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: employer.pl_plan_key)
|
||||
# employer.company_pb_entity_key = pb_company_plan.company_pb_entity_key
|
||||
|
||||
# card_print_name = Vhcs::PbEntity.where(company_pb_entity_key: employer.company_pb_entity_key, entity_type_id: 1007).last.last_name
|
||||
# id_card_setup.print_name = card_print_name
|
||||
|
||||
# if employer.up_to_date?
|
||||
# employer.active = true
|
||||
# end
|
||||
|
||||
# employer.default_network_logo = determine_network_logos(employer.pl_plan_key)
|
||||
|
||||
# plan_codes = Vhcs::HlEgglestonCardBenefit.where(plan_key: employer.pl_plan_key).pluck(:plan_id).uniq
|
||||
employer_plans = employer.id_card_setup.plans
|
||||
plan_titles = employer_plans.pluck(:title)
|
||||
vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: pb_company_plan.company_pb_entity_key, is_active: 255)
|
||||
vhcs_plans.each do |vp|
|
||||
if employer_plans.present? && plan_titles.all?(&:present?) && employer_plans.find_by(pb_product_key: vp.pb_product_key).nil?
|
||||
plan_title_matcher = Amatch::JaroWinkler.new(vp.short_description)
|
||||
closest_title = plan_titles.max_by { |title| plan_title_matcher.match(title) }
|
||||
plan = employer_plans.find_or_create_by(title: closest_title)
|
||||
plan.update(
|
||||
title: vp.short_description,
|
||||
pb_product_key: vp.pb_product_key,
|
||||
pl_plan_key: employer.pl_plan_key
|
||||
)
|
||||
plan_titles.delete(closest_title)
|
||||
elsif employer_plans.blank?
|
||||
employer_plans.create!(
|
||||
pb_product_key: vp.pb_product_key,
|
||||
title: vp.short_description,
|
||||
pl_plan_key: employer.pl_plan_key
|
||||
)
|
||||
# plan.update(
|
||||
# title: vp.short_description,
|
||||
# pl_plan_key: employer.pl_plan_key
|
||||
# )
|
||||
if employer_plan_header.empty?
|
||||
sql_query = "SELECT PLPlanKey, PlanId, ShortDesc FROM PLPlanHeader WHERE PLPlanKey = #{pl_plan_key}"
|
||||
employer_plan_header = VhcsRecord.connection.select_all(sql_query).first
|
||||
end
|
||||
end
|
||||
|
||||
employer
|
||||
puts "== Updating #{employer_plan_header['ShortDesc'].strip.titleize} =="
|
||||
|
||||
plan_code = Vhcs::HlPlanCode.find_by(plan_key: pl_plan_key)
|
||||
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: pl_plan_key)
|
||||
employer = Employer.find_or_create_by!(employer_identifier)
|
||||
id_card_setup = employer.id_card_setup || employer.create_id_card_setup!(pl_plan_key: employer.pl_plan_key)
|
||||
full_sync = employer.previously_new_record? || full_sync
|
||||
unless group_number.present?
|
||||
group_number = Vhcs::PlPlanGroupCode.find_by(pl_plan_key: pl_plan_key).group_code
|
||||
end
|
||||
|
||||
employer_update_attrs = {}
|
||||
employer_update_attrs.merge!({
|
||||
plan_id: employer_plan_header['PlanId'].strip.to_i,
|
||||
company_pb_entity_key: pb_company_plan.company_pb_entity_key,
|
||||
group_number: group_number,
|
||||
pl_plan_key: pl_plan_key
|
||||
})
|
||||
|
||||
if plan_code.present? && employer.effective_date.blank?
|
||||
employer_update_attrs.merge!({
|
||||
effective_date: plan_code.effect_date.strftime("%m/%d/%Y")
|
||||
})
|
||||
end
|
||||
|
||||
if full_sync && employer.name.blank?
|
||||
employer_update_attrs.merge!({
|
||||
name: employer_plan_header['ShortDesc'].strip.titleize
|
||||
})
|
||||
end
|
||||
|
||||
employer.update(employer_update_attrs)
|
||||
|
||||
if [employer.pl_plan_key, employer.group_number, employer.company_pb_entity_key, employer.plan_id].all?(&:present?)
|
||||
employer.update(active: true)
|
||||
end
|
||||
|
||||
setup_update_attrs = {}
|
||||
if plan_code.present? && id_card_setup.rx_group_number.blank?
|
||||
setup_update_attrs.merge!({
|
||||
rx_group_number: plan_code.medical_number
|
||||
})
|
||||
end
|
||||
|
||||
if full_sync
|
||||
setup_update_attrs.merge!({
|
||||
print_name: determine_card_print_name(pb_company_plan.company_pb_entity_key, pl_plan_key)
|
||||
})
|
||||
end
|
||||
|
||||
id_card_setup.update(setup_update_attrs)
|
||||
|
||||
# plan_code = Vhcs::HlPlanCode.find_by(plan_key: employer.pl_plan_key)
|
||||
# employer.group_number = plan_code.group_number
|
||||
# id_card_setup.rx_group_number = plan_code.medical_number
|
||||
# employer.effective_date = plan_code.effect_date.strftime("%m/%d/%Y")
|
||||
|
||||
# pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: employer.pl_plan_key)
|
||||
# employer.company_pb_entity_key = pb_company_plan.company_pb_entity_key
|
||||
|
||||
# card_print_name = Vhcs::PbEntity.where(company_pb_entity_key: employer.company_pb_entity_key, entity_type_id: 1007).last.last_name
|
||||
# id_card_setup.print_name = card_print_name
|
||||
|
||||
# if employer.up_to_date?
|
||||
# employer.active = true
|
||||
# end
|
||||
|
||||
# employer.default_network_logo = determine_network_logos(employer.pl_plan_key)
|
||||
|
||||
# plan_codes = Vhcs::HlEgglestonCardBenefit.where(plan_key: employer.pl_plan_key).pluck(:plan_id).uniq
|
||||
# employer_plans = employer.id_card_setup.plans
|
||||
# plan_titles = employer_plans.pluck(:title)
|
||||
# vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: pb_company_plan.company_pb_entity_key, is_active: 255)
|
||||
# vhcs_plans.each do |vp|
|
||||
# if employer_plans.present? && plan_titles.all?(&:present?) && employer_plans.find_by(pb_product_key: vp.pb_product_key).nil?
|
||||
# plan_title_matcher = Amatch::JaroWinkler.new(vp.short_description)
|
||||
# closest_title = plan_titles.max_by { |title| plan_title_matcher.match(title) }
|
||||
# plan = employer_plans.find_or_create_by(title: closest_title)
|
||||
# plan.update(
|
||||
# title: vp.short_description,
|
||||
# pb_product_key: vp.pb_product_key,
|
||||
# pl_plan_key: employer.pl_plan_key
|
||||
# )
|
||||
# plan_titles.delete(closest_title)
|
||||
# elsif employer_plans.blank?
|
||||
# employer_plans.create!(
|
||||
# pb_product_key: vp.pb_product_key,
|
||||
# title: vp.short_description,
|
||||
# pl_plan_key: employer.pl_plan_key
|
||||
# )
|
||||
# # plan.update(
|
||||
# # title: vp.short_description,
|
||||
# # pl_plan_key: employer.pl_plan_key
|
||||
# # )
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
employer.presence
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
class UpdateEmployerPlansJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(pl_plan_key)
|
||||
|
||||
employer = Employer.includes(:id_card_setup).find_by(pl_plan_key: pl_plan_key)
|
||||
setup = employer.id_card_setup
|
||||
puts "== Updating #{employer.name} Plans =="
|
||||
|
||||
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: pl_plan_key)
|
||||
|
||||
vhcs_card_plans = Vhcs::PbProduct.where(company_pb_entity_key: pb_company_plan.company_pb_entity_key, is_active: 255).where.not("ShortDescription LIKE ?", "%Vision%")
|
||||
unless setup.has_dental
|
||||
vhcs_card_plans = vhcs_card_plans.where.not("ShortDescription LIKE ?", "%Dental%")
|
||||
end
|
||||
vhcs_card_plan_product_keys = vhcs_card_plans.pluck(:pb_product_key)
|
||||
vhcs_card_plan_titles = vhcs_card_plans.pluck(:short_description).map(&:strip)
|
||||
|
||||
employer_plans = employer.id_card_setup.plans
|
||||
employer_plan_product_keys = employer_plans.pluck(:pb_product_key)
|
||||
employer_plan_titles = employer_plans.pluck(:title)
|
||||
plans_without_product_key = employer_plans.where(pb_product_key: ["", nil])
|
||||
|
||||
new_card_plan_pb_product_keys = vhcs_card_plan_product_keys - employer_plan_product_keys
|
||||
|
||||
vhcs_card_plans_to_import = Vhcs::PbProduct.where(pb_product_key: new_card_plan_pb_product_keys)
|
||||
vhcs_card_plans_to_import.each do |vhcs_plan_import|
|
||||
# if employer_plans.present? && plan_titles.all?(&:present?) && employer_plans.find_by(pb_product_key: vhcs_plan.pb_product_key).nil?
|
||||
# if employer_plans.find_by(pb_product_key: vhcs_plan.pb_product_key).nil?
|
||||
|
||||
if plans_without_product_key
|
||||
plan_title_matcher = Amatch::JaroWinkler.new(vhcs_plan_import.short_description.strip)
|
||||
title_match = employer_plan_titles.max_by { |title| plan_title_matcher.match(title) }
|
||||
plan = employer_plans.find_or_create_by(title: title_match)
|
||||
plan.update(
|
||||
pb_product_key: vhcs_plan_import.pb_product_key,
|
||||
title: vhcs_plan_import.short_description.strip,
|
||||
pl_plan_key: employer.pl_plan_key
|
||||
)
|
||||
employer_plan_titles.delete(title_match)
|
||||
else
|
||||
employer_plans.create!(
|
||||
pb_product_key: vhcs_plan_import.pb_product_key,
|
||||
title: vhcs_plan_import.short_description.strip,
|
||||
pl_plan_key: employer.pl_plan_key
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
employer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def determine_card_print_name(company_pb_entity_key, pl_plan_key)
|
||||
card_print_names = Vhcs::PbEntity.where(company_pb_entity_key: company_pb_entity_key, entity_type_id: 1007)
|
||||
.where.not("LastName LIKE ? OR LastName LIKE ? OR LastName LIKE ?", "%COBRA%", "Active", ".%").pluck(:last_name)
|
||||
if pl_plan_key == "2"
|
||||
"sm ART"
|
||||
elsif card_print_names.count > 2
|
||||
Employer.employer_trim_name(card_print_names.first)
|
||||
else
|
||||
card_print_names.last
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,11 +3,11 @@ class UpdateMemberJob < ApplicationJob
|
||||
|
||||
def perform(pb_entity_key, employer_id, has_divisions = false, has_dental = false, vw_mb_member = {})
|
||||
|
||||
unless vw_mb_member.present?
|
||||
vw_mb_member = Vhcs::VwmbMember.find_by(enrollee_type_value_id: 1, pb_entity_key: pb_entity_key).attributes.with_indifferent_access.slice(:mb_member_key, :pb_entity_key, :pl_plan_key, :family_id, :full_name_last_name_first, :social_security_number)
|
||||
end
|
||||
unless vw_mb_member.present?
|
||||
vw_mb_member = Vhcs::VwmbMember.find_by(enrollee_type_value_id: 1, pb_entity_key: pb_entity_key).attributes.with_indifferent_access.slice(:mb_member_key, :pb_entity_key, :pl_plan_key, :family_id, :full_name_last_name_first, :social_security_number)
|
||||
end
|
||||
|
||||
pb_products = Vhcs::PbProduct.joins('
|
||||
pb_products = 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"
|
||||
@@ -42,7 +42,7 @@ class UpdateMemberJob < ApplicationJob
|
||||
end
|
||||
|
||||
if has_dental
|
||||
medical_pb_product_key = pb_products.where(short_description: "Medical")&.first&.pb_product_key
|
||||
medical_pb_product_key = pb_products.where("ShortDescription LIKE ?", "%Medical%")&.first&.pb_product_key
|
||||
dental_pb_product_key = pb_products.where("ShortDescription LIKE ?", "%Dental%")&.first&.pb_product_key
|
||||
# dental_pb_product_key = pb_products.where(short_description: "Dental")&.first&.pb_product_key
|
||||
if dental_pb_product_key
|
||||
@@ -74,8 +74,8 @@ class UpdateMemberJob < ApplicationJob
|
||||
# else
|
||||
|
||||
# end
|
||||
puts "---- #{member.name}"
|
||||
end
|
||||
puts "---- #{member.name}"
|
||||
member.presence
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user