Its been a while

This commit is contained in:
Jason Jordan
2026-07-23 10:32:51 -04:00
parent 5a90ea6e14
commit 56009fa158
70 changed files with 686 additions and 147 deletions
+72 -51
View File
@@ -1,7 +1,7 @@
class UpdateMemberJob < ApplicationJob
queue_as :default
def perform(pb_entity_key, employer_id, has_divisions = false, has_dental = false, vw_mb_member = {})
def perform(pb_entity_key, employer_id, has_divisions = false, has_dental = false, add_inactive = 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)
@@ -11,6 +11,8 @@ class UpdateMemberJob < ApplicationJob
INNER JOIN "PBProductAvailability" ON "PBProductAvailability"."PBProductKey" = "PBProduct"."PBProductKey"
INNER JOIN "PBProductParticipation" ON "PBProductParticipation"."PBProductAvailabilityKey" = "PBProductAvailability"."PBProductAvailabilityKey"
INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"
').select('
"PBProduct".*, "PBProductParticipation"."InEffect" AS InEffectDate, "PBProductParticipation"."OutOfEffect" AS OutOfEffectDate
').where('
"PBCoveredEntities"."PBEntityKey" = ?
AND "PBProductParticipation"."InEffect" <= ?
@@ -18,7 +20,9 @@ class UpdateMemberJob < ApplicationJob
vw_mb_member[:pb_entity_key], 3.month.from_now , 1.day.ago
)
if pb_products.present? && vw_mb_member[:social_security_number].present?
pb_products, max_in_effect, max_out_effect = get_products_with_max_dates(vw_mb_member[:pb_entity_key])
if add_inactive || (pb_products.exists? && max_out_effect > 1.year.ago) # && 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]
@@ -26,60 +30,62 @@ class UpdateMemberJob < ApplicationJob
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
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 max_in_effect <= 3.months.from_now && max_out_effect > 1.day.ago
if has_dental
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
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"
').select('
"GEN_LookupTables".*, "PBProductParticipation"."InEffect" AS EffDate
').where('
"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
).order('EffDate DESC').first.short_desc
member.coverage_class = coverage_class
else
member.coverage_class = "NONE"
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
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
member.save!
if has_dental
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
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"
').select('
"GEN_LookupTables".*, "PBProductParticipation"."InEffect" AS EffDate
').where('
"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
).order('EffDate DESC').first.short_desc
member.coverage_class = coverage_class
else
member.coverage_class = "NONE"
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)
member.active = true
else
member.active = false
end
puts "---- #{member.name}"
member.save!
end
member.presence
@@ -87,6 +93,21 @@ class UpdateMemberJob < ApplicationJob
private
def get_products_with_max_dates(pb_entity_key)
pb_product_with_dates = 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"
').select('
"PBProduct".*, "PBProductParticipation"."InEffect" AS InEffectDate, "PBProductParticipation"."OutOfEffect" AS OutOfEffectDate
').where('
"PBCoveredEntities"."PBEntityKey" = ?',
pb_entity_key
)
[pb_product_with_dates, pb_product_with_dates.map { |products| products["InEffectDate"]}.max, pb_product_with_dates.map { |products| products["OutOfEffectDate"]}.max]
end
def get_dependent_names_by_sequence(member)
dependents = Vhcs::VwmbMember.joins('
INNER JOIN "PBCoveredEntities" ON "PBCoveredEntities"."PBEntityKey" = "vwMBMember"."PBEntityKey"