DB restructure, print page

This commit is contained in:
Jason Jordan
2026-03-13 08:47:13 -04:00
parent 6a068243f4
commit 8c885b3e76
73 changed files with 1362 additions and 325 deletions
+2 -2
View File
@@ -5,11 +5,11 @@ module IdCard
private
def calculate_aspect_ratio
image_io = StringIO.new(self.image_data)
image_io = StringIO.new(image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
aspect_ratio = image_ratio.round(2)
end
end
end
-12
View File
@@ -1,12 +0,0 @@
module IdCard
class Exception < ApplicationRecord
belongs_to :setup
has_many :exception_items
accepts_nested_attributes_for :exception_items, allow_destroy: true, reject_if: :all_blank
VALID_TYPES = ['zipcode', 'state', 'family_id']
validates :type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
end
end
+35
View File
@@ -0,0 +1,35 @@
module IdCard
class FieldException < ApplicationRecord
belongs_to :configuration
has_many :field_exception_items, dependent: :destroy
accepts_nested_attributes_for :field_exception_items, allow_destroy: true, reject_if: :all_blank
VALID_TYPES = ['zipcode', 'state', 'family_id']
validates :exception_type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
class << self
def permitted_params(params)
params.require(:id_card_configuration).permit(
field_exceptions_attributes: [
:exception_type,
:exception_value,
:_destroy,
field_exception_items_attributes: [
:field_name,
:field_value,
:network_logo_id,
:provider_section_id,
:_destroy
]
]
)
end
end
end
end
+22 -4
View File
@@ -1,13 +1,31 @@
module IdCard
class NetworkLogo < ApplicationRecord
before_save :round_aspect_ratio
before_validation :calculate_aspect_ratio, if: :image_data_changed?
scope :defaults, -> { where(default: true) }
class << self
def medcost
defaults.where("filename LIKE ?", "%Medcost%")
end
def cigna
defaults.where("filename LIKE ?", "%Cigna%")
end
end
private
def round_aspect_ratio
if self.aspect_ratio.present?
self.aspect_ratio = self.aspect_ratio.round(2)
def calculate_aspect_ratio
image_io = StringIO.new(image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
end
end
end
end
+57 -16
View File
@@ -1,27 +1,68 @@
module IdCard
class Plan < ApplicationRecord
belongs_to :setup
belongs_to :configuration, optional: true
has_many :plan_benefits, dependent: :destroy
accepts_nested_attributes_for :plan_benefits, allow_destroy: true, reject_if: :all_blank
# after_initialize :create_default_benefits, if: :new_record?
scope :templates, -> { where(template: true) }
BENEFIT_FIELDS = ["Primary Visit",
"Specialist Visit",
"Urgent Care",
"INN-Ind Ded",
"INN-Family Ded",
"OON-Ind Ded",
"OON-Family Ded",
"Co-Insurance",
"INN-Ind OOP",
"INN-Family OOP",
"OON-Ind OOP",
"OON-Family OOP",
"Emergency Room",
"Preventive Care"].freeze
def self.permitted_params(params)
params.require(:id_card_plan).permit(
:title,
:pb_product_key,
:pl_plan_key,
:_destroy,
id_card_plan_benefits_attributes: [
:id,
:benefit_desc,
:benefit,
:sequence,
:_destroy,
]
)
after_initialize :build_plan_benefits, if: :new_record?
def build_plan_benefits
BENEFIT_FIELDS.each_with_index do |bene, i|
self.plan_benefits.build(benefit_desc: bene, sequence: (i + 1))
end
end
def format_template
formatted_title = title
if pl_plan_key.present?
employer_name = Employer.find_by(pl_plan_key: pl_plan_key).pluck(:name)
formatted_title.concat( " (#{employer_name})" )
end
{ id: id, title: formatted_title }
end
class << self
# def templates
# active_templates.map(&:format_template)
# end
def permitted_params(params)
params.require(:id_card_configuration).permit(
plans_attributes: [
:title,
:pb_product_key,
:pl_plan_key,
:_destroy,
plan_benefits_attributes: [
:id,
:benefit_desc,
:benefit,
:sequence,
:_destroy,
]
]
)
end
end
private
+31
View File
@@ -1,5 +1,36 @@
module IdCard
class ProviderSection < ApplicationRecord
scope :defaults, -> { where(default: true) }
def self.permitted_params(params)
params.require(:id_card_configuration).require(:provider_section).permit(
: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
)
end
end
end
+25 -4
View File
@@ -1,5 +1,5 @@
module IdCard
class Setup < ApplicationRecord
class Configuration < ApplicationRecord
belongs_to :employer, class_name: 'Employer'
belongs_to :employer_logo, optional: true
belongs_to :network_logo, optional: true
@@ -7,8 +7,17 @@ module IdCard
belongs_to :rx_section, optional: true
has_many :plans, dependent: :destroy
has_many :field_exceptions, dependent: :destroy
has_many :exceptions, dependent: :destroy
accepts_nested_attributes_for :plans, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :field_exceptions, allow_destroy: true, reject_if: :all_blank
attribute :queued_card_count, :integer, default: 0
scope :active, -> { where(active: true) }
FORM_COLORS = ['atmosphere', 'verdigris', 'bluemana', 'cobalt']
MODULE_COLOR = 'atmosphere'
# def employer_logo_filename
# self.employer_logo.filename
@@ -18,13 +27,25 @@ module IdCard
# self.network_logo.filename
# end
def build_plan_with_default_benefits(attributes = {})
plan = plans.new(attributes)
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
plan.plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
end
plan
end
def self.permitted_params(params)
params.require(:id_card_setup).permit(
params.require(:id_card_configuration).permit(
:print_name,
:network_provider,
:card_template,
:rx_group_number,
:id_card_employer_logo_id
:employer_logo_id,
:network_logo_id,
:rx_section_id,
:provider_section_id
)
end
end