class DraftConsent
Constants
- FLU_RESPONSES
Attributes
Public Class Methods
Source
# File app/models/draft_consent.rb, line 48 def initialize(current_user:, **attributes) @current_user = current_user super(**attributes) end
Calls superclass method
RequestSessionPersistable::new
Public Instance Methods
Source
# File app/models/draft_consent.rb, line 457 def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end
Source
# File app/models/draft_consent.rb, line 196 def consent ConsentPolicy::Scope .new(@current_user, Consent) .resolve .find_by(id: editing_id) end
Source
# File app/models/draft_consent.rb, line 203 def consent=(value) self.editing_id = value.id end
Source
# File app/models/draft_consent.rb, line 368 def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.
Source
# File app/models/draft_consent.rb, line 430 def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers = [] end
Source
# File app/models/draft_consent.rb, line 352 def flu_response? FLU_RESPONSES.include?(response) end
Source
# File app/models/draft_consent.rb, line 346 def follow_up_flow? = follow_up_flow == true def via_self_consent? = route == "self_consent" def send_confirmation? = notify_parent_on_refusal != false def flu_response? FLU_RESPONSES.include?(response) end def response_given? response == "given" || FLU_RESPONSES.include?(response) end def response_refused? = response == "refused" def responded_at = Time.current def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given?
Source
# File app/models/draft_consent.rb, line 479 def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end
Source
# File app/models/draft_consent.rb, line 381 def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end
Source
# File app/models/draft_consent.rb, line 364 def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else
Source
# File app/models/draft_consent.rb, line 428 def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers = []
Source
# File app/models/draft_consent.rb, line 177 def new_or_existing_contact=(value) @new_or_existing_contact = value if value == "new" self.route = nil self.parent = nil elsif value == "patient" self.route = "self_consent" self.parent = nil else self.route = nil self.parent = patient.parents.find_by(id: value) || Parent.where( consents: patient.consents.for_programme(programme) ).find_by(id: value) end end
Source
# File app/models/draft_consent.rb, line 242 def parent return nil if via_self_consent? parent = Parent.find_by(id: parent_id) || Parent.new parent.email = parent_email parent.full_name = parent_full_name parent.phone = parent_phone parent.phone_receive_updates = parent_phone_receive_updates # We can't use find_or_initialize_by here because we need the object to # remain attached to the parent so we can save the parent with its # relationships. parent_relationship = parent.parent_relationships.find { it.patient_id == patient_id } || parent.parent_relationships.build(patient_id:) parent_relationship.assign_attributes( patient:, # acts as preload type: parent_relationship_type, other_name: parent_relationship_other_name ) if parent_relationship.new_record? parent.parent_relationships << parent_relationship end parent end
Source
# File app/models/draft_consent.rb, line 273 def parent=(value) self.parent_id = value&.id parent_relationship = value&.parent_relationships&.find_by(patient_id:) self.parent_email = patient.restricted? ? "" : value&.email self.parent_full_name = value&.full_name self.parent_phone = patient.restricted? ? "" : value&.phone self.parent_phone_receive_updates = value&.phone_receive_updates self.parent_relationship_type = parent_relationship&.type self.parent_relationship_other_name = parent_relationship&.other_name self.parent_responsibility = value ? true : nil end
Source
# File app/models/draft_consent.rb, line 370 def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end
Source
# File app/models/draft_consent.rb, line 287 def patient return nil if patient_id.nil? PatientPolicy::Scope.new(@current_user, Patient).resolve.find(patient_id) end
Source
# File app/models/draft_consent.rb, line 293 def patient=(value) self.patient_id = value.id end
Source
# File app/models/draft_consent.rb, line 432 def readable_attribute_names writable_attribute_names + %w[parent] end
Source
# File app/models/draft_consent.rb, line 297 def recorded_by return nil if recorded_by_user_id.nil? User.find(recorded_by_user_id) end
Source
# File app/models/draft_consent.rb, line 303 def recorded_by=(value) self.recorded_by_user_id = value.id end
Source
# File app/models/draft_consent.rb, line 493 def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers = [] end end end
Source
# File app/models/draft_consent.rb, line 462 def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end
Source
# File app/models/draft_consent.rb, line 475 def requires_triage? response_given? && health_answers_require_triage? end
Source
# File app/models/draft_consent.rb, line 495 def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers = [] end end
Source
# File app/models/draft_consent.rb, line 362 def responded_at = Time.current def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty?
Source
# File app/models/draft_consent.rb, line 356 def response_given? response == "given" || FLU_RESPONSES.include?(response) end
Source
# File app/models/draft_consent.rb, line 360 def response_refused? = response == "refused" def responded_at = Time.current def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.
Source
# File app/models/draft_consent.rb, line 391 def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end
Source
# File app/models/draft_consent.rb, line 350 def send_confirmation? = notify_parent_on_refusal != false def flu_response? FLU_RESPONSES.include?(response) end def response_given? response == "given" || FLU_RESPONSES.include?(response) end def response_refused? = response == "refused" def responded_at = Time.current def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if
Source
# File app/models/draft_consent.rb, line 307 def session return nil if session_id.nil? SessionPolicy::Scope.new(@current_user, Session).resolve.find(session_id) end
Source
# File app/models/draft_consent.rb, line 313 def session=(value) self.session_id = value.id self.academic_year = value.academic_year end
Source
# File app/models/draft_consent.rb, line 320 def team_id = team&.id def write_to!(consent, triage_form:) self.response = "given" if flu_response? super(consent) consent.parent = parent consent.parent_full_name = parent_full_name consent.parent_email = parent_email consent.parent_phone = parent_phone consent.parent_phone_receive_updates = parent_phone_receive_updates consent.parent_relationship_type = parent_relationship_type consent.parent_relationship_other_name = parent_relationship_other_name consent.submitted_at ||= Time.current consent.academic_year = academic_year if academic_year.present? if triage_allowed? && requires_triage? triage_form.add_patient_specific_direction = triage_add_patient_specific_direction triage_form.current_user = recorded_by triage_form.delay_vaccination_until = triage_delay_vaccination_until triage_form.notes = triage_notes || "" triage_form.status_option = triage_status_option end end def follow_up_flow? = follow_up_flow == true def via_self_consent? = route == "self_consent" def send_confirmation? = notify_parent_on_refusal != false def flu_response? FLU_RESPONSES.include?(response) end def response_given? response == "given" || FLU_RESPONSES.include?(response) end def response_refused? = response == "refused" def responded_at = Time.current def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given?
Source
# File app/models/draft_consent.rb, line 467 def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end
Source
# File app/models/draft_consent.rb, line 471 def triage_status_options Triage.new(patient:, programme:).status_options end
Source
# File app/models/draft_consent.rb, line 229 def update_disease_types return if programme_type.nil? self.disease_types = if eligible_for_mmrv? && vaccine_stock_is_available Programme::Variant::DISEASE_TYPES["mmrv"] elsif is_mmr? Programme::Variant::DISEASE_TYPES["mmr"] else Programme::DISEASE_TYPES[programme_type] end end
Source
# File app/models/draft_consent.rb, line 207 def update_vaccine_methods_and_without_gelatine if flu_response? if response == "given_nasal" self.vaccine_methods = ["nasal"] self.without_gelatine = false vaccine_methods << "injection" if injection_alternative elsif response == "given_injection" self.vaccine_methods = ["injection"] self.without_gelatine = true self.injection_alternative = nil end elsif response_given? self.vaccine_methods = ["injection"] self.without_gelatine ||= false self.injection_alternative = nil else self.vaccine_methods = [] self.without_gelatine = nil self.injection_alternative = nil end end
Source
# File app/models/draft_consent.rb, line 385 def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers
Source
# File app/models/draft_consent.rb, line 387 def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers =
Source
# File app/models/draft_consent.rb, line 389 def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers = []
Source
# File app/models/draft_consent.rb, line 455 def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else self.health_answers = [] end end
Source
# File app/models/draft_consent.rb, line 348 def via_self_consent? = route == "self_consent" def send_confirmation? = notify_parent_on_refusal != false def flu_response? FLU_RESPONSES.include?(response) end def response_given? response == "given" || FLU_RESPONSES.include?(response) end def response_refused? = response == "refused" def responded_at = Time.current def invalidated? = false def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions
Source
# File app/models/draft_consent.rb, line 366 def withdrawn? = false def consent_form = nil def parent_relationship parent &.parent_relationships &.find { it.patient_id == patient_id } &.tap do it.patient = patient # acts as preload it.type = parent_relationship_type it.other_name = parent_relationship_other_name end end def human_enum_name(attribute) Consent.human_enum_name(attribute, send(attribute)) end def vaccine_method_injection? = vaccine_methods.include?("injection") def vaccine_method_nasal? = vaccine_methods.include?("nasal") def vaccine_method_nasal_only? = vaccine_methods == %w[nasal] def seed_health_questions return unless response_given? # If the health answers change due to the chosen vaccines changing, we # want to try and keep as much as what the parents already wrote intact. # We do this be saving the answers to the question title (as the IDs # and ordering can change). existing_health_answers = health_answers.each_with_object({}) do |health_answer, memo| memo[health_answer.question] = { response: health_answer.response, notes: health_answer.notes } end vaccines = VaccineCriteria.from_consentable(self).apply(programme.vaccines.active) self.health_answers = HealthAnswersDeduplicator .call(vaccines:) .map do |health_answer| if ( existing_health_answer = existing_health_answers[health_answer.question] ) health_answer.response = existing_health_answer[:response] health_answer.notes = existing_health_answer[:notes] end health_answer end end private def is_mmr? = programme_type == "mmr" def eligible_for_mmrv? = is_mmr? && patient&.eligible_for_mmrv? def readable_attribute_names writable_attribute_names + %w[parent] end def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end def vaccines = programme.vaccines def ask_notify_parent_on_refusal? response_refused? && reason_for_refusal == "personal_choice" && !via_self_consent? end def requires_notes? response_refused? && reason_for_refusal.in?(Consent::REASON_FOR_REFUSAL_REQUIRES_NOTES) end def triage_allowed? TriagePolicy.new(@current_user, Triage).new? end def triage_status_options Triage.new(patient:, programme:).status_options end def requires_triage? response_given? && health_answers_require_triage? end def health_answers_are_valid return if health_answers.map(&:valid?).all? health_answers.each_with_index do |health_answer, index| next unless health_answer.ask_notes? health_answer.errors.messages.each do |field, messages| messages.each do |message| errors.add("question-#{index}-#{field}", message) end end end end def request_session_key = "consent" def reset_unused_attributes update_vaccine_methods_and_without_gelatine update_disease_types self.notes = "" unless requires_notes? self.notify_parent_on_refusal = nil unless ask_notify_parent_on_refusal? self.reason_for_refusal = nil unless response_refused? if response_given? seed_health_questions if health_answers.empty? else
Source
# File app/models/draft_consent.rb, line 55 def wizard_steps [ (:who unless follow_up_flow?), (:parent_details unless via_self_consent?), (:route unless via_self_consent?), (:mmrv_vaccine_availability if eligible_for_mmrv?), :agree, (:notify_parents_on_vaccination if response_given? && via_self_consent?), (:questions if response_given?), (:triage if triage_allowed? && requires_triage?), (:reason_for_refusal if response_refused?), (:notify_parent_on_refusal if ask_notify_parent_on_refusal?), (:notes if requires_notes?), :confirm ].compact end
Source
# File app/models/draft_consent.rb, line 436 def writable_attribute_names %w[ disease_types health_answers notes notify_parent_on_refusal notify_parents_on_vaccination patient_id programme_type reason_for_refusal recorded_by_user_id response route team_id vaccine_methods without_gelatine ] end
Source
# File app/models/draft_consent.rb, line 322 def write_to!(consent, triage_form:) self.response = "given" if flu_response? super(consent) consent.parent = parent consent.parent_full_name = parent_full_name consent.parent_email = parent_email consent.parent_phone = parent_phone consent.parent_phone_receive_updates = parent_phone_receive_updates consent.parent_relationship_type = parent_relationship_type consent.parent_relationship_other_name = parent_relationship_other_name consent.submitted_at ||= Time.current consent.academic_year = academic_year if academic_year.present? if triage_allowed? && requires_triage? triage_form.add_patient_specific_direction = triage_add_patient_specific_direction triage_form.current_user = recorded_by triage_form.delay_vaccination_until = triage_delay_vaccination_until triage_form.notes = triage_notes || "" triage_form.status_option = triage_status_option end end
Calls superclass method
EditableWrapper#write_to!