Major features finished

This commit is contained in:
Jason Jordan
2026-04-15 08:12:47 -04:00
parent 9f306d3150
commit 247a075c9c
112 changed files with 3700 additions and 379 deletions
-90
View File
@@ -1,90 +0,0 @@
class ProcessIdCardDataJob < ApplicationJob
queue_as :default
def perform(member_key, field_exception_ids, has_divisions = false)
member = Member.find_by(pb_entity_key: member_key)
effect_date = determine_eff_date(member)
if effect_date
member_card = @base_card.dup
member_attributes = {
full_name: member.id_card_display_name,
full_name_last_name_first: member.name,
primary_mb_member_key: member.pb_entity_key,
family_id: member.family_id,
plan_id: member.id_card_plan_id,
medical_eff_date: effect_date.strftime("%m/%d/%Y")
}
dependent_attributes = get_dependent_fields(member)
if dependent_attributes.present?
member_attributes.merge!(dependent_attributes)
end
if has_divisions
member_attributes.merge!({employer_name: member.division})
end
if field_exception_ids.present?
exceptions_attributes = {}
field_exceptions = IdCard::FieldException.where(id: field_exception_ids)
member_exception_values = member.id_card_field_exception_values
field_exceptions.each do |fe|
if member_exception_values[fe.field_type] == fe.field_value
fe.field_exception_items.each do |fei|
if fei.field_value.present?
exceptions_attributes[fei.field_name] = fei.field_value
elsif fei.provider_section_id.present?
provider_attributes = IdCard::ProviderSection.find(fei.provider_section_id).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
)
exceptions_attributes.merge!(provider_attributes)
elsif fei.network_logo_id.present?
exceptions_attributes.merge!(network_logo_id: fei.network_logo_id)
exceptions_attributes.merge!(network_logo_filename: fei.network_logo.filename)
end
end
end
end
member_attributes.merge!(exceptions_attributes)
end
member_card = IdCard::PrintData.find_by(pl_plan_key: member.pl_plan_key, plan_id: member.id_card_plan_id, primary_mb_member_key: nil).dup
member_card.assign_attributes(member_attributes)
member_card.save
end
true
# BatchProcess.increment_counter(:completed_jobs, batch_process_id)
end
private
def determine_eff_date(member)
participation = Vhcs::PbProductParticipation.joins('INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', member.pb_entity_key).last
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 get_dependent_fields(member)
dependent_attributes = {}
dependents = Vhcs::VwmbMember.where(pl_plan_key: member.pl_plan_key, family_id: member.family_id).where.not(pb_entity_key: member.pb_entity_key)
dependents.each do |dep|
dependent_name = dep.first_name + ' ' + dep.last_name
dependent_attributes["dependent_#{dep.sequence_number - 1}".to_sym] = dependent_name
end
dependent_attributes
end
end
+118
View File
@@ -0,0 +1,118 @@
class ProcessMemberCardDataJob < ApplicationJob
queue_as :default
def perform(member_key, member_card_exceptions_attrs, has_divisions = false, has_dental = false)
member = Member.find_by(pb_entity_key: member_key)
effect_date = determine_eff_date(member)
if effect_date
member_card = @base_card.dup
member_attributes = {
full_name: member.id_card_display_name,
full_name_last_name_first: member.name,
primary_mb_member_key: member.pb_entity_key,
family_id: member.family_id,
plan_id: member.id_card_plan_id,
medical_eff_date: effect_date.strftime("%m/%d/%Y")
}
if member.dependents.present?
dependent_attributes = format_dependent_attributes(member)
member_attributes.merge!(dependent_attributes)
end
if has_divisions
member_attributes.merge!({employer_name: member.division})
end
if member_card_exceptions_attrs.present?
# exceptions_attributes = {}
# field_exceptions = IdCard::FieldException.where(id: field_exception_ids)
# member_exception_values = member.id_card_field_exception_values
# field_exceptions.each do |fe|
# if fe.exception_values.include?(member_exception_values[fe.exception_type.to_sym])
# fe.field_exception_items.each do |fei|
# if fei.field_value.present?
# exception_eff_date = Date.strptime(fei.field_value, "%m/%d/%Y")
# member_eff_date = Date.strptime(member_attributes[:medical_eff_date], "%m/%d/%Y")
# if exception_eff_date > member_eff_date
# exceptions_attributes[fei.field_name.to_sym] = fei.field_value
# end
# elsif fei.provider_section_id.present?
# provider_attributes = IdCard::ProviderSection.find(fei.provider_section_id).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
# )
# exceptions_attributes.merge!(provider_attributes)
# elsif fei.network_logo_id.present?
# exceptions_attributes.merge!(network_logo_filename: fei.network_logo.filename)
# end
# end
# end
# end
member_attributes.merge!(member_card_exceptions_attrs)
end
if has_dental
if member.dental_plan_key
member_attributes.merge!({dental_coverage: member.coverage_class.upcase})
unless member.id_card_plan_id
member_attributes.merge!({group_number: "", medical_eff_date: ""})
# dental_plan = IdCard::Plan.find_by(pb_product_key: 1025)
if IdCard::Plan.find_by(pb_product_key: member.dental_plan_key).blank?
member_attributes.merge!({employer_name: 'COBRA'})
end
end
end
end
if member.id_card_plan.present? && member.id_card_plan.title.upcase.include?('COBRA')
member_attributes.merge!({employer_name: 'COBRA'})
end
if member.id_card_plan_id.present?
member_card = IdCard::PrintData.find_by(pl_plan_key: member.pl_plan_key, plan_id: member.id_card_plan_id, primary_mb_member_key: nil).dup
else
member_card = IdCard::PrintData.where(pl_plan_key: member.pl_plan_key, primary_mb_member_key: nil).first.dup
end
member_card.assign_attributes(member_attributes)
member_card.save
# if dependent_attributes.present?
# dependent_card = member_card.dup
# dependent_card.full_name_last_name_first = dependent_card.full_name_last_name_first.concat(" dependent")
# dependent_card.save
# end
end
true
# BatchProcess.increment_counter(:completed_jobs, batch_process_id)
end
private
def determine_eff_date(member)
participation = Vhcs::PbProductParticipation.joins('INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', member.pb_entity_key).order(out_of_effect: :desc).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 format_dependent_attributes(member)
dependent_attributes = {}
member.dependents.each_with_index do |dep, index|
dependent_attributes["dependent_#{index + 1}".to_sym] = dep
end
dependent_attributes
end
end
+126
View File
@@ -0,0 +1,126 @@
class UpdateEmployerJob < ApplicationJob
queue_as :default
def perform(pl_plan_key, 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
end
puts "== Updating #{plan_header['ShortDesc'].strip.titleize} =="
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
# )
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
+104
View File
@@ -0,0 +1,104 @@
class UpdateMemberJob < ApplicationJob
queue_as :default
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
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"
').where('
"PBCoveredEntities"."PBEntityKey" = ?
AND "PBProductParticipation"."InEffect" <= ?
AND "PBProductParticipation"."OutOfEffect" > ?',
vw_mb_member[:pb_entity_key], 2.month.from_now , 1.day.ago
)
if pb_products.present? && vw_mb_member[:social_security_number].present?
member = Member.find_or_create_by!(pb_entity_key: vw_mb_member[:pb_entity_key], employer_id: employer_id)
member.name = vw_mb_member[:full_name_last_name_first].titleize
member.mb_member_key = vw_mb_member[:mb_member_key]
member.family_id = vw_mb_member[:family_id]
member.pl_plan_key = vw_mb_member[:pl_plan_key]
card_display_name = Vhcs::PbEntity.find_by(pb_entity_key: member.pb_entity_key).full_name
member.id_card_display_name = card_display_name
if 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"
').find_by('
"PBCoveredEntities"."PBEntityKey" = ?
AND "PBProductParticipation"."OutOfEffect" > ?',
member.pb_entity_key, 1.day.ago
).last_name
member.division = division
end
if has_dental
medical_pb_product_key = pb_products.where(short_description: "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
member.dental_plan_key = dental_pb_product_key
coverage_class = Vhcs::GenLookupTables.joins('
INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."CoverageTypeCode" = "GEN_LookupTables"."RecordID"
INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"
INNER JOIN "PBProductAvailability" ON "PBProductAvailability"."PBProductAvailabilityKey" = "PBProductParticipation"."PBProductAvailabilityKey"
INNER JOIN "PBProduct" ON "PBProduct"."PBProductKey" = "PBProductAvailability"."PBProductKey"
').find_by('
"PBCoveredEntities"."PBEntityKey" = ?
AND "PBProductParticipation"."InEffect" <= ?
AND "PBProductParticipation"."OutOfEffect" > ?
AND "PBProduct"."PBProductKey" = ?',
member.pb_entity_key, 1.month.from_now, 1.day.ago, dental_pb_product_key
).short_desc
member.coverage_class = coverage_class
end
else
medical_pb_product_key = pb_products.first.pb_product_key
end
if medical_pb_product_key && plan = IdCard::Plan.find_by(pb_product_key: medical_pb_product_key)
member.id_card_plan = plan
end
member.dependents = get_dependent_names_by_sequence(member)
# if employer_members_update
# member
# else
# end
end
puts "---- #{member.name}"
member.presence
end
private
def get_dependent_names_by_sequence(member)
dependents = Vhcs::VwmbMember.joins('
INNER JOIN "PBCoveredEntities" ON "PBCoveredEntities"."PBEntityKey" = "vwMBMember"."PBEntityKey"
INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"
INNER JOIN "PBProductAvailability" ON "PBProductAvailability"."PBProductAvailabilityKey" = "PBProductParticipation"."PBProductAvailabilityKey"
INNER JOIN "PBProduct" ON "PBProduct"."PBProductKey" = "PBProductAvailability"."PBProductKey"
').where('
"EnrolleeTypeKey" != 1044 AND "PLPlanKey" = ? AND "PBProductParticipation"."OutOfEffect" >= ? AND "FamilyID" = ?', member.pl_plan_key, Date.today.strftime("%m/%d/%Y"), member.family_id
)
if member.pl_plan_key == 3
dependents = dependents.where('"PBProduct"."PBProductKey" != 1024')
elsif member.pl_plan_key == 2
dependents = dependents.where('"PBProduct"."PBProductKey" != 1019')
end
dependent_names = dependents.order(:sequence_number).map { |dep| dep.first_name + ' ' + dep.last_name}.uniq
dependent_names
end
end