Browse Source

change get_question form method to prioritise the routed to questions

pull/434/head
Kat 3 years ago
parent
commit
26300cc70f
  1. 3
      app/helpers/interuption_screen_helper.rb
  2. 6
      app/models/form.rb
  3. 2
      app/models/form/question.rb
  4. 2
      app/models/validations/household_validations.rb

3
app/helpers/interuption_screen_helper.rb

@ -1,6 +1,7 @@
module InteruptionScreenHelper module InteruptionScreenHelper
def display_informative_text(informative_text, case_log) def display_informative_text(informative_text, case_log)
translation_questions = informative_text["argument"].map { |x| case_log.form.get_question(x) } translation_questions = informative_text["argument"].map { |x| case_log.form.get_question(x, case_log) }
begin begin
case translation_questions.count case translation_questions.count
when 2 when 2

6
app/models/form.rb

@ -24,8 +24,10 @@ class Form
pages.find { |p| p.id == id.to_s.underscore } pages.find { |p| p.id == id.to_s.underscore }
end end
def get_question(id) def get_question(id, case_log)
questions.find { |q| q.id == id.to_s.underscore } all_questions = questions.select { |q| q.id == id.to_s.underscore }
routed_question = all_questions.find { |q| q.page.routed_to?(case_log) }
routed_question || all_questions[0]
end end
def subsection_for_page(page) def subsection_for_page(page)

2
app/models/form/question.rb

@ -49,7 +49,7 @@ class Form::Question
return [] unless inferred_answers return [] unless inferred_answers
enabled_inferred_answers(inferred_answers, case_log).keys.map do |x| enabled_inferred_answers(inferred_answers, case_log).keys.map do |x|
form.get_question(x).label_from_value(case_log[x]) form.get_question(x, case_log).label_from_value(case_log[x])
end end
end end

2
app/models/validations/household_validations.rb

@ -88,7 +88,7 @@ module Validations::HouseholdValidations
end end
if record.is_internal_transfer? && [3, 4, 7, 9, 10, 13, 14, 19, 21, 23, 24, 25, 26, 27, 28, 29].include?(record.prevten) if record.is_internal_transfer? && [3, 4, 7, 9, 10, 13, 14, 19, 21, 23, 24, 25, 26, 27, 28, 29].include?(record.prevten)
label = record.form.get_question("prevten").present? ? record.form.get_question("prevten").label_from_value(record.prevten) : "" label = record.form.get_question("prevten", record).present? ? record.form.get_question("prevten", record).label_from_value(record.prevten) : ""
record.errors.add :prevten, I18n.t("validations.household.prevten.internal_transfer", prevten: label) record.errors.add :prevten, I18n.t("validations.household.prevten.internal_transfer", prevten: label)
record.errors.add :referral, I18n.t("validations.household.referral.prevten_invalid", prevten: label) record.errors.add :referral, I18n.t("validations.household.referral.prevten_invalid", prevten: label)
end end

Loading…
Cancel
Save