Major features finished

This commit is contained in:
Jason Jordan
2026-04-15 08:12:47 -04:00
parent 9f306d3150
commit 247a075c9c
112 changed files with 3700 additions and 379 deletions
+39 -5
View File
@@ -1,16 +1,50 @@
module IdCard
class EmployerLogo < ApplicationRecord
before_validation :calculate_aspect_ratio, if: :image_data_changed?
# before_validation :resize_logo, if: :image_data_changed?
# before_validation :calculate_aspect_ratio, if: :image_data_changed?
before_validation :process_image, if: :image_data_changed?
private
def calculate_aspect_ratio
image_io = StringIO.new(self.image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
def process_image
image = Vips::Image.new_from_buffer(self.image_data, "")
resized_image = ImageProcessing::Vips
.source(image)
.resize_to_limit(nil, 400)
processed_image = resized_image.convert("png").call
new_image_data = processed_image.read
if new_image_data
self.image_data = new_image_data
self.filename = File.basename(self.filename, File.extname(self.filename)) + ".png"
self.content_type = "image/png"
end
image_ratio = image.width.to_f / image.height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
end
end
# def resize_logo
# image = Vips::Image.new_from_buffer(self.image_data, "")
# processed_image = ImageProcessing::Vips
# .source(image)
# .resize_to_limit(nil, 200)
# .call
# self.image_data = processed_image.read
# end
# def calculate_aspect_ratio
# image_io = StringIO.new(self.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
+18 -2
View File
@@ -4,19 +4,27 @@ module IdCard
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']
serialize :exception_values, coder: JSON
VALID_TYPES = ['family_id', 'zipcode', 'state'].freeze
before_validation :format_exception_values, if: :exception_values_changed?
validates :exception_type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
def to_card_attrs
self.field_exception_items.map(&:card_attrs).reduce({}, :merge)
end
class << self
def permitted_params(params)
params.require(:id_card_setup).permit(
field_exceptions_attributes: [
:exception_type,
:exception_value,
:exception_values,
:_destroy,
field_exception_items_attributes: [
:field_name,
@@ -31,5 +39,13 @@ module IdCard
end
private
def format_exception_values
if self.exception_values.is_a?(String)
self.exception_values = self.exception_values.split(",").map(&:strip)
end
end
end
end
+18 -2
View File
@@ -6,14 +6,30 @@ module IdCard
validate :only_one_exception_field_present
FIELDS_TO_VALIDATE = [:field_value, :card_logo_file_id, :card_provider_id].freeze
FIELDS_TO_VALIDATE = [:field_value, :network_logo_id, :provider_section_id].freeze
VALID_FIELD_NAMES = ['network_logo', 'provider_section', 'effective_date']
VALID_FIELD_NAMES = ['network_logo', 'provider_section', 'medical_eff_date']
validates :field_name, inclusion: { in: VALID_FIELD_NAMES,
message: "%{value} is not a valid Id Card Field Name" }
def card_attrs
case self.field_name
when "network_logo"
{"network_logo_filename" => IdCard::NetworkLogo.find(self.network_logo_id).filename}
when "provider_section"
IdCard::ProviderSection.find(self.provider_section_id).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
)
when "medical_eff_date"
{"medical_eff_date" => self.field_value}
end
end
private
def only_one_exception_field_present
+39 -5
View File
@@ -1,6 +1,8 @@
module IdCard
class NetworkLogo < ApplicationRecord
before_validation :calculate_aspect_ratio, if: :image_data_changed?
# before_validation :resize_logo, if: :image_data_changed?
# before_validation :calculate_aspect_ratio, if: :image_data_changed?
before_validation :process_image, if: :image_data_changed?
scope :defaults, -> { where(default: true) }
@@ -18,14 +20,46 @@ module IdCard
private
def calculate_aspect_ratio
image_io = StringIO.new(image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
def process_image
image = Vips::Image.new_from_buffer(self.image_data, "")
resized_image = ImageProcessing::Vips
.source(image)
.resize_to_limit(nil, 400)
processed_image = resized_image.convert("png").call
new_image_data = processed_image.read
if new_image_data
self.image_data = new_image_data
self.filename = File.basename(self.filename, File.extname(self.filename)) + ".png"
self.content_type = "image/png"
end
image_ratio = image.width.to_f / image.height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
end
end
# def resize_logo
# image = Vips::Image.new_from_buffer(self.image_data, "")
# processed_image = ImageProcessing::Vips
# .source(image)
# .resize_to_limit(nil, 400)
# .call
# self.image_data = processed_image.read
# end
# 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
+1 -1
View File
@@ -1,7 +1,7 @@
module IdCard
class PrintData < ApplicationRecord
STRING_ATTRIBUTES = %w[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 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 dependent_1 dependent_2 dependent_3 dependent_4 dependent_5 dependent_6 dependent_7 dependent_8]
STRING_ATTRIBUTES = %w[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 dependent_1 dependent_2 dependent_3 dependent_4 dependent_5 dependent_6 dependent_7 dependent_8 dental_coverage]
before_validation :assign_blank_strings_to_unassigned_params
+39
View File
@@ -40,6 +40,45 @@ module IdCard
self.field_exceptions.present?
end
def field_exceptions_card_attributes_by_member_id(member_array = nil)
unless member_array.present?
member_array = self.employer.members.pluck(:pb_entity_key)
end
card_fes = self.field_exceptions.includes(:field_exception_items).in_order_of(:exception_type, IdCard::FieldException::VALID_TYPES)
# fe_by_value = card_fes.in_order_of(:exception_type, IdCard::FieldException::VALID_TYPES).group_by(&:exception_type)
# .transform_values { |fes| fes.map { |fe| [fe.id, fe.exception_values] }.to_h }
# .compact_blank
# field_exception_types = card_fes.pluck(:exception_type).uniq
# if field_exception_types.include?("family_id")
# members = Member.where(pb_entity_key: member_array)
# end
# if field_exception_types.intersect?(["state", "zipcode"])
# member_addresses = Vhcs::PbEntityAddress.where(pb_entity_key: member_array)
# end
card_exceptions_map = {}
card_fes.each do |fe|
if fe.exception_type == "family_id"
matches = Member.where(pb_entity_key: member_array, family_id: fe.exception_values).pluck(:pb_entity_key)
elsif fe.exception_type == "zipcode"
matches = Vhcs::PbEntityAddress.where(pb_entity_key: member_array, zip: fe.exception_values).pluck(:pb_entity_key)
elsif fe.exception_type == "state"
matches = Vhcs::PbEntityAddress.where(pb_entity_key: member_array, state: fe.exception_values).pluck(:pb_entity_key)
end
if matches.present?
card_exceptions_map[fe.id] = fe.to_card_attrs
matches.each do |match|
unless card_exceptions_map[match].present?
card_exceptions_map[match] = fe.id
end
end
end
end
card_exceptions_map
end
def self.permitted_params(params)
params.require(:id_card_setup).permit(
:print_name,