Major features finished
This commit is contained in:
@@ -3,7 +3,7 @@ module IdCardPrinterService
|
||||
|
||||
def initialize(employers_member_keys)
|
||||
# @employer = employer
|
||||
@employers_member_keys = employers_member_keys
|
||||
@employers_member_keys = Array.wrap(employers_member_keys)
|
||||
|
||||
# @employer = Employer.includes(id_card_setup: [:provider_section, :rx_section]).find_by(pl_plan_key: pl_plan_key)
|
||||
# @card_setup = @employer.id_card_setup
|
||||
@@ -41,7 +41,6 @@ module IdCardPrinterService
|
||||
group_number: @employer.group_number,
|
||||
rx_group: @card_setup.rx_group_number,
|
||||
network_provider: @card_setup.network_provider,
|
||||
network_logo_id: @card_setup.network_logo_id,
|
||||
network_logo_filename: @card_setup.network_logo.filename,
|
||||
employer_logo_filename: @card_setup.employer_logo.filename
|
||||
}
|
||||
@@ -58,7 +57,8 @@ module IdCardPrinterService
|
||||
: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
|
||||
:claim_to_7, :claim_to_8, :claim_to_9, :claim_to_10, :claim_to_11, :claim_to_12,
|
||||
:precert_1, :precert_2, :precert_3, :precert_4
|
||||
)
|
||||
|
||||
selected_attributes = employer_attributes.merge(rx_attributes).merge(provider_attributes)
|
||||
@@ -83,11 +83,16 @@ module IdCardPrinterService
|
||||
end
|
||||
|
||||
def create_member_cards_async
|
||||
field_exceptions = @card_setup.field_exceptions.pluck(:id)
|
||||
field_exceptions_map = @card_setup.field_exceptions_card_attributes_by_member_id(@member_keys)
|
||||
mmember_card_futures = @member_keys.map do |member_key|
|
||||
member_card_exceptions_attrs = {}
|
||||
member_card_exception_id = field_exceptions_map[member_key]
|
||||
if member_card_exception_id
|
||||
member_card_exceptions_attrs = field_exceptions_map[member_card_exception_id]
|
||||
end
|
||||
Concurrent::Future.execute do
|
||||
ActiveRecord::Base.connection_pool.with_connection do
|
||||
ProcessIdCardDataJob.perform_now(member_key, field_exceptions, @card_setup.has_divisions)
|
||||
ProcessMemberCardDataJob.perform_now(member_key, member_card_exceptions_attrs, @card_setup.has_divisions, @card_setup.has_dental)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,13 +15,30 @@ module IdCardPrinterService
|
||||
IdCard::PrintData.where(pl_plan_key: pl_plan_keys, primary_mb_member_key: nil).destroy_all
|
||||
|
||||
pdf_array = []
|
||||
batches = break_into_batches(pl_plan_keys)
|
||||
batches.each do |card_template, batch_pl_plan_keys|
|
||||
jasper_batch_id = "#{batch_pl_plan_keys.join('_')}-#{Time.current.utc.to_i}"
|
||||
batch = IdCard::PrintData.where(pl_plan_key: batch_pl_plan_keys)
|
||||
batch.update!(jasper_batch_id: jasper_batch_id)
|
||||
batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(card_template, jasper_batch_id, @layout).call
|
||||
pdf_array << batch_pdf
|
||||
template_groups = break_up_by_template(pl_plan_keys)
|
||||
template_groups.each do |card_template, template_pl_plan_keys|
|
||||
batch = IdCard::PrintData.where(pl_plan_key: template_pl_plan_keys)
|
||||
# all_template_cards.in_batches(of: 75).each_with_index do |batch, index|
|
||||
jasper_batch_id = "#{template_pl_plan_keys.join('_')}-#{Time.current.utc.to_i}"
|
||||
# binding.pry
|
||||
batch.update!(jasper_batch_id: jasper_batch_id)
|
||||
if @layout == "PrintCard"
|
||||
add_dependent_cards(batch)
|
||||
end
|
||||
batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(card_template, jasper_batch_id, @layout).call
|
||||
pdf_array << batch_pdf
|
||||
# end
|
||||
# jasper_batches = break_into_jasper_batches(group_pl_plan_keys)
|
||||
# jasper_batches.each_with_index do |batch, index|
|
||||
# jasper_batch_id = "#{group_pl_plan_keys.join('_')}-#{index + 1}-#{Time.current.utc.to_i}"
|
||||
# binding.pry
|
||||
# batch.update!(jasper_batch_id: jasper_batch_id)
|
||||
# if @layout == "PrintCard"
|
||||
# add_dependent_cards(batch)
|
||||
# end
|
||||
# batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(card_template, jasper_batch_id, @layout).call
|
||||
# pdf_array << batch_pdf
|
||||
# end
|
||||
end
|
||||
# @employers_member_keys.each do |emk|
|
||||
# employer_jasper_batches = IdCard::PrintData.where(pl_plan_key: emk[:pl_plan_key]).pluck(:network_logo_id).uniq
|
||||
@@ -44,18 +61,47 @@ module IdCardPrinterService
|
||||
|
||||
private
|
||||
|
||||
def break_into_batches(pl_plan_keys)
|
||||
def break_up_by_template(pl_plan_keys)
|
||||
batches_by_card_template = IdCard::Setup.where(pl_plan_key: pl_plan_keys).group_by(&:card_template)
|
||||
.transform_values { |setups| setups.map(&:pl_plan_key) }
|
||||
.compact_blank
|
||||
end
|
||||
|
||||
def break_into_jasper_batches(pl_plan_keys)
|
||||
all_cards = IdCard::PrintData.where(pl_plan_key: pl_plan_keys)
|
||||
binding.pry
|
||||
jasper_batches = all_cards.each_slice(75).to_a
|
||||
jasper_batches
|
||||
end
|
||||
|
||||
def add_dependent_cards(batch)
|
||||
batch.where.not(dependent_1: [nil, ""]).find_each do |member_card|
|
||||
dependent_card = member_card.dup
|
||||
dependent_card.update(
|
||||
full_name_last_name_first: member_card.full_name_last_name_first.concat(" dependent")
|
||||
)
|
||||
dependent_card.save
|
||||
end
|
||||
end
|
||||
|
||||
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])
|
||||
pdf_file = pdf_array.first
|
||||
puts "-- CombinePdfPages --"
|
||||
puts pdf_file.pages.count
|
||||
pdf_file.pages.reverse.each do |page|
|
||||
page_pdf = CombinePDF.new
|
||||
page_pdf << page
|
||||
page_data = page_pdf.to_pdf
|
||||
full_name_last_name_first = get_watermark_field(page_data)
|
||||
if full_name_last_name_first.present?
|
||||
page_filename = "#{full_name_last_name_first.gsub(", ", "_")}_digital_card_#{Date.today}.pdf"
|
||||
puts "-- Filename --"
|
||||
puts page_filename
|
||||
zio.put_next_entry(page_filename)
|
||||
zio.write(page_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -64,5 +110,19 @@ module IdCardPrinterService
|
||||
end
|
||||
group_cards_pdf
|
||||
end
|
||||
|
||||
def get_watermark_field(page_data)
|
||||
watermark_field = ""
|
||||
reader = PDF::Reader.new(StringIO.new(page_data))
|
||||
puts "-- ReaderPages --"
|
||||
puts reader.pages.count
|
||||
page = reader.pages.first
|
||||
if watermark_match = page.text.match(/:WATERMARK:([^:]*):/)
|
||||
watermark_field = page.text.match(/:WATERMARK:([^:]*):/)[1].strip
|
||||
else
|
||||
puts "blank page"
|
||||
end
|
||||
watermark_field
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ module IdCardPrinterService
|
||||
host: '10.41.1.115',
|
||||
port: 8080,
|
||||
path: '/trunk/IdCardsServlet',
|
||||
query: "reportConn=BrittonConnect&cardTemplate=#{@card_template}Batch&printType=Batch#{@layout}&jasper_batch_id=#{@jasper_batch_id}&FileType=PDF"
|
||||
query: "reportConn=BrittonConnect&cardTemplate=#{@card_template}&printType=#{@layout}&jasper_batch_id=#{@jasper_batch_id}&FileType=PDF"
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ module IdCardPrinterService
|
||||
def call
|
||||
|
||||
response = HTTParty.get(@jasper_url)
|
||||
# response.body
|
||||
CombinePDF.parse(response.body)
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
module IdCardPrinterService
|
||||
class PdfFormatter
|
||||
|
||||
def initialize(pdf_array ,layout, zip=false)
|
||||
@pdf_array = pdf_array
|
||||
@layout = layout
|
||||
@zip = zip
|
||||
end
|
||||
|
||||
def call
|
||||
|
||||
if @layout == "FullPageCard"
|
||||
pdf_file = @pdf_array.first
|
||||
puts "-- CombinePdfPages --"
|
||||
puts pdf_file.pages.count
|
||||
pdf_file.pages.reverse.each do |page|
|
||||
page_pdf = CombinePDF.new
|
||||
page_pdf << page
|
||||
page_data = page_pdf.to_pdf
|
||||
full_name_last_name_first = get_watermark_field(page_data)
|
||||
if full_name_last_name_first.present?
|
||||
page_filename = "#{full_name_last_name_first.gsub(", ", "_")}_digital_card_#{Date.today}.pdf"
|
||||
group_cards_pdf_array << { name: page_filename, data: page_data }
|
||||
end
|
||||
end
|
||||
|
||||
group_cards_pdf = Zip::OutputStream.write_buffer do |zio|
|
||||
pdf_file = pdf_array.first
|
||||
puts "-- CombinePdfPages --"
|
||||
puts pdf_file.pages.count
|
||||
pdf_file.pages.reverse.each do |page|
|
||||
page_pdf = CombinePDF.new
|
||||
page_pdf << page
|
||||
page_data = page_pdf.to_pdf
|
||||
full_name_last_name_first = get_watermark_field(page_data)
|
||||
if full_name_last_name_first.present?
|
||||
page_filename = "#{full_name_last_name_first.gsub(", ", "_")}_digital_card_#{Date.today}.pdf"
|
||||
puts "-- Filename --"
|
||||
puts page_filename
|
||||
zio.put_next_entry(page_filename)
|
||||
zio.write(page_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
group_cards_pdf = CombinePDF.new
|
||||
pdf_array.each { |pdf| group_cards_pdf << pdf }
|
||||
end
|
||||
group_cards_pdf
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_watermark_field(page_data)
|
||||
watermark_field = ""
|
||||
reader = PDF::Reader.new(StringIO.new(page_data))
|
||||
puts "-- ReaderPages --"
|
||||
puts reader.pages.count
|
||||
page = reader.pages.first
|
||||
if watermark_match = page.text.match(/:WATERMARK:([^:]*):/)
|
||||
watermark_field = page.text.match(/:WATERMARK:([^:]*):/)[1].strip
|
||||
else
|
||||
puts "blank page"
|
||||
end
|
||||
watermark_field
|
||||
end
|
||||
|
||||
def break_into_batches(pl_plan_keys)
|
||||
batches_by_card_template = IdCard::Setup.where(pl_plan_key: pl_plan_keys).group_by(&:card_template)
|
||||
.transform_values { |setups| setups.map(&:pl_plan_key) }
|
||||
.compact_blank
|
||||
end
|
||||
|
||||
def combine_pdfs(pdf_array)
|
||||
if @zip
|
||||
group_cards_pdf = Zip::OutputStream.write_buffer do |zio|
|
||||
pdf_file = pdf_array.first
|
||||
puts "-- CombinePdfPages --"
|
||||
puts pdf_file.pages.count
|
||||
pdf_file.pages.reverse.each do |page|
|
||||
page_pdf = CombinePDF.new
|
||||
page_pdf << page
|
||||
page_data = page_pdf.to_pdf
|
||||
full_name_last_name_first = get_watermark_field(page_data)
|
||||
if full_name_last_name_first.present?
|
||||
page_filename = "#{full_name_last_name_first.gsub(", ", "_")}_digital_card_#{Date.today}.pdf"
|
||||
puts "-- Filename --"
|
||||
puts page_filename
|
||||
zio.put_next_entry(page_filename)
|
||||
zio.write(page_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
group_cards_pdf = CombinePDF.new
|
||||
pdf_array.each { |pdf| group_cards_pdf << pdf }
|
||||
end
|
||||
group_cards_pdf
|
||||
end
|
||||
|
||||
def get_watermark_field(page_data)
|
||||
watermark_field = ""
|
||||
reader = PDF::Reader.new(StringIO.new(page_data))
|
||||
puts "-- ReaderPages --"
|
||||
puts reader.pages.count
|
||||
page = reader.pages.first
|
||||
if watermark_match = page.text.match(/:WATERMARK:([^:]*):/)
|
||||
watermark_field = page.text.match(/:WATERMARK:([^:]*):/)[1].strip
|
||||
else
|
||||
puts "blank page"
|
||||
end
|
||||
watermark_field
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user