|
|
|
@ -13,36 +13,36 @@ module CheckAnswersHelper
|
|
|
|
|
total_questions = {} |
|
|
|
|
page_name = form.pages_for_subsection(subsection).keys.first |
|
|
|
|
|
|
|
|
|
while page_name != "check_answers" && page_name != :check_answers |
|
|
|
|
while page_name.to_s != "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) |
|
|
|
|
applicable_questions = filter_conditional_questions(questions, case_log) |
|
|
|
|
total_questions = total_questions.merge(applicable_questions) |
|
|
|
|
|
|
|
|
|
page_name = get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) |
|
|
|
|
page_name = get_next_page_name(form, page_name, applicable_questions, question_key, case_log, question_value) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
total_questions |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def filter_conditional_questions(questions, case_log) |
|
|
|
|
appliccable_questions = questions |
|
|
|
|
applicable_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 } |
|
|
|
|
applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
appliccable_questions |
|
|
|
|
applicable_questions |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) |
|
|
|
|
if appliccable_questions[question_key].key?("conditional_route_to") |
|
|
|
|
appliccable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition| |
|
|
|
|
def get_next_page_name(form, page_name, applicable_questions, question_key, case_log, question_value) |
|
|
|
|
if applicable_questions[question_key].key?("conditional_route_to") |
|
|
|
|
applicable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition| |
|
|
|
|
unless condition_not_met(case_log, question_key, question_value, condition) |
|
|
|
|
return conditional_page_key |
|
|
|
|
end |
|
|
|
|