Employer form mostly working with persist to db

This commit is contained in:
Jason Jordan
2025-12-10 13:22:33 -05:00
parent 78ce415b94
commit 0464ba8929
68 changed files with 3071 additions and 365 deletions
@@ -0,0 +1,72 @@
module BenefitsWordDoc
class MapEmployerInformation
def initialize(process, word_doc_section)
@process = process
@word_doc_section = word_doc_section
end
def call
search_fields = mapping_hash.keys.to_set
@word_doc_section.each do |line|
matching_field = search_fields.detect { |field| line.include?(field) }
if matching_field
field_mapping = mapping_hash[matching_field]
field_regex = field_mapping[:doc_to_process_regex]
field_value = line.match(field_regex)[1].strip
process_field = field_mapping[:process_field]
if field_mapping[:validation].present?
validation_type = field_mapping[:validation]
if send("is_#{validation_type}?".to_sym, field_value)
@process[process_field] = field_value
end
else
@process[process_field] = field_value
end
end
end
@process.save
end
private
def mapping_hash
{
'Employer Name' => {
process_field: :employer_name,
doc_field: 'Employer Name',
doc_field_desc: 'Follows pattern - Employer Name:New Employer',
doc_to_process_regex: /.*:(.*)/,
regex_desc: 'Grabs everything after colon'
},
'Group Number' => {
process_field: :group_number,
doc_field: 'Group Number',
doc_field_desc: 'Follows pattern - Group Number:099999',
doc_to_process_regex: /.*:(.*)/,
regex_desc: 'Grabs everything after colon',
validation: 'number'
},
'Group Effective Date' => {
process_field: :effective_date,
doc_field: 'Group Effective Date',
doc_field_desc: 'Follows pattern - Group Effective Date:12/1/2025',
doc_to_process_regex: /.*:(.*)/,
regex_desc: 'Grabs everything after colon',
validation: 'date'
}
}
end
def is_number?(string)
true if Float(string) rescue false
end
def is_date?(string)
true if Date.parse rescue false
end
end
end
@@ -0,0 +1,28 @@
module BenefitsWordDoc
class MapEmployerLogo
def initialize(process, word_doc)
@process = process
@word_doc = word_doc
end
def call
extracted_images = []
Zip::File.open(@word_doc) do |zip_file|
zip_file.each do |entry|
if entry.name.start_with?('word/media/') && !entry.directory?
filename = @process.employer_name.titleize.gsub(/\s+/, '').concat("Logo.png")
image_data = entry.get_input_stream.read
extracted_images << { filename: filename, data: image_data }
end
end
end
if extracted_images.length > 1
employer_logo = extracted_images.last
@process.employer_logo = employer_logo[:filename]
# same file logic
end
@process.save
end
end
end
@@ -0,0 +1,149 @@
module BenefitsWordDoc
class MapPlansInformation
def initialize(process, word_doc_section)
@process = process
@word_doc_section = word_doc_section
end
def call
search_fields = mapping_hash.keys.to_set
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 = @process.plans.create(title: @word_doc_section[plan_index])
plan_lines = @word_doc_section.slice(plan_index + 1, 14)
plan_lines.each_with_index do |line, i|
matching_field = search_fields.detect { |field| line.include?(field) }
if matching_field
puts matching_field
field_mapping = mapping_hash[matching_field]
field_regex = field_mapping[:doc_to_process_regex]
field_value = line.match(field_regex)[1].strip
process_benefit_desc_field = field_mapping[:process_benefit_desc_field]
puts process_benefit_desc_field
puts new_plan.plan_benefits.map { |b| b.benefit_desc}
new_benefit = new_plan.plan_benefits.find_by(benefit_desc: process_benefit_desc_field)
new_benefit.benefit = field_value
new_benefit.save
end
end
end
end
private
def mapping_hash
{
'Physician Visit' => {
process_field: :benefit,
process_benefit_desc_field: 'Primary Visit',
doc_field_desc: 'Follows pattern - Physician Visit$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Specialist Visit' => {
process_field: :benefit,
process_benefit_desc_field: 'Specialist Visit',
doc_field_desc: 'Follows pattern - Specialist Visit$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Urgent Care' => {
process_field: :benefit,
process_benefit_desc_field: 'Urgent Care',
doc_field_desc: 'Follows pattern - Urgent Care$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Individual Deductible (in network )' => {
process_field: :benefit,
process_benefit_desc_field: 'INNInd Ded',
doc_field_desc: 'Follows pattern - Individual Deductible (in network )$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Family Deductible(in network )' => {
process_field: :benefit,
process_benefit_desc_field: 'INNFamily Ded',
doc_field_desc: 'Follows pattern - Family Deductible(in network )$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Individual Deductible (out of network)' => {
process_field: :benefit,
process_benefit_desc_field: 'OONInd Ded',
doc_field_desc: 'Follows pattern - Individual Deductible (out of network)$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Family Deductible (out of network)' => {
process_field: :benefit,
process_benefit_desc_field: 'OONFamily Ded',
doc_field_desc: 'Follows pattern - Family Deductible (out of network)$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Co-Insurance' => {
process_field: :benefit,
process_benefit_desc_field: 'Co-Insurance',
doc_field_desc: 'Follows pattern - Co-Insurance70%/30%',
doc_to_process_regex: /Co-Insurance(.*)/,
regex_desc: 'Grabs everything after field name'
},
'Out-of-Pocket(in network)' => {
process_field: :benefit,
process_benefit_desc_field: 'INNInd OOP',
doc_field_desc: 'Follows pattern - Out-of-Pocket(in network)$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Out-of-Pocket Family(in network)' => {
process_field: :benefit,
process_benefit_desc_field: 'INNFamily OOP',
doc_field_desc: 'Follows pattern - Out-of-Pocket Family(in network)$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Out-of-Pocket(out of network)' => {
process_field: :benefit,
process_benefit_desc_field: 'OONInd OOP',
doc_field_desc: 'Follows pattern - Out-of-Pocket(out of network)$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Out-of-Pocket Family (out of network)' => {
process_field: :benefit,
process_benefit_desc_field: 'OONFamily OOP',
doc_field_desc: 'Follows pattern - Out-of-Pocket Family (out of network)$x,xxx',
doc_to_process_regex: /\$(.*)/,
regex_desc: 'Grabs everything after dollar sign'
},
'Emergency Room' => {
process_field: :benefit,
process_benefit_desc_field: 'Emergency Room',
doc_field_desc: 'Follows pattern - Emergency RoomXxxxx',
doc_to_process_regex: /Emergency Room(.*)/,
regex_desc: 'Grabs everything after field name'
},
'Preventive Care' => {
process_field: :benefit,
process_benefit_desc_field: 'Preventive Care',
doc_field_desc: 'Follows pattern - Preventive Care100%',
doc_to_process_regex: /Preventive Care(.*)/,
regex_desc: 'Grabs everything after field name'
},
}
end
def is_number?(string)
true if Float(string) rescue false
end
def is_date?(string)
true if Date.parse rescue false
end
end
end