Skip to content

Commit c10f162

Browse files
authored
Merge pull request #3961 from nhsuk/verbal-consent-follow-up-questions
Don't ask follow up root questions in verbal consent
2 parents d0e8c6b + f9ba5cf commit c10f162

5 files changed

Lines changed: 85 additions & 24 deletions

File tree

app/controllers/draft_consents_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def update
4242
@draft_consent.assign_attributes(update_params)
4343
end
4444

45+
@draft_consent.seed_health_questions if current_step == :agree
46+
4547
jump_to("confirm") if @draft_consent.editing? && current_step != :confirm
4648

4749
set_steps
@@ -85,9 +87,13 @@ def handle_confirm
8587
end
8688

8789
def handle_questions
88-
questions_attrs = update_params.except(:wizard_step).values
89-
@draft_consent.health_answers.each_with_index do |ha, index|
90-
ha.assign_attributes(questions_attrs[index])
90+
questions_attrs = update_params.except(:wizard_step)
91+
92+
@draft_consent.health_answers.each_with_index do |health_answer, index|
93+
attributes = questions_attrs["question_#{index}"]
94+
if health_answer.requires_notes?
95+
health_answer.assign_attributes(attributes)
96+
end
9197
end
9298

9399
@draft_consent.assign_attributes(wizard_step: current_step)

app/models/draft_consent.rb

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,40 @@ def vaccine_method_injection? = vaccine_methods.include?("injection")
355355

356356
def vaccine_method_nasal? = vaccine_methods.include?("nasal")
357357

358+
def seed_health_questions
359+
return unless response_given?
360+
361+
# If the health answers change due to the chosen vaccines changing, we
362+
# want to try and keep as much as what the parents already wrote intact.
363+
# We do this be saving the answers to the question title (as the IDs
364+
# and ordering can change).
365+
366+
existing_health_answers =
367+
health_answers.each_with_object({}) do |health_answer, memo|
368+
memo[health_answer.question] = {
369+
response: health_answer.response,
370+
notes: health_answer.notes
371+
}
372+
end
373+
374+
vaccines = programme.vaccines.where(method: vaccine_methods)
375+
376+
self.health_answers =
377+
HealthAnswersDeduplicator
378+
.call(vaccines:)
379+
.map do |health_answer|
380+
if (
381+
existing_health_answer =
382+
existing_health_answers[health_answer.question]
383+
)
384+
health_answer.response = existing_health_answer[:response]
385+
health_answer.notes = existing_health_answer[:notes]
386+
end
387+
388+
health_answer
389+
end
390+
end
391+
358392
private
359393

360394
def readable_attribute_names
@@ -393,6 +427,8 @@ def health_answers_are_valid
393427
return if health_answers.map(&:valid?).all?
394428

395429
health_answers.each_with_index do |health_answer, index|
430+
next unless health_answer.requires_notes?
431+
396432
health_answer.errors.messages.each do |field, messages|
397433
messages.each do |message|
398434
errors.add("question-#{index}-#{field}", message)
@@ -408,10 +444,7 @@ def reset_unused_fields
408444
self.notes = "" unless notes_required?
409445

410446
if response_given?
411-
if health_answers.empty?
412-
vaccine = programme.vaccines.first # assumes all vaccines in the programme have the same questions
413-
self.health_answers = vaccine.health_questions.to_health_answers
414-
end
447+
seed_health_questions if health_answers.empty?
415448
else
416449
self.health_answers = []
417450
end

app/views/draft_consents/questions.html.erb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
<% content_for(:before_content) { f.govuk_error_summary } %>
1616

1717
<% @draft_consent.health_answers.each_with_index do |health_answer, index| %>
18-
<%= f.fields_for "question_#{index}", health_answer do |ff| %>
19-
<%= ff.govuk_radio_buttons_fieldset(:question,
20-
legend: { size: "s", text: health_answer.question },
21-
hint: { text: health_answer.hint }) do %>
22-
<%= ff.govuk_radio_button :response, "yes",
23-
label: { text: "Yes" },
24-
link_errors: true do %>
25-
<%= ff.govuk_text_area :notes,
26-
label: { text: "Give details" } %>
18+
<% if health_answer.requires_notes? %>
19+
<%= f.fields_for "question_#{index}", health_answer do |ff| %>
20+
<%= ff.govuk_radio_buttons_fieldset :question,
21+
legend: { size: "s", text: health_answer.question },
22+
hint: { text: health_answer.hint } do %>
23+
<%= ff.govuk_radio_button :response, "yes",
24+
label: { text: "Yes" },
25+
link_errors: true do %>
26+
<%= ff.govuk_text_area :notes, label: { text: "Give details" } %>
27+
<% end %>
28+
29+
<%= ff.govuk_radio_button :response, "no", label: { text: "No" } %>
2730
<% end %>
28-
<%= ff.govuk_radio_button :response, "no",
29-
label: { text: "No" } %>
3031
<% end %>
3132
<% end %>
3233
<% end %>

spec/features/self_consent_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def and_the_nurse_records_consent_for_the_child
237237

238238
def and_the_child_can_give_their_own_consent_that_the_nurse_records
239239
click_on "Change method"
240+
240241
choose "Child (Gillick competent)"
241242
5.times { click_on "Continue" }
242243

spec/features/verbal_consent_given_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
# frozen_string_literal: true
22

33
describe "Verbal consent" do
4-
scenario "Given" do
4+
scenario "Given HPV" do
55
given_an_hpv_programme_is_underway
66
and_i_am_signed_in
7+
78
when_i_record_that_verbal_consent_was_given
89
then_an_email_is_sent_to_the_parent_confirming_their_consent
910
and_a_text_is_sent_to_the_parent_confirming_their_consent
1011
and_the_patients_status_is_safe_to_vaccinate
1112
and_i_can_see_the_consent_response_details
1213
end
1314

14-
scenario "Given flu nasal consent" do
15+
scenario "Given flu nasal spray" do
1516
given_an_flu_programme_is_underway
1617
and_i_am_signed_in
18+
1719
when_i_record_that_verbal_nasal_consent_was_given
1820
and_the_patients_status_is_safe_to_vaccinate_with_nasal_spray
1921
end
2022

23+
scenario "Given flu nasal spray and injection" do
24+
given_an_flu_programme_is_underway
25+
and_i_am_signed_in
26+
27+
when_i_record_that_verbal_nasal_and_injection_consent_was_given
28+
end
29+
2130
def given_an_hpv_programme_is_underway
2231
create_programme(:hpv)
2332
end
@@ -41,19 +50,32 @@ def create_programme(programme_type)
4150
end
4251

4352
def when_i_record_that_verbal_consent_was_given
44-
record_that_verbal_consent_was_given(consent_option: "Yes, they agree")
53+
record_that_verbal_consent_was_given(
54+
consent_option: "Yes, they agree",
55+
number_of_health_questions: 4
56+
)
4557
end
4658

4759
def when_i_record_that_verbal_nasal_consent_was_given
4860
record_that_verbal_consent_was_given(
4961
consent_option: "Yes, for the nasal spray",
62+
number_of_health_questions: 9,
63+
triage_option: "Yes, it’s safe to vaccinate with nasal spray"
64+
)
65+
end
66+
67+
def when_i_record_that_verbal_nasal_and_injection_consent_was_given
68+
record_that_verbal_consent_was_given(
69+
consent_option: "Yes, for the nasal spray",
70+
number_of_health_questions: 10,
5071
triage_option: "Yes, it’s safe to vaccinate with nasal spray",
5172
injective_alternative: true
5273
)
5374
end
5475

5576
def record_that_verbal_consent_was_given(
5677
consent_option:,
78+
number_of_health_questions:,
5779
triage_option: "Yes, it’s safe to vaccinate",
5880
injective_alternative: false
5981
)
@@ -86,11 +108,9 @@ def record_that_verbal_consent_was_given(
86108
if consent_option.include?("nasal")
87109
choose injective_alternative ? "Yes" : "No"
88110
end
89-
90111
click_button "Continue"
91112

92-
# assumes all vaccines in the programme have the same questions
93-
@programme.vaccines.first.health_questions.size.times do |index|
113+
number_of_health_questions.times do |index|
94114
find_all(".nhsuk-fieldset")[index].choose "No"
95115
end
96116

0 commit comments

Comments
 (0)