Before a few renames
This commit is contained in:
@@ -3,6 +3,7 @@ module BenefitsWordDoc
|
||||
|
||||
def initialize(employer, word_doc_section)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
@word_doc_section = word_doc_section
|
||||
end
|
||||
|
||||
@@ -27,6 +28,7 @@ module BenefitsWordDoc
|
||||
end
|
||||
end
|
||||
end
|
||||
@card_config.rx_group_number = @employer.group_number
|
||||
@employer
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ module BenefitsWordDoc
|
||||
|
||||
def initialize(employer, word_doc)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
@word_doc = word_doc
|
||||
end
|
||||
|
||||
@@ -40,7 +41,7 @@ module BenefitsWordDoc
|
||||
# @employer.single_card_template = "FairosRxIDCard"
|
||||
# end
|
||||
|
||||
@employer.id_card_configuration.employer_logo = logo
|
||||
@card_config.employer_logo = logo
|
||||
end
|
||||
end
|
||||
@employer
|
||||
|
||||
@@ -3,6 +3,7 @@ module BenefitsWordDoc
|
||||
|
||||
def initialize(employer, word_doc_section)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
@word_doc_section = word_doc_section
|
||||
end
|
||||
|
||||
@@ -19,7 +20,7 @@ module BenefitsWordDoc
|
||||
if line.match?(/cigna/i)
|
||||
break "Cigna"
|
||||
elsif line.match?(/medcost/i)
|
||||
break "Medcost"
|
||||
break "MedCost"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,11 +29,11 @@ module BenefitsWordDoc
|
||||
# end
|
||||
|
||||
if network
|
||||
@employer.id_card_configuration.network_provider = network
|
||||
@employer.id_card_configuration.network_logo = IdCard::NetworkLogo
|
||||
provider_code = network_provider == "Cigna" ? "5" : "2"
|
||||
@employer.card_provider = CardProvider.find_by(provider_code: provider_code)
|
||||
@employer.card_rx = CardRx.find_by(web_url: "www.FairosRx.com")
|
||||
@card_config.network_provider = network
|
||||
logo_name = "#{network}Logo.png"
|
||||
@card_config.network_logo = IdCard::NetworkLogo.find_by(filename: logo_name)
|
||||
@card_config.provider_section = IdCard::ProviderSection.find_by(title: network)
|
||||
@card_config.rx_section = IdCard::RxSection.find_by(title: "FairosRx")
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ module BenefitsWordDoc
|
||||
|
||||
def initialize(employer, word_doc_section)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
@word_doc_section = word_doc_section
|
||||
end
|
||||
|
||||
@@ -11,12 +12,12 @@ module BenefitsWordDoc
|
||||
plans_indexes = @word_doc_section.each_index.select { |index| @word_doc_section[index].match?(/\d*\.?\d+k/i) }
|
||||
|
||||
plans_indexes.each do |plan_index|
|
||||
new_plan = @employer.build_plan_with_default_benefits(title: @word_doc_section[plan_index])
|
||||
new_plan = @card_config.plans.build(title: @word_doc_section[plan_index])
|
||||
plan_lines = @word_doc_section.slice(plan_index + 1, 14)
|
||||
plan_lines.each_with_index do |line, i|
|
||||
field_mapping = mapping_array[i]
|
||||
if line.match(/:.*/)
|
||||
field_value = line.match(/:.*/)[0].strip
|
||||
if line.match(/(?<=:).+/)
|
||||
field_value = line.match(/(?<=:).+/)[0].strip
|
||||
else
|
||||
field_regex = field_mapping[:doc_to_employer_regex]
|
||||
if line.match(field_regex)
|
||||
|
||||
@@ -6,6 +6,7 @@ class BenefitsWordDocProcessor
|
||||
@employer = employer
|
||||
else
|
||||
@employer = Employer.new
|
||||
@employer.build_id_card_configuration
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module EmployerCards
|
||||
class GetQueuedCards
|
||||
|
||||
def initialize(pl_plan_keys)
|
||||
def initialize(pl_plan_keys = nil)
|
||||
if pl_plan_keys
|
||||
@employer_pl_plan_keys = pl_plan_keys
|
||||
else
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
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
|
||||
@@ -1,17 +1,38 @@
|
||||
module IdCardPrinter
|
||||
class EmployerCardsGenerator
|
||||
|
||||
def initialize(pl_plan_key, layout, zip=false)
|
||||
@pl_plan_key = pl_plan_key
|
||||
def initialize(employer, layout, zip=false)
|
||||
@employer = employer
|
||||
@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
|
||||
IdCard::PrintData.where(pl_plan_key: @employer.pl_plan_key).destroy_all
|
||||
IdCardPrinter::EmployerDataFormatter.new(@employer).call
|
||||
|
||||
IdCardPrinter::PdfProcessor.new(@pl_plan_key, @layout, @zip).call
|
||||
pdf_array = IdCardPrinter::PdfProcessor.new(@employer, @layout, @zip).call
|
||||
|
||||
group_pdfs = combine_pdfs(pdf_array)
|
||||
group_pdfs
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def combine_pdfs(pdf_array)
|
||||
if @zip
|
||||
group_cards_pdf = Zip::OutputStream.write_buffer do |zio|
|
||||
pdf_array.each do |file|
|
||||
zio.put_next_entry(file[:name])
|
||||
zio.write(file[:data])
|
||||
end
|
||||
end
|
||||
else
|
||||
group_cards_pdf = CombinePDF.new
|
||||
pdf_array.each { |pdf| group_cards_pdf << pdf }
|
||||
end
|
||||
group_cards_pdf
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
module IdCardPrinter
|
||||
class EmployerDataFormatter
|
||||
|
||||
def initialize(employer, member_keys = nil)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
|
||||
if member_keys
|
||||
@members = @employer.members.where(pb_entity_key: member_keys).order(:name)
|
||||
else
|
||||
@members = @employer.members.order(:name)
|
||||
end
|
||||
end
|
||||
|
||||
def call
|
||||
@base_card = IdCard::PrintData.new()
|
||||
@employer_cards = []
|
||||
|
||||
set_common_fields
|
||||
set_member_fields
|
||||
|
||||
|
||||
set_plan_fields
|
||||
|
||||
@employer_cards.each(&:save!)
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_common_fields
|
||||
employer_attributes = {
|
||||
employer_name: @card_config.print_name,
|
||||
pl_plan_key: @card_config.pl_plan_key,
|
||||
group_number: @employer.group_number,
|
||||
rx_group: @card_config.rx_group_number,
|
||||
network_provider: @card_config.network_provider
|
||||
}
|
||||
|
||||
rx_attributes = @card_config.rx_section.attributes.with_indifferent_access.slice(
|
||||
:customer_service,
|
||||
:web_url
|
||||
)
|
||||
|
||||
provider_attributes = @card_config.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
|
||||
)
|
||||
|
||||
selected_attributes = employer_attributes.merge(rx_attributes).merge(provider_attributes)
|
||||
@base_card.assign_attributes(selected_attributes)
|
||||
end
|
||||
|
||||
def set_common_fields_old
|
||||
employer_attributes = {
|
||||
employer_name: @card_config.print_name,
|
||||
group_number: @employer.group_number,
|
||||
rx_group: @card_config.rx_group_number
|
||||
}
|
||||
|
||||
rx_attributes = @card_config.rx_section.attributes.with_indifferent_access.slice(
|
||||
:customer_service,
|
||||
:web_url
|
||||
)
|
||||
|
||||
provider_attributes = @card_config.provider_section.attributes.with_indifferent_access.slice(
|
||||
:provider_code, :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
|
||||
)
|
||||
|
||||
selected_attributes = employer_attributes.merge(rx_attributes).merge(provider_attributes)
|
||||
@employer_cards.each do |card|
|
||||
card.assign_attributes(selected_attributes)
|
||||
end
|
||||
end
|
||||
|
||||
def set_plan_fields
|
||||
@card_config.plans.each do |plan|
|
||||
selected_attributes = {}
|
||||
plan.plan_benefits.each do |bene|
|
||||
selected_attributes["benefit_desc_#{bene.sequence}".to_sym] = bene.benefit_desc
|
||||
selected_attributes["benefit_#{bene.sequence}".to_sym] = bene.benefit
|
||||
end
|
||||
@employer_cards.find_all { |card| card.plan_id == plan.id.to_s }.each do |card|
|
||||
card.assign_attributes(selected_attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_member_fields
|
||||
@group_dependents = Vhcs::VwmbMember.where(pl_plan_key: @employer.pl_plan_key)
|
||||
@members.each do |me|
|
||||
effect_date = determine_eff_date(me)
|
||||
if effect_date
|
||||
member_card = @base_card.dup
|
||||
member_attributes = {
|
||||
full_name: me.id_card_display_name,
|
||||
full_name_last_name_first: me.name,
|
||||
primary_mb_member_key: me.pb_entity_key,
|
||||
family_id: me.family_id,
|
||||
plan_id: me.id_card_plan_id,
|
||||
medical_eff_date: effect_date.strftime("%m/%d/%Y")
|
||||
}
|
||||
|
||||
dependent_attributes = get_dependent_fields(me)
|
||||
if dependent_attributes.present?
|
||||
selected_attributes = member_attributes.merge(dependent_attributes)
|
||||
else
|
||||
selected_attributes = member_attributes
|
||||
end
|
||||
|
||||
member_card.assign_attributes(selected_attributes)
|
||||
@employer_cards.push(member_card)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def set_network_fields
|
||||
# selected_attributes = @employer.card_provider.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
|
||||
# )
|
||||
# @employer_cards.all do |card|
|
||||
# card.assign_attributes(selected_attributes)
|
||||
# end
|
||||
# end
|
||||
|
||||
# def set_rx_fields
|
||||
# # fairos_information = Vhcs::HlrxCrosRef.where(pl_plan_key: 52).first
|
||||
# selected_attributes = @employer.card_rx.attributes.with_indifferent_access.slice(
|
||||
# :customer_service,
|
||||
# :web_url
|
||||
# )
|
||||
# @employer_cards.all do |card|
|
||||
# card.assign_attributes(selected_attributes)
|
||||
# end
|
||||
# end
|
||||
|
||||
def determine_eff_date(member)
|
||||
|
||||
participation = Vhcs::PbProductParticipation.joins('INNER JOIN "PBCoveredEntities" ON "PBProductParticipation"."PBProductParticipationKey" = "PBCoveredEntities"."PBProductParticipationKey"').where('"PBCoveredEntities"."PBEntityKey" = ?', member.pb_entity_key).last
|
||||
in_effect = participation.in_effect
|
||||
out_of_effect = participation.out_of_effect
|
||||
|
||||
if in_effect <= (Date.today + 90.days) && (out_of_effect - 1.day) > Date.today && out_of_effect > in_effect
|
||||
in_effect
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def get_dependent_fields(member)
|
||||
dependent_attributes = {}
|
||||
dependents = @group_dependents.where(family_id: member.family_id).where.not(pb_entity_key: member.pb_entity_key)
|
||||
dependents.each do |dep|
|
||||
dependent_name = dep.first_name + ' ' + dep.last_name
|
||||
dependent_attributes["dependent_#{dep.sequence_number - 1}".to_sym] = dependent_name
|
||||
end
|
||||
dependent_attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,9 +3,9 @@ module IdCardPrinter
|
||||
|
||||
def initialize(pl_plan_key, family_id, layout)
|
||||
@pl_plan_key = pl_plan_key
|
||||
@card_config = IdCard::Configuration.find_by(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
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
module IdCardPrinter
|
||||
class MemberCardsGenerator
|
||||
|
||||
def initialize(member_keys, layout)
|
||||
@member_keys = Array.wrap(member_keys)
|
||||
@employer = employer
|
||||
@layout = layout
|
||||
@zip = zip
|
||||
end
|
||||
|
||||
def call
|
||||
IdCard::PrintData.where(mb_member_key: @employer.pl_plan_key).destroy_all
|
||||
IdCardPrinter::EmployerDataFormatter.new(@employer).call
|
||||
|
||||
pdf_array = IdCardPrinter::PdfProcessor.new(@employer, @layout, @zip).call
|
||||
|
||||
group_pdfs = combine_pdfs(pdf_array)
|
||||
group_pdfs
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def combine_pdfs(pdf_array)
|
||||
if @zip
|
||||
group_cards_pdf = Zip::OutputStream.write_buffer do |zio|
|
||||
pdf_array.each do |file|
|
||||
zio.put_next_entry(file[:name])
|
||||
zio.write(file[:data])
|
||||
end
|
||||
end
|
||||
else
|
||||
group_cards_pdf = CombinePDF.new
|
||||
pdf_array.each { |pdf| group_cards_pdf << pdf }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,40 +1,45 @@
|
||||
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
|
||||
def initialize(employer, layout, zip = false)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
@layout = layout
|
||||
@zip = zip
|
||||
end
|
||||
|
||||
def call
|
||||
# if @zip
|
||||
# group_cards_pdf_array = []
|
||||
# else
|
||||
# group_cards_pdf = CombinePDF.new
|
||||
# end
|
||||
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
|
||||
IdCard::PrintData.where(pl_plan_key: @employer.pl_plan_key).each do |card|
|
||||
url = IdCardPrinter::JasperUrlGenerator.new(@employer.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"
|
||||
card_filename = "#{card.full_name_last_name_first.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
|
||||
# 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
|
||||
group_cards_pdf_array
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,61 @@
|
||||
module IdCardPrinter
|
||||
class QueuedCardsGenerator
|
||||
|
||||
def initialize(employer_member_keys)
|
||||
@employer_member_keys = Array.wrap(employer_member_keys)
|
||||
@layout = 'PrintCard'
|
||||
@pl_plan_keys = @employer_member_keys.map { |emk| emk["PlanKey"].to_s }
|
||||
end
|
||||
|
||||
def call
|
||||
white_card_array = []
|
||||
blue_card_array = []
|
||||
IdCard::PrintData.where(pl_plan_key: @pl_plan_keys).destroy_all
|
||||
@employer_member_keys.each do |emk|
|
||||
employer = Employer.find_by(pl_plan_key: emk["PlanKey"])
|
||||
member_keys = emk["MemberKeys"].split(", ").map(&:to_i)
|
||||
IdCardPrinter::EmployerDataFormatter.new(employer, member_keys).call
|
||||
if emk["PlanKey"] == "3"
|
||||
blue_card_array = IdCardPrinter::PdfProcessor.new(employer, @layout).call
|
||||
else
|
||||
white_card_array = IdCardPrinter::PdfProcessor.new(employer, @layout).call
|
||||
end
|
||||
end
|
||||
|
||||
combine_pdfs(blue_card_array, white_card_array)
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def combine_pdfs(blue_cards, white_cards)
|
||||
if blue_cards.present? && white_cards.present?
|
||||
combined_pdfs = []
|
||||
blue_filename = "queued_blue_cards_#{Date.today}.pdf"
|
||||
combined_pdfs << { name: blue_filename, data: blue_cards.to_pdf }
|
||||
white_filename = "queued_white_cards_#{Date.today}.pdf"
|
||||
combined_pdfs << { name: white_filename, data: white_cards.to_pdf }
|
||||
|
||||
output_file = zip_cards(combined_pdfs)
|
||||
elsif blue_cards.present?
|
||||
output_file = CombinePDF.new
|
||||
blue_cards.each { |pdf| output_file << pdf }
|
||||
elsif white_cards.present?
|
||||
output_file = CombinePDF.new
|
||||
white_cards.each { |pdf| output_file << pdf }
|
||||
end
|
||||
|
||||
output_file
|
||||
end
|
||||
|
||||
def zip_cards(pdf_array)
|
||||
Zip::OutputStream.write_buffer do |zio|
|
||||
pdf_array.each do |file|
|
||||
zio.put_next_entry(file[:name])
|
||||
zio.write(file[:data])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
module IdCardPrinter
|
||||
class SampleCardsGenerator
|
||||
|
||||
def initialize(employer)
|
||||
@employer = employer
|
||||
end
|
||||
|
||||
def call
|
||||
IdCard::PrintData.where(employer_name: @employer.name).destroy_all
|
||||
IdCardPrinter::SampleDataFormatter.new(@employer).call
|
||||
|
||||
IdCardPrinter::SamplePdfProcessor.new(@employer).call
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,96 @@
|
||||
module IdCardPrinter
|
||||
class SampleDataFormatter
|
||||
|
||||
def initialize(employer)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
end
|
||||
|
||||
def call
|
||||
@base_card = IdCard::PrintData.new(sample: true)
|
||||
|
||||
set_employer_fields()
|
||||
set_sample_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
|
||||
}
|
||||
|
||||
@base_card.assign_attributes(selected_attributes)
|
||||
end
|
||||
|
||||
def set_plan_fields
|
||||
plans_base_cards = []
|
||||
@card_config.plans.each do |plan|
|
||||
@base_card.sample_key = @card_config.print_name.titleize.split.map(&:first).push(plan.id).join
|
||||
plan_base_card = @base_card.dup
|
||||
plan_name = plan.title.split(/(?<=\d[kK])/).first
|
||||
plan.plan_benefits.each do |bene|
|
||||
plan_base_card["benefit_desc_#{bene.sequence}".to_sym] = bene.benefit_desc
|
||||
plan_base_card["benefit_#{bene.sequence}".to_sym] = bene.benefit
|
||||
end
|
||||
plan_base_card.sample_plan_title = plan_name
|
||||
plans_base_cards.push(plan_base_card)
|
||||
end
|
||||
plans_base_cards
|
||||
end
|
||||
|
||||
def set_sample_fields
|
||||
selected_attributes = {
|
||||
full_name: "JANE DOE",
|
||||
primary_mb_member_key: "888888",
|
||||
rx_group: @employer.group_number.present? ? @employer.group_number : "999999"
|
||||
}
|
||||
|
||||
@base_card.assign_attributes(selected_attributes)
|
||||
end
|
||||
|
||||
def set_network_fields
|
||||
selected_attributes = @card_config.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 @card_config.network_provider == "Cigna"
|
||||
# @base_card.provider_code = "5"
|
||||
# end
|
||||
@base_card.network_provider = @card_config.network_provider
|
||||
|
||||
@base_card.assign_attributes(selected_attributes)
|
||||
end
|
||||
|
||||
def set_rx_fields
|
||||
# fairos_information = Vhcs::HlrxCrosRef.where(pl_plan_key: 52).first
|
||||
selected_attributes = @card_config.rx_section.attributes.with_indifferent_access.slice(
|
||||
:customer_service,
|
||||
:web_url
|
||||
)
|
||||
|
||||
@base_card.assign_attributes(selected_attributes)
|
||||
end
|
||||
|
||||
def set_dependent_fields
|
||||
@base_card.dependent_1 = "John Doe"
|
||||
# @base_card.dependent_2 = "Molly Doe"
|
||||
# @base_card.dependent_3 = "Jonathan Doe"
|
||||
# @base_card.dependent_4 = "Calvin Doe"
|
||||
# @base_card.dependent_5 = "Richard Doe"
|
||||
# @base_card.dependent_6 = "Jannet Doe"
|
||||
# @base_card.dependent_7 = "Longername Doe"
|
||||
# @base_card.dependent_8 = "Robbert Doe"
|
||||
end
|
||||
end
|
||||
end
|
||||
+8
-24
@@ -1,9 +1,10 @@
|
||||
module SampleCard
|
||||
class JasperUrlGenerator
|
||||
module IdCardPrinter
|
||||
class SampleJasperUrlGenerator
|
||||
|
||||
def initialize(employer, plan_name)
|
||||
@plan_name = plan_name
|
||||
@employer = employer
|
||||
def initialize(employer, sample_key, sample_title)
|
||||
@sample_key = sample_key
|
||||
@sample_title = sample_title
|
||||
@card_config = employer.id_card_configuration
|
||||
end
|
||||
|
||||
def call
|
||||
@@ -14,23 +15,6 @@ module SampleCard
|
||||
|
||||
private
|
||||
|
||||
def determine_card_template
|
||||
# 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
|
||||
# if @employer.single_card_template.include?("Half")
|
||||
# "FairosRxSampleIDCard-Half-Display"
|
||||
# else
|
||||
# "FairosRxSampleIDCard-Display"
|
||||
# end
|
||||
end
|
||||
|
||||
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
|
||||
@@ -41,7 +25,7 @@ module SampleCard
|
||||
# end
|
||||
# end
|
||||
# @network_logos.find_by(default: true).net_logo
|
||||
@employer.default_network_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
|
||||
@@ -50,7 +34,7 @@ module SampleCard
|
||||
host: '10.41.1.115',
|
||||
port: 8080,
|
||||
path: '/trunk/IdCardsServlet',
|
||||
query: "reportConn=BrittonConnect&cardTemplate=FairosRxIDCard&printType=SampleCard&family_id=#{@plan_name}&employer_logo=#{@employer.employer_logo_filename}&network_logo=#{determine_network_logo}&FileType=PDF"
|
||||
query: "reportConn=BrittonConnect&cardTemplate=#{@card_config.card_template}&printType=SampleCard&sample_key=#{@sample_key}&sample_plan_title=#{@sample_title}&employer_logo=#{@card_config.employer_logo.filename}&network_logo=#{determine_network_logo}&FileType=PDF"
|
||||
}
|
||||
end
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
module IdCardPrinter
|
||||
class SamplePdfProcessor
|
||||
|
||||
def initialize(employer)
|
||||
@employer = employer
|
||||
@card_config = @employer.id_card_configuration
|
||||
end
|
||||
|
||||
def call
|
||||
group_cards_pdf = CombinePDF.new
|
||||
IdCard::PrintData.where(employer_name: @employer.name).each do |card|
|
||||
url = IdCardPrinter::SampleJasperUrlGenerator.new(@employer, card.sample_key, card.sample_plan_title).call
|
||||
puts url
|
||||
card_pdf = IdCardPrinter::JasperPdfGenerator.new(url).call
|
||||
|
||||
group_cards_pdf << card_pdf
|
||||
end
|
||||
|
||||
# todays_date = DateTime.current.strftime('%Y%m%d%H%M%S')
|
||||
# group_cards_pdf.save("tmp/#{@employer.name}_print_cards_#{todays_date}.pdf")
|
||||
|
||||
group_cards_pdf
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user