working on data printer

This commit is contained in:
Jason Jordan
2026-03-16 12:09:45 -04:00
parent 8c885b3e76
commit 011ee91707
26 changed files with 357 additions and 214 deletions
@@ -6,9 +6,9 @@ module IdCard
def edit
@employer = Employer.find_by(slug: params[:employer_id])
if @employer.id_card_enabled?
@setup = @employer.id_card_setup
@setup = @employer.id_card_configuration
else
@setup = @employer.create_id_card_setup
@setup = @employer.create_id_card_configuration
end
render :edit
end
@@ -39,10 +39,10 @@ module IdCard
end
def update_general
if params[:id_card_setup]["provider_section_id"].include?("new|")
if params[:id_card_configuration]["provider_section_id"].include?("new|")
new_provider_section_params = IdCard::ProviderSection.permitted_params(params)
new_provider_section = IdCard::ProviderSection.create(new_provider_section_params)
params[:id_card_setup]["provider_section_id"] = new_provider_section.id
params[:id_card_configuration]["provider_section_id"] = new_provider_section.id
end
general_params = IdCard::Configuration.permitted_params(params)
if @setup.update(general_params)
@@ -99,10 +99,10 @@ module IdCard
def set_employer_and_setup
@employer = Employer.find_by(slug: params[:employer_id])
if @employer.id_card_setup.present?
@setup = @employer.id_card_setup
if @employer.id_card_configuration.present?
@setup = @employer.id_card_configuration
else
@setup = @employer.create_id_card_setup
@setup = @employer.create_id_card_configuration
end
end
@@ -10,11 +10,16 @@ module IdCard
# API Methods
def print_queued
@queue_counts = EmployerCards::GetQueuedCards.new().call
end
private
def add_queued_count_to_card_configuration
@queue_counts = EmployerCards::QueueCounter.new().call
@queue_counts = EmployerCards::GetQueuedCounts.new().call
@queue_counts.each do |qc|
match = @employer_configurations.find { |configuration| configuration.pl_plan_key == qc["PLPlanKey"] }
if match.present?
@@ -0,0 +1,17 @@
module EmployerCards
class GetQueuedCards
def initialize(pl_plan_keys)
if pl_plan_keys
@employer_pl_plan_keys = pl_plan_keys
else
@employer_pl_plan_keys = IdCard::Configuration.active.pluck(:pl_plan_key).join(',')
end
end
def call
CallStoredProc.new('BrittonGetQueuedIdCardMemberKeysTPA', { PLPlanKeys: @employer_pl_plan_keys }).call.to_ary
end
end
end
@@ -1,12 +1,12 @@
module EmployerCards
class QueueCounter
class GetQueuedCounts
def initialize()
@employer_pl_plan_keys = IdCard::Configuration.active.pluck(:pl_plan_key).join(',')
end
def call
CallStoredProc.new('HLGetQueuedIdCardsTPANewCount', { PLPlanKeys: @employer_pl_plan_keys }).call.to_ary
CallStoredProc.new('BrittonGetQueuedIdCardCountsTPA', { PLPlanKeys: @employer_pl_plan_keys }).call.to_ary
end
end
@@ -1,10 +1,11 @@
module EmployerCards
class JasperUrlGenerator
def initialize(employer, family_id, layout)
def initialize(pl_plan_key, family_id, layout)
@pl_plan_key = pl_plan_key
@family_id = family_id
@employer = employer
@layout = layout
@card_config = IdCard::Configuration.find_by(pl_plan_key: pl_plan_key)
end
def call
@@ -0,0 +1,93 @@
module IdCardPrinter
class DataFormatter
def initialize(employer)
@employer = employer
end
def call
@sample_card = SampleIdCard.new()
set_employer_fields()
set_generic_fields()
set_rx_fields()
set_network_fields()
# set_dependent_fields()
sample_cards = set_plan_fields()
sample_cards.each(&:save!)
end
private
def set_employer_fields
selected_attributes = {
employer_name: @employer.name,
group_number: @employer.group_number.present? ? @employer.group_number : "999999",
medical_eff_date: @employer.effective_date
}
@sample_card.assign_attributes(selected_attributes)
end
def set_plan_fields
plans_sample_cards = []
@employer.id_card_configuration.plans.each do |plan|
plan_sample_card = @sample_card.dup
plan_name = plan.title.split(/(?<=\d[kK])/).first
plan_sample_card.family_id = plan_name
plan.plan_benefits.each do |bene|
plan_sample_card["benefit_desc_#{bene.sequence}".to_sym] = bene.benefit_desc
plan_sample_card["benefit_#{bene.sequence}".to_sym] = bene.benefit
end
plans_sample_cards.push(plan_sample_card)
end
plans_sample_cards
end
def set_generic_fields
selected_attributes = {
full_name: "JANE DOE",
primary_mb_member_key: "888888",
rx_group: @employer.group_number.present? ? @employer.group_number : "999999"
}
@sample_card.assign_attributes(selected_attributes)
end
def set_network_fields
selected_attributes = @employer.id_card_configuration.provider_section.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
)
if @employer.network_provider == "Cigna"
@sample_card.provider_code = "5"
end
@sample_card.assign_attributes(selected_attributes)
end
def set_rx_fields
# fairos_information = Vhcs::HlrxCrosRef.where(pl_plan_key: 52).first
selected_attributes = @employer.id_card_configuration.rx_section.attributes.with_indifferent_access.slice(
:customer_service,
:web_url
)
@sample_card.assign_attributes(selected_attributes)
end
def set_dependent_fields
@sample_card.dependent_1 = "John Doe"
@sample_card.dependent_2 = "Molly Doe"
@sample_card.dependent_3 = "Jonathan Doe"
@sample_card.dependent_4 = "Calvin Doe"
@sample_card.dependent_5 = "Richard Doe"
@sample_card.dependent_6 = "Jannet Doe"
@sample_card.dependent_7 = "Longername Doe"
@sample_card.dependent_8 = "Robbert Doe"
end
end
end
@@ -0,0 +1,17 @@
module IdCardPrinter
class EmployerCardsGenerator
def initialize(pl_plan_key, layout, zip=false)
@pl_plan_key = pl_plan_key
@layout = layout
@zip = zip
end
def call
IdCard::PrintData.where(pl_plan_key: @pl_plan_key).destroy_all
EmployerCards::DataFormatter.new(@pl_plan_key).call
IdCardPrinter::PdfProcessor.new(@pl_plan_key, @layout, @zip).call
end
end
end
@@ -0,0 +1,17 @@
module IdCardPrinter
class JasperPdfGenerator
def initialize(jasper_url)
@jasper_url = jasper_url
end
def call
response = HTTParty.get(@jasper_url)
CombinePDF.parse(response.body)
end
end
end
@@ -0,0 +1,41 @@
module IdCardPrinter
class JasperUrlGenerator
def initialize(pl_plan_key, family_id, layout)
@pl_plan_key = pl_plan_key
@family_id = family_id
@layout = layout
@card_config = IdCard::Configuration.find_by(pl_plan_key: pl_plan_key)
end
def call
URI::HTTP.build(url_components)
end
private
def determine_network_logo
# if @network_logos.length > 1
# member_geographic_info = Vhcs::PbEntityAddress.joins("INNER JOIN vwMBMember ON PBEntityAddress.PBEntityKey = vwMBMember.PBEntityKey AND PBEntityAddress.AddressTypeID = 1137").where("vwMBMember.FamilyID = ?", @family_id).first
# @network_logos.where.not(default: true).each do |pnl|
# if member_geographic_info[pnl.exception_type] == pnl.exception_value
# return pnl.net_logo
# end
# end
# end
# @network_logos.find_by(default: true).net_logo
@card_config.network_logo.filename
end
# http://localhost:8080/trunk/PdfServlet?reportConn=BrittonConnect&id=&reportName=FairosRxSampleIDCard-Half&family_id=Classic%202K&employer_logo=BryanPestControl.jpeg&network_logo=CignaLogo.png&reportDir=secure/Documents&SUBREPORT_DIR=/&ImageDir=secure/Documents&netToken=3a4a8b03f4dfb0e6e3fc82dd369f70ef&FileType=PDF
# http://localhost:8080/trunk/PdfServlet?reportConn=BrittonConnect&id=&reportName=FairosRxSampleIDCard-Half&family_id=Classic%202K&employer_logo=BryanPestControl.jpeg&network_logo=CignaLogo.png&reportDir=secure/Documents&SUBREPORT_DIR=/&ImageDir=secure/Documents&netToken=3a4a8b03f4dfb0e6e3fc82dd369f70ef&FileType=PDF
def url_components
{
host: '10.41.1.115',
port: 8080,
path: '/trunk/IdCardsServlet',
query: "reportConn=BrittonConnect&cardTemplate=#{@card_config.card_template}&printType=#{@layout}&family_id=#{@family_id }&employer_logo=#{@card_config.employer_logo.filename}&network_logo=#{determine_network_logo}&FileType=PDF"
}
end
end
end
@@ -0,0 +1,40 @@
module IdCardPrinter
class PdfProcessor
def initialize(pl_plan_key, layout, zip)
@pl_plan_key = pl_plan_key
@employer_card_config = Employer.find_by(pl_plan_key: pl_plan_key).id_card_configuration
@layout = layout
@zip = zip
end
def call
group_cards_pdf_array = []
IdCard::PrintData.where(pl_plan_key: @pl_plan_key).each do |card|
url = IdCardPrinter::JasperUrlGenerator.new(@pl_plan_key, card.family_id, @layout).call
puts url
card_pdf = IdCardPrinter::JasperPdfGenerator.new(url).call
if @zip
card_filename = "#{card.name.gsub(", ", "_")}_digital_card_#{Date.today}.pdf"
group_cards_pdf_array << { name: card_filename, data: card_pdf.to_pdf }
else
group_cards_pdf_array << card_pdf
end
end
if @zip
group_cards_pdf = Zip::OutputStream.write_buffer do |zio|
group_cards_pdf_array.each do |file|
zio.put_next_entry(file[:name])
zio.write(file[:data])
end
end
else
todays_date = DateTime.current.strftime('%Y%m%d%H%M%S')
group_cards_pdf.save("tmp/#{@employer.name}_print_cards_#{todays_date}.pdf")
end
group_cards_pdf
end
end
end
+1 -1
View File
@@ -13,7 +13,7 @@
<%= es.pl_plan_key %> -
<%= es.employer.name %>
(
<div class="mx-1 text-<%= es.queued_card_count > 0 ? "brightlava" : "limegreen" %>">
<div class="mx-1 text-<%= es.queued_card_count > 0 ? "bronze" : "bluetang" %>">
<%= es.queued_card_count %>
</div>
)
+1 -1
View File
@@ -29,7 +29,7 @@ Rails.application.routes.draw do
post 'import'
end
namespace :id_card do
resources :setup, only: [:destroy] do
resources :configuration, only: [:destroy] do
collection do
get 'general'
patch 'update_general'
+32 -32
View File
@@ -24,6 +24,27 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_16_182836) do
t.datetime "updated_at", null: false
end
create_table "id_card_configurations", force: :cascade do |t|
t.string "print_name"
t.string "network_provider"
t.string "card_template"
t.string "rx_group_number"
t.string "pl_plan_key"
t.boolean "active", default: false
t.bigint "employer_id", null: false
t.bigint "employer_logo_id"
t.bigint "network_logo_id"
t.bigint "provider_section_id"
t.bigint "rx_section_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["employer_id"], name: "index_id_card_configurations_on_employer_id"
t.index ["employer_logo_id"], name: "index_id_card_configurations_on_employer_logo_id"
t.index ["network_logo_id"], name: "index_id_card_configurations_on_network_logo_id"
t.index ["provider_section_id"], name: "index_id_card_configurations_on_provider_section_id"
t.index ["rx_section_id"], name: "index_id_card_configurations_on_rx_section_id"
end
create_table "id_card_employer_logos", force: :cascade do |t|
t.string "filename"
t.binary "image_data"
@@ -50,10 +71,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_16_182836) do
create_table "id_card_field_exceptions", force: :cascade do |t|
t.string "exception_type"
t.string "exception_value"
t.bigint "setup_id", null: false
t.bigint "configuration_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["setup_id"], name: "index_id_card_field_exceptions_on_setup_id"
t.index ["configuration_id"], name: "index_id_card_field_exceptions_on_configuration_id"
end
create_table "id_card_network_logos", force: :cascade do |t|
@@ -82,10 +103,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_16_182836) do
t.integer "pb_product_key"
t.string "pl_plan_key"
t.boolean "template"
t.bigint "setup_id"
t.bigint "configuration_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["setup_id"], name: "index_id_card_plans_on_setup_id"
t.index ["configuration_id"], name: "index_id_card_plans_on_configuration_id"
end
create_table "id_card_print_data", force: :cascade do |t|
@@ -223,27 +244,6 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_16_182836) do
t.datetime "updated_at", null: false
end
create_table "id_card_setups", force: :cascade do |t|
t.string "print_name"
t.string "network_provider"
t.string "card_template"
t.string "rx_group_number"
t.string "pl_plan_key"
t.boolean "active", default: false
t.bigint "employer_id", null: false
t.bigint "employer_logo_id"
t.bigint "network_logo_id"
t.bigint "provider_section_id"
t.bigint "rx_section_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["employer_id"], name: "index_id_card_setups_on_employer_id"
t.index ["employer_logo_id"], name: "index_id_card_setups_on_employer_logo_id"
t.index ["network_logo_id"], name: "index_id_card_setups_on_network_logo_id"
t.index ["provider_section_id"], name: "index_id_card_setups_on_provider_section_id"
t.index ["rx_section_id"], name: "index_id_card_setups_on_rx_section_id"
end
create_table "members", force: :cascade do |t|
t.string "name"
t.string "id_card_display_name"
@@ -259,17 +259,17 @@ ActiveRecord::Schema[7.2].define(version: 2026_01_16_182836) do
t.index ["id_card_plan_id"], name: "index_members_on_id_card_plan_id"
end
add_foreign_key "id_card_configurations", "employers"
add_foreign_key "id_card_configurations", "id_card_employer_logos", column: "employer_logo_id"
add_foreign_key "id_card_configurations", "id_card_network_logos", column: "network_logo_id"
add_foreign_key "id_card_configurations", "id_card_provider_sections", column: "provider_section_id"
add_foreign_key "id_card_configurations", "id_card_rx_sections", column: "rx_section_id"
add_foreign_key "id_card_field_exception_items", "id_card_field_exceptions", column: "field_exception_id"
add_foreign_key "id_card_field_exception_items", "id_card_network_logos", column: "network_logo_id"
add_foreign_key "id_card_field_exception_items", "id_card_provider_sections", column: "provider_section_id"
add_foreign_key "id_card_field_exceptions", "id_card_setups", column: "setup_id"
add_foreign_key "id_card_field_exceptions", "id_card_configurations", column: "configuration_id"
add_foreign_key "id_card_plan_benefits", "id_card_plans", column: "plan_id"
add_foreign_key "id_card_plans", "id_card_setups", column: "setup_id"
add_foreign_key "id_card_setups", "employers"
add_foreign_key "id_card_setups", "id_card_employer_logos", column: "employer_logo_id"
add_foreign_key "id_card_setups", "id_card_network_logos", column: "network_logo_id"
add_foreign_key "id_card_setups", "id_card_provider_sections", column: "provider_section_id"
add_foreign_key "id_card_setups", "id_card_rx_sections", column: "rx_section_id"
add_foreign_key "id_card_plans", "id_card_configurations", column: "configuration_id"
add_foreign_key "members", "employers"
add_foreign_key "members", "id_card_plans"
end
+64 -153
View File
@@ -1,47 +1,40 @@
def determine_id_card_templates(pl_plan_key)
pl_plan_key = pl_plan_key.to_i
if [13, 19, 20, 48, 49, 50, 51, 52, 53, 54, 58, 59, 61].include?(pl_plan_key)
single_card_template = 'CignaFairosIDCard'
elsif [39].include?(pl_plan_key)
single_card_template = 'CignaFairosIDCard-HALF'
elsif [4, 5, 16, 23, 33, 55, 57, 63].include?(pl_plan_key)
single_card_template = 'MedCostFairosIDCard'
elsif [1, 2].include?(pl_plan_key)
single_card_template = 'SmartIDCard'
elsif [10, 17].include?(pl_plan_key)
single_card_template = 'FirstCallTPAIDCard'
elsif [15, 18].include?(pl_plan_key)
single_card_template = 'SRIIDCARD'
elsif [21].include?(pl_plan_key)
single_card_template = 'SRIIDCARDFairosRx'
elsif [3].include?(pl_plan_key)
single_card_template = 'TPAIDCardTan'
elsif [56].include?(pl_plan_key)
single_card_template = 'CignaHealthBusIDCard'
case pl_plan_key
when 2
"SmartIDCard"
when 3
"TPAIDCardTan"
when 56
"HealthBusIDCard"
else
single_card_template = 'TPAIDCard'
"FairosIDCard"
end
end
if [4, 5, 16, 21, 33, 55, 57, 58, 59, 61].include?(pl_plan_key)
multiple_card_template = 'AllTPAIDCardFairosRx'
elsif [13, 19, 20, 39, 48, 49, 50, 52, 53, 54].include?(pl_plan_key)
multiple_card_template = 'AllHerritageIdCards'
elsif [15, 18].include?(pl_plan_key)
multiple_card_template = 'ALLSRIIDCARD'
elsif [10, 17].include?(pl_plan_key)
multiple_card_template = 'AllFirstCallTPAIDCard'
elsif [3].include?(pl_plan_key)
multiple_card_template = 'AllTPAIDCardTan'
elsif [56].include?(pl_plan_key)
multiple_card_template = 'AllCignaHealthBusIDCard'
else
multiple_card_template = 'AllTPAIDCard'
def determine_id_card_network(pl_plan_key)
pl_plan_key = pl_plan_key.to_i
cigna_groups = [13,20,39,48,49,51,53,54,56,58,60,61,62,65,67,68]
medcost_groups = [4,5,16,23,33,55,57,59,63,66]
old_cigna_groups = [19,21]
smart_medcost = [2]
tan_medcost = [3]
case
when cigna_groups.include?(pl_plan_key)
{ provider: "Cigna", network_logo: "CignaLogo.png", provider_section: "Cigna" }
when medcost_groups.include?(pl_plan_key)
{ provider: "MedCost", network_logo: "MedcostLogo.png", provider_section: "MedCost" }
when old_cigna_groups.include?(pl_plan_key)
{ provider: "Cigna", network_logo: "CignaLogo.png", provider_section: "Cigna (Beam/Stevens)" }
when smart_medcost.include?(pl_plan_key)
{ provider: "MedCost", network_logo: "MedcostLogo.png", provider_section: "MedCost (smART)" }
when tan_medcost.include?(pl_plan_key)
{ provider: "MedCost", network_logo: "MedcostLogo.png", provider_section: "MedCost (Tandemloc)" }
end
{
single_card_template: single_card_template,
multiple_card_template: multiple_card_template
}
end
def determine_network_logos(pl_plan_key)
@@ -131,133 +124,33 @@ end
# Imports employers and members from VHCS
sql_query = "SELECT PLPlanKey, PlanId, ShortDesc FROM PLPlanHeader WHERE ActiveInactive = 'Active' AND PLPlanKey = 65"
plan_headers = VhcsRecord.connection.select_all(sql_query)
# use rake tasks
plan_headers.each do |ph|
import_employer = Employer.find_or_create_by!(pl_plan_key: ph['PLPlanKey']) do |em|
puts "Importing #{ph['ShortDesc'].strip}"
em.name = ph['ShortDesc'].strip
em.plan_id = ph['PlanId'].strip.to_i
id_card_templates = determine_id_card_templates(em.pl_plan_key)
em.single_card_template = id_card_templates[:single_card_template]
em.multiple_card_template = id_card_templates[:multiple_card_template]
plan_code = Vhcs::HlPlanCode.find_by(plan_key: em.pl_plan_key)
em.group_number = plan_code.group_number
em.rx_group_number = plan_code.medical_number
em.effective_date = plan_code.effect_date.strftime("%m/%d/%Y")
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: em.pl_plan_key)
em.company_pb_entity_key = pb_company_plan.company_pb_entity_key
card_display_name = Vhcs::PbEntity.find_by(company_pb_entity_key: em.company_pb_entity_key).last_name
em.id_card_display_name = em.employer_trim_name(card_display_name)
em.default_network_logo = determine_network_logos(em.pl_plan_key)
end
vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: import_employer.company_pb_entity_key)
vhcs_plans.each do |vp|
puts "~~ Importing #{vp.short_description}"
import_plan = import_employer.plans.find_or_create_by!(pb_product_key: vp.pb_product_key) do |pl|
pl.title = vp.short_description
end
vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: import_plan.pb_product_key)
vhcs_plan_benefits.each do |vb|
import_plan.plan_benefits.find_or_create_by!(benefit_desc: vb.benefit_desc) do |pb|
pb.sequence = vb.sequence
pb.benefit = vb.benefit
end
end
end
# if mcswain_employers.include?(ph['PLPlanKey'])
# em.broker = mcswain_broker
# end
vw_mb_members = Vhcs::VwmbMember.where(enrollee_type_value_id: 1, pl_plan_key: ph['PLPlanKey']).select(:mb_member_key, :pb_entity_key, :pl_plan_key, :family_id, :full_name_last_name_first)
vw_mb_members_count = vw_mb_members.length
vw_mb_members.each_with_index do |vwm, i|
import_member = Member.find_or_create_by!(mb_member_key: vwm.mb_member_key) do |me|
me.name = vwm.full_name_last_name_first.titleize
me.pb_entity_key = vwm.pb_entity_key
me.family_id = vwm.family_id
me.pl_plan_key = vwm.pl_plan_key
me.employer = import_employer
card_display_name = Vhcs::PbEntity.find_by(pb_entity_key: me.pb_entity_key).full_name
me.id_card_display_name = card_display_name
plan_pb_product_key = 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" = ?', me.pb_entity_key).first.pb_product_key
if plan = Plan.find_by(pb_product_key: plan_pb_product_key)
me.plan = plan
end
end
puts "Employer #{import_employer.name} (#{i}/#{vw_mb_members_count}) members imported"
end
end
base_cp_provider_codes = ["5", "2"]
needed_codes = %w(M T A I 8 7 1 6 3 P C V Y Z)
# provider_code_map = {}
vhcs_cp = Vhcs::HlidCardProvider.where(provider_code: base_cp_provider_codes).to_a + Vhcs::HlidCardProvider.where(provider_code: needed_codes).order(:provider_code).to_a
default_provider_codes = ["5", "2"]
needed_codes_mapping = {
"0": "MedCost VA Plus Network",
"2": "MedCost",
"3": "AHA Preferred",
"5": "Cigna",
"6": "Cigna (Beam/Stevens)",
A: "AHA",
M: "MedCost (smART)",
T: "MedCost (Tandemloc)"
}.stringify_keys
needed_codes = needed_codes_mapping.keys
vhcs_cp = Vhcs::HlidCardProvider.where(provider_code: needed_codes)
vhcs_cp.each do |vhcs|
attributes_hash = vhcs.attributes.except(:provider_code, :group_number)
attributes_hash.delete_if { |key, value| !key.to_s.include?("_") }
existing_cp = IdCard::ProviderSection.find_by(attributes_hash)
if existing_cp
existing_cp.title = existing_cp.title.concat(vhcs.provider_code)
existing_cp.save
else
title = case
when vhcs.provider_line_1 == "PO Box 188061"
"Cigna #{vhcs.provider_code}"
when vhcs.provider_line_1.present?
"#{vhcs.provider_line_1} #{vhcs.provider_code}"
else
"Medcost #{vhcs.provider_code}"
end
if base_cp_provider_codes.include?(vhcs.provider_code)
if default_provider_codes.include?(vhcs.provider_code)
attributes_hash[:default] = true
end
attributes_hash[:title] = title
attributes_hash[:provider_code] = vhcs.provider_code
attributes_hash[:title] = needed_codes_mapping[vhcs.provider_code]
IdCard::ProviderSection.find_or_create_by(attributes_hash)
end
end
base_cp_provider_codes = ["5", "2"]
needed_codes = %w(M T A I 8 7 1 6 3 P C V Y Z)
# provider_code_map = {}
vhcs_cp = Vhcs::HlidCardProvider.where(provider_code: base_cp_provider_codes).to_a + Vhcs::HlidCardProvider.where(provider_code: needed_codes).order(:provider_code).to_a
vhcs_cp.each do |vhcs|
attributes_hash = vhcs.attributes.except(:provider_code)
attributes_hash.delete_if { |key, value| !key.to_s.include?("_") }
existing_cp = IdCard::ProviderSection.find_by(attributes_hash)
if existing_cp
existing_cp
# if provider_code_map[existing_cp.provider_code]
# provider_code_map[existing_cp.provider_code].push(vhcs.provider_code)
# else
# provider_code_map[existing_cp.provider_code] = [vhcs.provider_code]
# end
else
attributes_hash[:provider_code] = vhcs.provider_code
IdCard::ProviderSection.find_or_create_by(attributes_hash)
end
end
Vhcs::HlrxCrosRef.all.each do |vhcs|
rx = IdCard::RxSection.find_or_create_by(help_desk: vhcs.help_desk, customer_service: vhcs.customer_service, web_url: vhcs.web_url)
title = rx.web_url.gsub(/^www\./, '').gsub(/\.com\Z/, '')
@@ -276,6 +169,24 @@ end
new_logo.save
end
IdCard::Configuration.all.each do |config|
config.card_template = determine_id_card_templates(config.pl_plan_key)
network_information = determine_id_card_network(config.pl_plan_key)
config.network_provider = network_information[:provider]
ps_id = IdCard::ProviderSection.find_by(title: network_information[:provider_section]).id
config.provider_section_id = ps_id
nl_id = IdCard::NetworkLogo.find_by(filename: network_information[:network_logo]).id
config.network_logo_id = nl_id
employer_name = configuration.employer.name
logo_name = employer_name.titleize.gsub(' ', '')
logo = IdCard::EmployerLogo.where("filename LIKE ?", "%#{logo_name}%")
if logo
config.employer_logo_id = logo.first.id
end
end
# 15, 18, 19, 20, 13, 21
+12 -11
View File
@@ -9,28 +9,28 @@ namespace :employer do
plan_headers.each do |ph|
import_employer = Employer.find_or_create_by!(pl_plan_key: ph['PLPlanKey']) do |em|
puts "Importing #{ph['ShortDesc'].strip}"
em.name = ph['ShortDesc'].strip
em.name = ph['ShortDesc'].strip.titleize
em.plan_id = ph['PlanId'].strip.to_i
# id_card_templates = determine_id_card_templates(em.pl_plan_key)
id_card_templates = determine_id_card_templates(em.pl_plan_key)
# em.single_card_template = id_card_templates[:single_card_template]
# em.multiple_card_template = id_card_templates[:multiple_card_template]
id_card_setup = em.build_id_card_setup(pl_plan_key: em.pl_plan_key)
id_card_configuration = em.build_id_card_configuration(pl_plan_key: em.pl_plan_key)
plan_code = Vhcs::HlPlanCode.find_by(plan_key: em.pl_plan_key)
em.group_number = plan_code.group_number
id_card_setup.rx_group_number = plan_code.medical_number
id_card_configuration.rx_group_number = plan_code.medical_number
em.effective_date = plan_code.effect_date.strftime("%m/%d/%Y")
pb_company_plan = Vhcs::PbCompanyPlans.find_by(pl_plan_key: em.pl_plan_key)
em.company_pb_entity_key = pb_company_plan.company_pb_entity_key
card_print_name = Vhcs::PbEntity.find_by(company_pb_entity_key: em.company_pb_entity_key).last_name
id_card_setup.print_name = em.employer_trim_name(card_print_name)
id_card_configuration.print_name = em.employer_trim_name(card_print_name)
id_card_setup.active = true
id_card_configuration.active = true
# em.default_network_logo = determine_network_logos(em.pl_plan_key)
end
@@ -38,15 +38,16 @@ namespace :employer do
vhcs_plans = Vhcs::PbProduct.where(company_pb_entity_key: import_employer.company_pb_entity_key)
vhcs_plans.each do |vp|
puts "~~ Importing #{vp.short_description}"
import_plan = import_employer.id_card_setup.plans.find_or_create_by!(pb_product_key: vp.pb_product_key) do |pl|
import_plan = import_employer.id_card_configuration.plans.find_or_create_by!(pb_product_key: vp.pb_product_key) do |pl|
pl.title = vp.short_description
pl.pl_plan_key = import_employer.pl_plan_key
pl.template = false
end
#Find where benefits info comes from for plplankeys ["2", "3", "5", "13", "16", "19", "20", "21", "33", "49"]
vhcs_plan_benefits = Vhcs::HlEgglestonCardBenefit.where(plan_id: import_plan.pb_product_key)
vhcs_plan_benefits.each do |vb|
import_plan.plan_benefits.find_or_create_by!(benefit_desc: vb.benefit_desc) do |pb|
pb.sequence = vb.sequence
pb.benefit = vb.benefit
end
import_benefit = import_plan.plan_benefits.find_by(sequence: vb.sequence)
import_benefit.update(benefit: vb.benefit)
end
end
end