92 lines
2.7 KiB
Ruby
92 lines
2.7 KiB
Ruby
class MedicalRelease < ApplicationRecord
|
|
include Contractable
|
|
include Notable
|
|
include Photoable
|
|
include Releasable
|
|
include Searchable
|
|
include Signable
|
|
include Syncable
|
|
include PersonName
|
|
include GuardianPhotoable
|
|
include SecondGuardianPhotoable
|
|
include GuardianName
|
|
include SecondGuardianName
|
|
|
|
NUMBER_OF_CUSTOM_FIELDS = 15
|
|
|
|
composed_of :person_address,
|
|
class_name: "Address",
|
|
mapping: [
|
|
%w(person_address_street1 street1),
|
|
%w(person_address_street2 street2),
|
|
%w(person_address_city city),
|
|
%w(person_address_state state),
|
|
%w(person_address_zip zip),
|
|
%w(person_address_country country)
|
|
]
|
|
|
|
def self.face_photo_acceptable_content_types
|
|
["image/png", "image/jpeg"]
|
|
end
|
|
|
|
# These validations apply to all releases
|
|
validates :person_first_name, :person_last_name, presence: true
|
|
validates :person_email, email: true, allow_blank: true
|
|
validate :valid_answers
|
|
|
|
acts_as_taggable_on :internal_tags, :tags
|
|
|
|
# These validations apply to releases being signed by a minor
|
|
with_options if: :minor? do
|
|
validates :guardian_email, email: true, allow_blank: true
|
|
validates :guardian_2_email, email: true, allow_blank: true
|
|
end
|
|
|
|
# These validations apply to releases created natively by the system (i.e. not imported from elsewhere)
|
|
with_options on: :native do
|
|
validates :signature, attached: true
|
|
end
|
|
|
|
# These validations apply to releases imported to the system from an outside source
|
|
with_options on: :non_native do
|
|
validates :contract, attached: true
|
|
end
|
|
|
|
searchable_on %i[
|
|
person_first_name person_last_name person_email person_phone
|
|
person_address_street1 person_address_street2 person_address_city person_address_state person_address_zip person_address_country
|
|
]
|
|
|
|
# All releases must respond to the following messages
|
|
def name
|
|
person_name
|
|
end
|
|
|
|
def filename_suffix
|
|
"#{person_last_name} #{person_first_name}"
|
|
end
|
|
|
|
def contact_person
|
|
@contact_person ||= Contact.new(person_name, person_address, person_email, person_phone)
|
|
end
|
|
|
|
def uses_edl?
|
|
false
|
|
end
|
|
|
|
def contract_file_name
|
|
"#{project.name.parameterize}_#{contract_template.release_type}_#{(signed_at || created_at).strftime("%Y.%m.%d")}_#{release_number}_#{filename_suffix.parameterize}"
|
|
end
|
|
|
|
private
|
|
|
|
def valid_answers
|
|
(1..ContractTemplate::NUMBER_OF_CUSTOM_FIELDS).each do |index|
|
|
if contract_template && contract_template["question_#{index}_text"].present? &&
|
|
public_send("question_#{index}_answer").blank?
|
|
errors.add("question_#{index}", I18n.t('medical_releases.custom_validation_errors.question_answer_is_required'))
|
|
end
|
|
end
|
|
end
|
|
end
|