diff --git a/app/controllers/employers_controller.rb b/app/controllers/employers_controller.rb
index 05628a6..dcd4205 100644
--- a/app/controllers/employers_controller.rb
+++ b/app/controllers/employers_controller.rb
@@ -2,11 +2,8 @@ class EmployersController < ApplicationController
# View Methods
def index
- @not_automation_ready = Employer.not_automation_ready
- @missing_keychain_initialization = Employer.missing_keychain_initialization
- @missing_plans_initialization = Employer.missing_plans_initialization
- @missing_members_initialization = Employer.missing_members_initialization
- @active_with_active_id_card_setup = Employer.active_with_active_id_card_setup
+ @uninitialized = Employer.in_automation_initilization
+ @with_active_id_card_setup = Employer.with_active_id_card_setup
@deactivated = Employer.deactivated
end
diff --git a/app/jobs/update_employer_job.rb b/app/jobs/update_employer_job.rb
index b3b6b36..99f2866 100644
--- a/app/jobs/update_employer_job.rb
+++ b/app/jobs/update_employer_job.rb
@@ -5,6 +5,7 @@ class UpdateEmployerJob < ApplicationJob
if employer_plan_header.present?
pl_plan_key = employer_plan_header['PLPlanKey'].to_s
+ employer_identifier[:pl_plan_key] = pl_plan_key
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
diff --git a/app/models/concerns/employer_automation.rb b/app/models/concerns/employer_automation.rb
index 9ffffd5..0b78b39 100644
--- a/app/models/concerns/employer_automation.rb
+++ b/app/models/concerns/employer_automation.rb
@@ -2,34 +2,49 @@ module EmployerAutomation
extend ActiveSupport::Concern
included do
+
+ scope :uninitialized, -> {
+ where(initialized: false)
+ }
+
+ scope :initialized, -> {
+ where(initialized: true)
+ }
+
scope :not_automation_ready, -> {
- where(pl_plan_key: [nil, ''], group_number: [nil, ''])
+ where(group_number: [nil, ''])
}
scope :automation_ready, -> {
- where.not(pl_plan_key: [nil, ''])
- .or(where.not(group_number: [nil, '']))
+ 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 :in_automation_initilization, -> {
+ joins(:id_card_setup)
+ .where(initialized: false)
+ .or(
+ where(id_card_setup: {initialized: false})
+ )
}
+ # 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
+ uninitialized.automation_ready
}
- scope :building_id_card_setup, -> {
- active.left_outer_joins(:id_card_setup)
- .where(id_card_setup: {active: false})
+ scope :uninitialized_id_card_setup, -> {
+ joins(:id_card_setup)
+ .where(id_card_setup: {initialized: false})
}
- scope :missing_plans_initialization, -> {
- building_id_card_setup
- .where.missing(:plans)
+ scope :missing_plans, -> {
+ where.missing(:plans)
.or(
where(
id: joins(:plans)
@@ -39,9 +54,8 @@ module EmployerAutomation
)
}
- scope :missing_members_initialization, -> {
- building_id_card_setup
- .where.associated(:plans)
+ scope :has_plans, -> {
+ where.associated(:plans)
.where.not(
id: joins(:plans)
.where(plans: { pb_product_key: [nil, ''] })
@@ -49,22 +63,30 @@ module EmployerAutomation
).distinct
}
- scope :active_with_active_id_card_setup, -> {
+ scope :missing_plans_initialization, -> {
+ uninitialized_id_card_setup.missing_plans
+ }
+
+ scope :missing_members_initialization, -> {
+ uninitialized_id_card_setup.has_plans
+ }
+
+ scope :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 :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
+ inactive.initialized
}
# Employer.joins(:id_card_setup)
# .left_outer_joins(:plans)
diff --git a/app/models/employer.rb b/app/models/employer.rb
index 07cd295..68509ce 100644
--- a/app/models/employer.rb
+++ b/app/models/employer.rb
@@ -9,14 +9,17 @@ class Employer < ApplicationRecord
scope :inactive, -> { where(active: false) }
before_save :create_slug, if: :will_save_change_to_name?
- before_save :deactivation_check, if: :will_save_change_to_active?
+ before_save :active_initialized_check, if: :will_save_change_to_active?
def create_slug
self.slug = Employer.employer_trim_name(name).parameterize
end
- def deactivation_check
+ def active_initialized_check
+ if active
+ self.initialized = true
+ end
if active == false
id_card_setup&.update(active: false)
end
diff --git a/app/models/id_card/setup.rb b/app/models/id_card/setup.rb
index ebd27b3..e98de17 100644
--- a/app/models/id_card/setup.rb
+++ b/app/models/id_card/setup.rb
@@ -19,6 +19,14 @@ module IdCard
FORM_COLORS = ['atmosphere', 'verdigris', 'bluemana', 'cobalt']
MODULE_COLOR = 'atmosphere'
+ before_save :active_initialized_check, if: :will_save_change_to_active?
+
+ def active_initialized_check
+ if active
+ self.initialized = true
+ end
+ end
+
# def employer_logo_filename
# self.employer_logo.filename
# end
diff --git a/app/services/automation_service/batch_employer_update.rb b/app/services/automation_service/batch_employer_update.rb
index 4372a2b..5272dd4 100644
--- a/app/services/automation_service/batch_employer_update.rb
+++ b/app/services/automation_service/batch_employer_update.rb
@@ -1,13 +1,16 @@
module AutomationService
class BatchEmployerUpdate
- def initialize(pl_plan_keys)
+ def initialize(pl_plan_keys = nil)
@pl_plan_keys = pl_plan_keys
end
def call
sql_query = "SELECT PLPlanKey, PlanId, ShortDesc FROM PLPlanHeader
- WHERE ActiveInactive = 'Active' AND PLPlanKey IN (#{@pl_plan_keys.join(',')})"
+ WHERE ActiveInactive = 'Active'"
+ if @pl_plan_keys.present?
+ sql_query = sql_query.concat(" AND PLPlanKey IN (#{@pl_plan_keys.join(',')})")
+ end
employer_plan_headers = VhcsRecord.connection.select_all(sql_query)
employer_update_futures = employer_plan_headers.map do |employer_plan_header|
diff --git a/app/services/id_card_queue_service/get_queued_counts.rb b/app/services/id_card_queue_service/get_queued_counts.rb
index 389369f..7a40ff7 100644
--- a/app/services/id_card_queue_service/get_queued_counts.rb
+++ b/app/services/id_card_queue_service/get_queued_counts.rb
@@ -6,7 +6,20 @@ module IdCardQueueService
end
def call
- CallStoredProc.new('BrittonGetQueuedIdCardCountsTPA', { PLPlanKeys: @employer_pl_plan_keys }).call.to_ary
+ raw_employers_member_keys = CallStoredProc.new('HLGetQueuedIdCardMemberKeysTPA', { PLPlanKeys: @employer_pl_plan_keys }).call.to_ary
+
+ end
+
+ private
+
+ def format_employers_member_keys(raw_employers_member_keys)
+ key_map = { "PlanKey" => :pl_plan_key, "MemberKeys" => :member_keys }
+
+ raw_employers_member_keys.map do |hash|
+ hash["PlanKey"] = hash["PlanKey"].to_s
+ hash["MemberKeys"] = hash["MemberKeys"].split(", ").map(&:to_i)
+ hash.transform_keys(key_map)
+ end
end
end
diff --git a/app/views/employers/edit.html.erb b/app/views/employers/edit.html.erb
index bdef2b9..25024b9 100644
--- a/app/views/employers/edit.html.erb
+++ b/app/views/employers/edit.html.erb
@@ -9,18 +9,18 @@
<%= f.text_field :name, label: { text: "Employer Name" }, class: "w-full" %>
- <%= f.text_field :slug, label: { text: "Slug" }, class: "w-full" %>
+ <%= f.text_field :effective_date, label: { text: "Effective Date" }, class: "w-full" %>
- <%= f.text_field :pl_plan_key, label: { text: "Pl Plan Key" }, class: "w-full" %>
+ <%= f.text_field :group_number, label: { text: "Group/Medical Number" }, class: "w-full" %>
- <%= f.text_field :group_number, label: { text: "Group/Medical Number" }, class: "w-full" %>
+ <%= f.text_field :slug, label: { text: "Slug" }, class: "w-full" %>
- <%= f.text_field :effective_date, label: { text: "Effective Date" }, class: "w-full" %>
+ <%= f.text_field :pl_plan_key, label: { text: "Pl Plan Key" }, class: "w-full" %>
diff --git a/app/views/employers/index.html.erb b/app/views/employers/index.html.erb
index 58d8f40..a8fa8ff 100644
--- a/app/views/employers/index.html.erb
+++ b/app/views/employers/index.html.erb
@@ -1,89 +1,111 @@
-
+
Employers
- <%= link_to new_employer_path, class: "flex justify-center items-center h-8 w-8 ml-2 mb-6 text-sm text-bronze bg-deepcove hover:bg-cobalt font-semibold p-1 -l border-2 border-cobalt" do %>
- <%= icon "clipboard-plus", library: "lucide" %>
- <% end %>
+
+
+ <%= link_to "NEW", new_employer_path %>
+
+
- <% if @not_automation_ready.present? || @missing_keychain_initialization.present? || @missing_plans_initialization.present? || @missing_members_initialization.present? %>
+ <% if @uninitialized.present? %>
In Process:
- <% no_employers_text = @not_automation_ready.present? ? "" : " NONE" %>
-
- <%= "Waiting for Groups Number/Pl Plan Key:#{no_employers_text}" %>
-
-
- <% @not_automation_ready.each_with_index do |emp, index| %>
-
-
- <%= link_to emp.name, employer_path(emp.slug), class: "text-bronze hover:text-platinum" %>
-
-
- <%= "(Effective #{emp.effective_date})" %>
-
-
- <% end %>
-
- <% no_employers_text = @missing_keychain_initialization.present? ? "" : " NONE" %>
-
- <%= "Waiting for Employer to be created in VHCS:#{no_employers_text}" %>
-
-
- <% @missing_keychain_initialization.each_with_index do |emp, index| %>
-
-
- <%= link_to emp.name, employer_path(emp.slug), class: "text-verdigris-vivid hover:text-platinum" %>
-
-
- <%= "(Effective #{emp.effective_date})" %>
-
-
- <% end %>
-
- <% no_employers_text = @missing_plans_initialization.present? ? "" : " NONE" %>
-
- <%= "Waiting for Plans to be created in VHCS:#{no_employers_text}" %>
-
-
- <% @missing_plans_initialization.each_with_index do |emp, index| %>
-
-
- <%= link_to emp.name, employer_path(emp.slug), class: "text-copper hover:text-platinum" %>
-
-
- <%= "(Effective #{emp.effective_date})" %>
-
-
- <% end %>
-
- <% no_employers_text = @missing_members_initialization.present? ? "" : " NONE" %>
-
- <%= "Waiting for Inital Members to be created in VHCS:#{no_employers_text}" %>
-
-
- <% @missing_members_initialization.each_with_index do |emp, index| %>
-
-
- <%= link_to emp.name, employer_path(emp.slug), class: "text-bluemana hover:text-platinum" %>
-
-
- <% member_counter_color = "text-".concat(emp.members.present? ? "limegreen" : "brightlava") %>
-
- Members:
-
- <%= emp.members.count %>
-
+
+
+ <%= "Waiting for Groups Number Entry" %>
+
+ <% if @uninitialized.not_automation_ready.present? %>
+
+ <% @uninitialized.not_automation_ready.each do |emp| %>
+
+
+ <%= link_to emp.name, employer_path(emp.slug), class: "text-bronze hover:text-platinum" %>
+
+
+ <%= "(Effective #{emp.effective_date})" %>
+
-
- <%= "(Effective #{emp.effective_date})" %>
-
-
+ <% end %>
+ <% else %>
+
+ <% end %>
+
+
+
+ <%= "Waiting for Employer to be created in VHCS" %>
+
+ <% if @uninitialized.missing_keychain_initialization.present? %>
+
+ <% @uninitialized.missing_keychain_initialization.each do |emp| %>
+
+
+ <%= link_to emp.name, employer_path(emp.slug), class: "text-verdigris-vivid hover:text-platinum" %>
+
+
+ <%= "(Effective #{emp.effective_date})" %>
+
+
+ <% end %>
+
+ <% else %>
+
+ <% end %>
+
+
+
+ <%= "Waiting for Plans to be created in VHCS" %>
+
+ <% if @uninitialized.missing_plans_initialization.present? %>
+
+ <% @uninitialized.missing_plans_initialization.each do |emp| %>
+
+
+ <%= link_to emp.name, employer_path(emp.slug), class: "text-copper hover:text-platinum" %>
+
+
+ <%= "(Effective #{emp.effective_date})" %>
+
+
+ <% end %>
+
+ <% else %>
+
+ <% end %>
+
+
+
+ <%= "Waiting for Inital Members to be created in VHCS" %>
+
+ <% if @uninitialized.missing_members_initialization.present? %>
+
+ <% @uninitialized.missing_members_initialization.each do |emp| %>
+
+
+ <%= link_to emp.name, employer_path(emp.slug), class: "text-bluemana hover:text-platinum" %>
+
+
+ <% member_counter_color = "text-".concat(emp.members.present? ? "limegreen" : "brightlava") %>
+
+ Members:
+
+ <%= emp.members.count %>
+
+
+
+ <%= "(Effective #{emp.effective_date})" %>
+
+
+
+ <% end %>
+
+ <% else %>
+
<% end %>
<% end %>
Live:
- <% @active_with_active_id_card_setup.order(:name).each_with_index do |emp, index| %>
+ <% @with_active_id_card_setup.order(:name).each do |emp| %>
<%= link_to emp.name, employer_path(emp.slug), class: "text-atmosphere hover:text-platinum" %>
@@ -101,7 +123,7 @@
Deactivated:
- <% @deactivated.each_with_index do |emp, index| %>
+ <% @deactivated.each do |emp| %>
<%= link_to emp.name, employer_path(emp.slug), class: "text-platinum hover:text-bluemana" %>
diff --git a/app/views/employers/new.html.erb b/app/views/employers/new.html.erb
index 6c75634..3412795 100644
--- a/app/views/employers/new.html.erb
+++ b/app/views/employers/new.html.erb
@@ -19,14 +19,12 @@
<%= f.text_field :name, label: { text: "Employer Name" }, data: { logo_upload_target: "employer" }, class: "w-full" %>
-
- <%= f.text_field :group_number, label: { text: "Group/Medical Number" }, class: "w-full" %>
-
-
-
<%= f.text_field :effective_date, label: { text: "Effective Date" }, class: "w-full" %>
+
+ <%= f.text_field :group_number, label: { text: "Group/Medical Number" }, class: "w-full" %>
+
diff --git a/bin/cron-entrypoint b/bin/cron-entrypoint
new file mode 100644
index 0000000..636f87b
--- /dev/null
+++ b/bin/cron-entrypoint
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+set -e
+
+printenv >> /etc/environment
+
+echo "updating cron..."
+bundle exec whenever --update-crontab --set environment=development
+
+# Start cron in foreground
+echo "starting cron..."
+cron
+# bundle exec whenever --update-crontab
+
+# Then exec the container's main process (what's set as CMD in the Dockerfile).
+exec "$@"
diff --git a/bin/development-entrypoint b/bin/development-entrypoint
new file mode 100644
index 0000000..b119093
--- /dev/null
+++ b/bin/development-entrypoint
@@ -0,0 +1,13 @@
+#!/bin/bash
+set -e
+
+# Remove a potentially pre-existing server.pid for Rails.
+rm -f /usr/src/app/tmp/pids/server.pid
+
+rm -rf /usr/local/bundle/cache/*.gem
+
+echo "bundle install..."
+bundle check || bundle install --jobs 4
+
+# Then exec the container's main process (what's set as CMD in the Dockerfile).
+exec "$@"
diff --git a/compose.yaml b/compose.yaml
index 895c7bd..8c31183 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -15,15 +15,13 @@ services:
- HISTFILE=/usr/src/app/log/.bash_history
- RAILS_ENV=development
- TAILWIND_POLLING=true
- - PUID=1000
- - PGID=100
+ # - PUID=1000
+ # - PGID=100
tty: true
stdin_open: true
# depends_on:
# db:
# condition: service_healthy
- # redis:
- # condition: service_started
# db:
# build:
# context: .
@@ -38,11 +36,21 @@ services:
# timeout: 3s
# retries: 10
# start_period: 10s
- # redis:
- # image: redis
+ # cron:
+ # build:
+ # context: ./
+ # dockerfile: development3.Dockerfile
+ # command: ./bin/cron-entrypoint
# volumes:
- # - redis_data:/data
-
+ # - .:/usr/src/app
+ # - bundle:/usr/local/bundle
+ # environment:
+ # - RAILS_ENV=development
+ # - PUID=1000
+ # - PGID=1001
+ # depends_on:
+ # - web
+ # - db
volumes:
# redis_data:
bundle:
diff --git a/config/schedule.rb b/config/schedule.rb
index 3320295..9151c1c 100644
--- a/config/schedule.rb
+++ b/config/schedule.rb
@@ -2,8 +2,7 @@ set :output, "log/cron_log.log"
set :environment, ENV['RAILS_ENV'] || 'development'
every 1.minute do
- runner "Rails.logger.info 'Cron test ran at: ' + Time.now.to_s"
- command "echo 'Cron test ran at: ' $(date) >> log/cron_log.log"
+ rake "employer_automation:employer_initialize_test"
end
every 1.day, at: ['6:00 am', '6:00 pm'] do
diff --git a/db/migrate/20251202140122_create_employers.rb b/db/migrate/20251202140122_create_employers.rb
index 8ca7245..6e05906 100644
--- a/db/migrate/20251202140122_create_employers.rb
+++ b/db/migrate/20251202140122_create_employers.rb
@@ -9,6 +9,7 @@ class CreateEmployers < ActiveRecord::Migration[7.2]
t.string :group_number
t.string :effective_date
t.boolean :active, default: false
+ t.boolean :initialized, default: false
t.timestamps
end
diff --git a/db/migrate/20251204041154_create_id_card_setups.rb b/db/migrate/20251204041154_create_id_card_setups.rb
index b0b69b1..c2303f5 100644
--- a/db/migrate/20251204041154_create_id_card_setups.rb
+++ b/db/migrate/20251204041154_create_id_card_setups.rb
@@ -7,9 +7,10 @@ class CreateIdCardSetups < ActiveRecord::Migration[7.2]
t.string :card_color
t.string :rx_group_number
t.string :pl_plan_key
- t.boolean :active, default: false
t.boolean :has_divisions, default: false
t.boolean :has_dental, default: false
+ t.boolean :active, default: false
+ t.boolean :initialized, default: false
t.belongs_to :employer, null: false, foreign_key: true
t.belongs_to :employer_logo, null: true, foreign_key: { to_table: :id_card_employer_logos }
t.belongs_to :network_logo, null: true, foreign_key: { to_table: :id_card_network_logos }
diff --git a/db/schema.rb b/db/schema.rb
index afa3a56..d376124 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -20,6 +20,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_04_08_210447) do
t.string "group_number"
t.string "effective_date"
t.boolean "active", default: false
+ t.boolean "initialized", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
@@ -239,9 +240,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_04_08_210447) do
t.string "card_color"
t.string "rx_group_number"
t.string "pl_plan_key"
- t.boolean "active", default: false
t.boolean "has_divisions", default: false
t.boolean "has_dental", default: false
+ t.boolean "active", default: false
+ t.boolean "initialized", default: false
t.bigint "employer_id", null: false
t.bigint "employer_logo_id"
t.bigint "network_logo_id"
diff --git a/db/seeds.rb b/db/seeds.rb
index 5885744..50ddb04 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -15,6 +15,7 @@
"seed_tasks:determine_network_fields",
"seed_tasks:determine_employer_fields",
+ "seed_tasks:build_plans",
"seed_tasks:build_members"
]
diff --git a/development3.Dockerfile b/development3.Dockerfile
index f5f03b4..758a2dd 100644
--- a/development3.Dockerfile
+++ b/development3.Dockerfile
@@ -13,6 +13,8 @@ RUN --mount=type=cache,target=/var/cache/apt \
build-essential \
less \
git \
+ cron \
+ dos2unix \
tdsodbc \
freetds-dev \
libvips \
@@ -27,34 +29,16 @@ WORKDIR /usr/src/app
RUN gem install foreman
-# RUN chmod +x /usr/src/app/bin/jobs
+# COPY bin/development-entrypoint.sh /bin/development-entrypoint.sh
+# RUN chown root:root bin/development-entrypoint.sh && chmod +x bin/development-entrypoint.sh
-# Copy runtime Ruby dependencies and the precompiled assets from the builder stage
-# COPY --from=builder /usr/local/bundle /usr/local/bundle
-# COPY --from=builder /usr/src/app /usr/src/app
-# COPY --from=watchman_builder /usr/local/bin/watchman /usr/local/bin/watchman
-# COPY --from=watchman_builder /usr/local/bin/watchman-wait /usr/local/bin/watchman-wait
+ENTRYPOINT ["./bin/development-entrypoint"]
-# RUN mkdir -p /usr/local/var/run/watchman \
-# && touch /usr/local/var/run/watchman/.not-empty \
-# && chmod 2777 /usr/local/var/run/watchman
+ENTRYPOINT ["./bin/cron-entrypoint"]
-# COPY . .
-
-# 1. Add bin/jobs script to container
-COPY bin/jobs /usr/src/bin/jobs
-
-# 2. Make the script executable
-RUN chmod +x /usr/src/bin/jobs
-
-# 3. Set it as the entrypoint
-# ENTRYPOINT ["/usr/src/bin/jobs"]
-
-# The entrypoint script is a good practice for handling Rails server startup
-ENTRYPOINT ["./bin/docker-entrypoint-development"]
# Expose the application port
EXPOSE 3002
# Set the default command to run the Rails server
-CMD ["./bin/dev", "bin/jobs start"]
+CMD ["./bin/dev", "./bin/jobs start"]
diff --git a/lib/tasks/employer_automation.rake b/lib/tasks/employer_automation.rake
index 90d11d5..29a5741 100644
--- a/lib/tasks/employer_automation.rake
+++ b/lib/tasks/employer_automation.rake
@@ -3,9 +3,10 @@ namespace :employer_automation do
desc "Employer Initialization Automation"
# rake employer_automation:employer_initialize
task employer_initialize: :environment do
+ puts "Running Employer Init Automation"
Employer.missing_keychain_initialization.map(&:sync_with_vhcs)
Employer.missing_plans_initialization.map(&:sync_plans_with_vhcs)
- Employer.missing_initial_members.map(&:sync_members_with_vhcs)
+ Employer.missing_members_initialization.map(&:sync_members_with_vhcs)
end
desc "Employer Initialization Automation Test"
@@ -26,8 +27,8 @@ namespace :employer_automation do
# rake employer_automation:employer_maintenance
task employer_maintenance: :environment do
Employer.automation_ready.map(&:sync_with_vhcs)
- Employer.active.map(&:sync_plans_with_vhcs)
- Employer.active.map(&:sync_members_with_vhcs)
+ Employer.with_active_id_card_setup.map(&:sync_plans_with_vhcs)
+ Employer.with_active_id_card_setup.map(&:sync_members_with_vhcs)
end
end
diff --git a/lib/tasks/seed_tasks.rake b/lib/tasks/seed_tasks.rake
index 393e0a3..192acce 100644
--- a/lib/tasks/seed_tasks.rake
+++ b/lib/tasks/seed_tasks.rake
@@ -184,35 +184,44 @@ namespace :seed_tasks do
plan_headers = VhcsRecord.connection.select_all(sql_query)
plan_headers.each do |plan_header|
- employer = UpdateEmployerJob.perform_now(employer_plan_header: plan_header, full_sync: true)
+ UpdateEmployerJob.new.perform(employer_plan_header: plan_header, full_sync: true)
+ end
+
+ end
+
+ desc "Build Initial Plans"
+ # rake seed_tasks:build_plans
+ task build_plans: :environment do
+ puts "Importing Plans"
+
+ Employer.all.each do |employer|
puts "-- #{employer.name}"
UpdateEmployerPlansJob.new.perform(employer.pl_plan_key)
# employer_plans = employer.id_card_setup.plans
- vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: employer.company_pb_entity_key, is_active: 255)
- vhcs_plans.each do |vp|
- # plan = employer_plans.find_by(pb_product_key: vp.pb_product_key)
- # if plan.present?
- # plan_titles = employer_plans.pluck(:title)
- # plan_title_matcher = JaroWinkler.new(vp.short_description)
- # closest_title = plan_titles.max_by { |title| plan_title_matcher.match(title) }
- # plan = employer_plans.find_by(title: closest_title)
- # plan.update(pb_product_key: vp.pb_product_key)
- # end
- plan = employer.id_card_setup.plans.find_by(pb_product_key: vp.pb_product_key)
+
+ employer.id_card_setup.plans.each do |plan|
puts "---- #{plan.title}"
- # plan.update(
- # title: vp.short_description,
- # pl_plan_key: employer.pl_plan_key
- # )
vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: plan.pb_product_key)
- vhcs_plan_benefits.each do |vb|
- benefit = plan.plan_benefits.find_by(sequence: vb.sequence)
- benefit.update(benefit: vb.benefit)
+ vhcs_plan_benefits.each do |vpb|
+ if vpb.benefit.present?
+ benefit = plan.plan_benefits.find_by(sequence: vpb.sequence)
+ benefit.update(benefit: vpb.benefit)
+ end
end
end
- if vhcs_plans.empty?
- employer.active = false
- end
+ # vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: employer.company_pb_entity_key, is_active: 255)
+ # vhcs_plans.each do |vp|
+ # plan = employer.id_card_setup.plans.find_by(pb_product_key: vp.pb_product_key)
+ # puts "---- #{plan.title}"
+ # vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: plan.pb_product_key)
+ # vhcs_plan_benefits.each do |vb|
+ # benefit = plan.plan_benefits.find_by(sequence: vb.sequence)
+ # benefit.update(benefit: vb.benefit)
+ # end
+ # end
+ # if vhcs_plans.empty?
+ # employer.active = false
+ # end
employer.save
end
@@ -223,8 +232,7 @@ namespace :seed_tasks do
task build_members: :environment do
puts "Importing Members"
Employer.all.map(&:sync_members_with_vhcs)
- Employer.left_outer_joins(:members)
- .where(members: { id: nil })
+ Employer.where.missing(:members)
.update_all(active: false)
end