|
|
|
@ -10,24 +10,50 @@ module CheckAnswersHelper
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def total_questions(subsection, case_log, form) |
|
|
|
|
questions = form.questions_for_subsection(subsection) |
|
|
|
|
questions_not_applicable = [] |
|
|
|
|
questions.reject do |question_key, question| |
|
|
|
|
question.fetch("conditional_for", []).map do |conditional_question_key, condition| |
|
|
|
|
if condition_not_met(case_log, question_key, question, condition) |
|
|
|
|
questions_not_applicable << conditional_question_key |
|
|
|
|
total_questions = {} |
|
|
|
|
page_name = form.pages_for_subsection(subsection).keys.first |
|
|
|
|
|
|
|
|
|
while page_name != "check_answers" && page_name != :check_answers |
|
|
|
|
questions = form.questions_for_page(page_name) |
|
|
|
|
question_key = questions.keys[0] |
|
|
|
|
question_value = questions.values[0] |
|
|
|
|
|
|
|
|
|
appliccable_questions = filter_conditional_questions(questions, case_log) |
|
|
|
|
total_questions = total_questions.merge(appliccable_questions) |
|
|
|
|
|
|
|
|
|
page_name = get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
total_questions |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def filter_conditional_questions(questions, case_log) |
|
|
|
|
appliccable_questions = questions |
|
|
|
|
|
|
|
|
|
questions.each do |k, question| |
|
|
|
|
question.fetch("conditional_for", []).each do |conditional_question_key, condition| |
|
|
|
|
if condition_not_met(case_log, k, question, condition) |
|
|
|
|
appliccable_questions = appliccable_questions.reject { |z| z == conditional_question_key } |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
#check_answers is not a real page |
|
|
|
|
question.fetch("conditional_route_to", []).reject { |q| q == "check_answers" }.map do |conditional_page_key, condition| |
|
|
|
|
if condition_not_met(case_log, question_key, question, condition) |
|
|
|
|
questions_not_applicable += form.questions_for_page(conditional_page_key).keys |
|
|
|
|
end |
|
|
|
|
appliccable_questions |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) |
|
|
|
|
new_page_name = form.next_page(page_name) |
|
|
|
|
if form.all_pages[page_name].key?("default_next_page") |
|
|
|
|
new_page_name = form.all_pages[page_name]["default_next_page"] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if appliccable_questions[question_key].key?("conditional_route_to") |
|
|
|
|
appliccable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition| |
|
|
|
|
unless condition_not_met(case_log, question_key, question_value, condition) |
|
|
|
|
new_page_name = conditional_page_key |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
# binding.pry |
|
|
|
|
questions_not_applicable.include?(question_key) |
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
new_page_name |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def condition_not_met(case_log, question_key, question, condition) |
|
|
|
|