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
+7 -38
View File
@@ -3,54 +3,23 @@ class Employer < ApplicationRecord
has_many :members, dependent: :destroy
accepts_nested_attributes_for :members, allow_destroy: true, reject_if: :all_blank
has_one :id_card_setup, class_name: 'IdCard::Setup', dependent: :destroy
has_many :plans, class_name: 'IdCard::Plan', through: :id_card_setup
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
# before_save :process_employer_logo
# before_save :process_employer_logo, if: :employer_logo_filename_changed?
# before_save :create_slug, if: :new_record?
before_save :create_slug, if: :will_save_change_to_name?
# before_save :set_active_status, unless: :will_save_change_to_active?
# after_save :process_employer_logo, if: :saved_change_to_employer_logo_filename?
before_save :deactivation_check, if: :will_save_change_to_active?
# def process_employer_logo
# # if self.employer_logo.present? && !self.employer_logo.is_a?(String)
# # self.card_logo_files.new(
# # filename: self.employer_logo.filename,
# # logo_type: 'employer',
# # image: self.employer_logo.data,
# # pl_plan_key: self.pl_plan_key || ""
# # )
# # end
# if self.employer_logo_filename.present? && self.employer_logo_filename.is_a?(String)
# image_file = CardLogoFile.find_by(filename: self.employer_logo_filename)
# if image_file.present?
# if self.employer_brand_logo.present?
# self.employer_brand_logo.update(card_logo_file: image_file)
# else
# self.create_employer_brand_logo(card_logo_file: image_file, logo_type: 'employer')
# end
# end
# end
# end
def create_slug
self.slug = Employer.employer_trim_name(self.name).parameterize
self.slug = Employer.employer_trim_name(name).parameterize
end
def set_active_status
self.active = (
self.pl_plan_key.present? &&
self.company_pb_entity_key.present? &&
self.plan_id.present? &&
self.group_number.present? &&
self.effective_date.present?
)
def deactivation_check
if active == false
id_card_setup&.update(active: false)
end
end
def id_card_enabled?
+15 -16
View File
@@ -6,26 +6,25 @@ module IdCard
scope :templates, -> { where(template: true) }
BENEFIT_FIELDS = ["Primary Visit",
"Specialist Visit",
"Urgent Care",
"INN-Ind Ded",
"INN-Family Ded",
"OON-Ind Ded",
"OON-Family Ded",
"Co-Insurance",
"INN-Ind OOP",
"INN-Family OOP",
"OON-Ind OOP",
"OON-Family OOP",
"Emergency Room",
"Preventive Care"].freeze
FARIOS_BENEFIT_FIELDS = ["Primary Visit", "Specialist Visit", "Urgent Care", "INN-Ind Ded", "INN-Family Ded", "OON-Ind Ded", "OON-Family Ded", "Co-Insurance", "INN-Ind OOP", "INN-Family OOP", "OON-Ind OOP", "OON-Family OOP", "Emergency Room", "Preventive Care"].freeze
TANDEMLOC_BENEFIT_FIELDS = ["Physician Visit", "Specialist Visit", "Urgent Care", "Deductible", "Co-Insurance", "Out-of-Pocket", "Emergency Room", "Preventive Care"].freeze
SMART_BENEFIT_FIELDS = [].freeze
after_initialize :build_plan_benefits, if: :new_record?
def build_plan_benefits
BENEFIT_FIELDS.each_with_index do |bene, i|
self.plan_benefits.build(benefit_desc: bene, sequence: (i + 1))
if plan_benefits.empty?
plan_benefit_fields = case setup&.card_template
when "TandemlocIDCard"
TANDEMLOC_BENEFIT_FIELDS
when "SmartIDCard"
SMART_BENEFIT_FIELDS
else
FARIOS_BENEFIT_FIELDS
end
plan_benefit_fields.each_with_index do |bene, i|
self.plan_benefits.build(benefit_desc: bene, sequence: (i + 1))
end
end
end
+43
View File
@@ -0,0 +1,43 @@
module Vhcs
class PbOrgUnit < VhcsRecord
self.table_name = 'PBOrgUnit'
alias_attribute :pb_entity_key, :PBEntityKey
alias_attribute :web_site, :WebSite
alias_attribute :federal_tax_id, :FederalTaxID
alias_attribute :duns_number, :DunsNumber
alias_attribute :company_number, :CompanyNumber
alias_attribute :company_location, :CompanyLocation
alias_attribute :division, :Division
alias_attribute :policy_number, :PolicyNumber
alias_attribute :when_last_changed, :WhenLastChanged
alias_attribute :who_last_changed, :WhoLastChanged
alias_attribute :mmsea_employer_size_g_1_1_5, :MMSEAEmployerSize_G115
alias_attribute :wait_period_delay_type_g_1_0_7, :WaitPeriodDelayType_G107
alias_attribute :wait_period, :WaitPeriod
alias_attribute :wait_period_unit_g_1_0_6, :WaitPeriodUnit_G106
def attributes
rails_like = {
pb_entity_key: self.pb_entity_key,
web_site: self.web_site,
federal_tax_id: self.federal_tax_id,
duns_number: self.duns_number,
company_number: self.company_number,
company_location: self.company_location,
division: self.division,
policy_number: self.policy_number,
when_last_changed: self.when_last_changed,
who_last_changed: self.who_last_changed,
mmsea_employer_size_g_1_1_5: self.mmsea_employer_size_g_1_1_5,
wait_period_delay_type_g_1_0_7: self.wait_period_delay_type_g_1_0_7,
wait_period: self.wait_period,
wait_period_unit_g_1_0_6: self.wait_period_unit_g_1_0_6,
}
super.merge(rails_like)
end
end
end
+23
View File
@@ -0,0 +1,23 @@
module Vhcs
class PlPlanGroupCode < VhcsRecord
self.table_name = 'PLPlanGroupCode'
alias_attribute :group_code, :GroupCode
alias_attribute :pl_plan_key, :PLPlanKey
alias_attribute :pl_cov_type_hdr_key, :PLCovTypeHdrKey
alias_attribute :group_code_desc, :GroupCodeDesc
def attributes
rails_like = {
group_code: self.group_code,
pl_plan_key: self.pl_plan_key,
pl_cov_type_hdr_key: self.pl_cov_type_hdr_key,
group_code_desc: self.group_code_desc,
}
super.merge(rails_like)
end
end
end