automation and view updates

This commit is contained in:
Jason Jordan
2026-04-17 15:35:10 -04:00
parent 247a075c9c
commit 7ab1143db8
30 changed files with 124704 additions and 602 deletions
+92 -20
View File
@@ -2,34 +2,96 @@ module EmployerAutomation
extend ActiveSupport::Concern
included do
scope :new_groups, -> {
where(active: false)
.where.not(pl_plan_key: [nil, ''])
scope :not_automation_ready, -> {
where(pl_plan_key: [nil, ''], group_number: [nil, ''])
}
scope :with_plans, -> {
joins(id_card_setup: :plans).distinct
scope :automation_ready, -> {
where.not(pl_plan_key: [nil, ''])
.or(where.not(group_number: [nil, '']))
}
scope :missing_keychain_values, -> {
where(company_pb_entity_key: [nil, ''])
.or(where(plan_id: [nil, '']))
.or(where(group_number: [nil, '']))
.or(where(pl_plan_key: [nil, '']))
}
scope :missing_keychain_initialization, -> {
inactive.automation_ready.missing_keychain_values
}
scope :building_id_card_setup, -> {
active.left_outer_joins(:id_card_setup)
.where(id_card_setup: {active: false})
}
scope :missing_plans_initialization, -> {
building_id_card_setup
.where.missing(:plans)
.or(
where(
id: joins(:plans)
.where(plans: { pb_product_key: [nil, ''] })
.select(:id)
)
)
}
scope :missing_members_initialization, -> {
building_id_card_setup
.where.associated(:plans)
.where.not(
id: joins(:plans)
.where(plans: { pb_product_key: [nil, ''] })
.select(:id)
).distinct
}
scope :active_with_active_id_card_setup, -> {
active.left_outer_joins(:id_card_setup)
.where(id_card_setup: {active: true})
}
scope :with_keychain_values, -> {
where.not(
pl_plan_key: [nil, ''],
group_number: [nil, ''],
company_pb_entity_key: [nil, ''],
plan_id: [nil, '']
)
}
scope :deactivated, -> {
inactive.with_keychain_values
}
# Employer.joins(:id_card_setup)
# .left_outer_joins(:plans)
# .where(plans: { pb_product_key: [nil, ''] })
# .group('users.id') # Group by user ID
# .having('COUNT(posts.id) = 0')
# Employer.left_outer_joins(:plans)
# .where(plans: { id: nil })
# .or(Employer.where(plans: { pb_product_key: [nil, ''] }))
# Employer.where.missing(:plans)
# .or(Employer.joins(:plans).where(plans: { pb_product_key: [nil, ''] }))
# Employer.joins(id_card_setup: :plans).where.not("plans.id_card_setup_id = id_card_setup.id").or
# (where(plans: { pb_product_key: [nil, ''] }))
# scope :with_survey_and_no_questions, -> {
# joins(:survey) # join has_one
# .left_joins(survey: :questions) # join has_many through has_one
# .where(questions: { id: nil }) # filter where has_many is empty
# }
scope :missing_keychain_values, -> {
new_groups
.where(
arel_table[:company_pb_entity_key].in([nil, ''])
.or(arel_table[:plan_id].in([nil, '']))
.or(arel_table[:group_number].in([nil, '']))
.or(arel_table[:effective_date].in([nil, '']))
)
}
scope :missing_initial_members, -> {
new_groups.with_plans
}
# scope :missing_initial_members, -> {
# new_groups.with_plans
# }
end
# class_methods do
@@ -49,11 +111,21 @@ module EmployerAutomation
# end
def sync_members_with_vhcs
AutomationService::EmployerMembersUpdate.new(self.pl_plan_key).call
AutomationService::EmployerMembersUpdate.new(pl_plan_key).call
end
def sync_plans_with_vhcs
AutomationService::EmployerPlansUpdate.new(pl_plan_key).call
end
def automation_identifier
attributes.with_indifferent_access.slice(
pl_plan_key.present? ? :pl_plan_key : :group_number
)
end
def sync_with_vhcs
AutomationService::EmployerUpdate.new(self.pl_plan_key).call
employer_identifier = automation_identifier
AutomationService::EmployerUpdate.new(employer_identifier).call
end
end