Skip to content

Commit a0ed5a6

Browse files
authored
Merge pull request #5564 from nhsuk/restore-add-programmes
Allow editing programmes at any point
2 parents deb0bfb + f3f688c commit a0ed5a6

9 files changed

Lines changed: 128 additions & 61 deletions

File tree

app/controllers/draft_sessions_controller.rb

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DraftSessionsController < ApplicationController
1010
before_action :set_programmes, if: -> { current_step == :programmes }
1111
before_action :set_year_group_options, if: -> { current_step == :year_groups }
1212

13-
with_options only: :show, if: -> { current_step == :dates_check } do
13+
with_options only: :show, if: :is_check_step? do
1414
before_action :set_catch_up_year_groups
1515
before_action :set_catch_up_patients_vaccinated_percentage
1616
before_action :set_catch_up_patients_receiving_consent_requests_count
@@ -24,7 +24,7 @@ class DraftSessionsController < ApplicationController
2424
def show
2525
authorize @session, @session.new_record? ? :new? : :edit?
2626

27-
skip_step if current_step == :dates_check && should_skip_dates_check?
27+
skip_step if is_check_step? && should_skip_check?
2828

2929
render_wizard
3030
end
@@ -50,6 +50,8 @@ def update
5050

5151
private
5252

53+
def is_check_step? = step.end_with?("-check")
54+
5355
def is_confirm_step? = step == "confirm"
5456

5557
def set_draft_session
@@ -191,11 +193,11 @@ def set_back_link_path
191193
wizard_path("dates")
192194
elsif current_step == @draft_session.wizard_steps.first
193195
@draft_session.return_to == "school" ? schools_path : sessions_path
194-
elsif previous_step == "dates-check"
195-
# The `dates-check` page is special in that it skips forward if it
196-
# doesn't need to be shown, however this leads to users getting stuck
197-
# in a loop.
198-
wizard_path("dates")
196+
elsif is_check_step?
197+
# The checks page are special in that they skip forward if they don't
198+
# need to be shown, however this leads to users getting stuck in a
199+
# loop.
200+
wizard_path(previous_step.split("-").first)
199201
else
200202
previous_wizard_path
201203
end
@@ -284,6 +286,7 @@ def update_params
284286
programmes: {
285287
programme_types: []
286288
},
289+
programmes_check: [],
287290
register_attendance: %i[requires_registration],
288291
school: %i[location_id],
289292
year_groups: {
@@ -333,7 +336,12 @@ def go_to_confirm_after_submission?
333336
# means we can't always skip straight to the confirmation page.
334337

335338
if current_step == :dates && steps.include?("dates-check") &&
336-
!should_skip_dates_check?
339+
!should_skip_check?
340+
return false
341+
end
342+
343+
if current_step == :programmes && steps.include?("programmes-check") &&
344+
!should_skip_check?
337345
return false
338346
end
339347

@@ -348,19 +356,29 @@ def go_to_confirm_after_submission?
348356
return !is_confirm_step?
349357
end
350358

359+
# When first creating a session we go straight to the confirmation page
360+
# after setting the dates.
361+
351362
current_step == :dates_check ||
352363
(
353364
current_step == :dates && steps.include?("dates-check") &&
354-
should_skip_dates_check?
365+
should_skip_check?
355366
) || (current_step == :dates && !steps.include?("dates-check"))
356367
end
357368

358-
def should_skip_dates_check?
369+
def should_skip_check?
359370
if @draft_session.editing? &&
371+
@draft_session.session.programme_types ==
372+
@draft_session.programme_types &&
360373
@draft_session.session.dates == @draft_session.dates
361374
return true
362375
end
363376

377+
if @draft_session.programme_types.empty? ||
378+
@draft_session.year_groups.empty? || @draft_session.dates.empty?
379+
return true
380+
end
381+
364382
any_programme_has_high_unvaccinated_count =
365383
@draft_session.programmes.any? do |programme|
366384
programme_has_high_unvaccinated_count?(programme)

app/models/draft_session.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def wizard_steps
4040
steps << :school if school? && !editing?
4141

4242
steps << :programmes
43+
steps << :programmes_check
4344
steps << :year_groups if school? && !editing?
4445

4546
steps << :dates
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<% content_for :before_main do %>
2+
<%= govuk_back_link(href: @back_link_path) %>
3+
<% end %>
4+
5+
<% title = "Have you imported historical vaccination records for #{@draft_session.programmes.map(&:name).to_sentence}?" %>
6+
<% content_for :page_title, title %>
7+
8+
<%= govuk_panel(title_text: title, classes: %w[app-panel--interruption]) do %>
9+
<p>
10+
<%= @catch_up_patients_vaccinated_percentage == 0 ? "" : "Only " %>
11+
<%= @catch_up_patients_vaccinated_percentage %>% of children in
12+
<%= format_year_groups(@catch_up_year_groups) %> in
13+
this session have vaccination records. This is unusually low coverage for
14+
catch-up year groups.
15+
</p>
16+
17+
<p>
18+
Check and confirm that vaccination records have been imported for all
19+
children in this school before you continue.
20+
</p>
21+
22+
<% if @draft_session.open_for_consent? && @catch_up_patients_receiving_consent_requests_count > 0 %>
23+
<p>
24+
Scheduling this session now will send consent requests to
25+
<%= pluralize(@catch_up_patients_receiving_consent_requests_count, "parent") %>
26+
of children in <%= format_year_groups(@catch_up_year_groups) %> on
27+
<%= @draft_session.send_consent_requests_at.to_fs(:long) %>. Many of them
28+
may be parents of already vaccinated children.
29+
</p>
30+
<% end %>
31+
32+
<%= form_with model: @draft_session, url: wizard_path, method: :put do |f| %>
33+
<div class="nhsuk-button-group">
34+
<%= f.govuk_submit submit_text, class: "nhsuk-button--reverse" %>
35+
<%= link_to cancel_text, cancel_href %>
36+
</div>
37+
<% end %>
38+
<% end %>

app/views/draft_sessions/confirm.html.erb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
summary_list.with_row do |row|
2525
row.with_key { "Programmes" }
2626
row.with_value { render AppProgrammeTagsComponent.new(@draft_session.programmes) }
27-
28-
unless @draft_session.editing?
29-
row.with_action(text: "Change", href: draft_session_path("programmes"), visually_hidden_text: "programmes")
30-
end
27+
row.with_action(text: "Change", href: draft_session_path("programmes"), visually_hidden_text: "programmes")
3128
end
3229

3330
summary_list.with_row do |row|
Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
1-
<% content_for :before_main do %>
2-
<%= govuk_back_link(href: @back_link_path) %>
3-
<% end %>
4-
5-
<% title = t(".title", programmes: @draft_session.programmes.map(&:name).to_sentence) %>
6-
<% content_for :page_title, title %>
7-
8-
<%= govuk_panel(title_text: title, classes: %w[app-panel--interruption]) do %>
9-
<p>
10-
<%= @catch_up_patients_vaccinated_percentage == 0 ? "" : "Only " %>
11-
<%= @catch_up_patients_vaccinated_percentage %>% of children in
12-
<%= format_year_groups(@catch_up_year_groups) %> in
13-
this session have vaccination records. This is unusually low coverage for
14-
catch-up year groups.
15-
</p>
16-
17-
<p>
18-
Check and confirm that vaccination records have been imported for all
19-
children in this school before you continue.
20-
</p>
21-
22-
<% if @draft_session.open_for_consent? && @catch_up_patients_receiving_consent_requests_count > 0 %>
23-
<p>
24-
Scheduling this session now will send consent requests to
25-
<%= pluralize(@catch_up_patients_receiving_consent_requests_count, "parent") %>
26-
of children in <%= format_year_groups(@catch_up_year_groups) %> on
27-
<%= @draft_session.send_consent_requests_at.to_fs(:long) %>. Many of them
28-
may be parents of already vaccinated children.
29-
</p>
30-
<% end %>
31-
32-
<%= form_with model: @draft_session, url: wizard_path, method: :put do |f| %>
33-
<div class="nhsuk-button-group">
34-
<%= f.govuk_submit "Keep session dates", class: "nhsuk-button--reverse" %>
35-
<%= link_to "Remove session dates", draft_session_path("dates") %>
36-
</div>
37-
<% end %>
38-
<% end %>
1+
<%= render "check",
2+
submit_text: "Keep session dates",
3+
cancel_text: "Remove session dates",
4+
cancel_href: draft_session_path("dates") %>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<%= render "check",
2+
submit_text: "Continue",
3+
cancel_text: "Cancel",
4+
cancel_href: draft_session_path("programmes") %>

config/locales/en.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,6 @@ en:
623623
other: Why are they refusing to give consent?
624624
personal_choice: Why are they refusing to give consent?
625625
will_be_vaccinated_elsewhere: Where will their child get their vaccination?
626-
draft_sessions:
627-
dates_check:
628-
title: Have you imported historical vaccination records for %{programmes}?
629626
import_duplicate_form:
630627
options:
631628
label:

config/locales/wicked.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ en:
3434
parent: parent
3535
parent_details: parent-details
3636
programmes: programmes
37+
programmes_check: programmes-check
3738
questions: questions
3839
reason_for_refusal: reason-for-refusal
3940
reason_for_refusal_notes: reason-for-refusal-notes

spec/features/edit_session_programmes_spec.rb

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
describe "Edit session programmes" do
44
around { |example| travel_to(Time.zone.local(2024, 2, 1)) { example.run } }
55

6+
scenario "add new programme to existing session" do
7+
given_a_school_exists
8+
and_the_school_has_unvaccinated_catch_up_patients
9+
and_an_hpv_session_already_exists
10+
11+
when_i_visit_the_session_page
12+
and_i_click_on_edit_session
13+
and_i_add_the_mmr_programme
14+
then_i_see_the_warning_panel_about_unvaccinated_patients
15+
16+
when_i_click_continue
17+
then_i_should_see_the_mmr_programme
18+
screenshot_and_save_page
19+
end
20+
621
scenario "choosing programmes with a high number of unvaccinated catch up patients" do
722
given_a_school_exists
823
and_the_school_has_unvaccinated_catch_up_patients
@@ -14,16 +29,27 @@
1429
and_i_choose_the_date
1530
then_i_see_the_warning_panel_about_unvaccinated_patients
1631

17-
when_i_click_continue
32+
when_i_click_keep_session_dates
1833
then_i_should_see_the_mmr_programme
1934
end
2035

2136
def given_a_school_exists
22-
@team =
23-
create(:team, :with_one_nurse, programmes: [Programme.hpv, Programme.mmr])
37+
@programmes = [Programme.hpv, Programme.mmr]
38+
39+
@team = create(:team, :with_one_nurse, programmes: @programmes)
40+
41+
@location = create(:school, team: @team, programmes: @programmes)
42+
end
2443

25-
@location =
26-
create(:school, team: @team, programmes: [Programme.hpv, Programme.mmr])
44+
def and_an_hpv_session_already_exists
45+
@session =
46+
create(
47+
:session,
48+
:scheduled,
49+
team: @team,
50+
location: @location,
51+
programmes: [Programme.hpv]
52+
)
2753
end
2854

2955
def and_the_school_has_unvaccinated_catch_up_patients
@@ -33,15 +59,30 @@ def and_the_school_has_unvaccinated_catch_up_patients
3359
:eligible_for_vaccination,
3460
location: @location,
3561
year_group: 9,
36-
programmes: [Programme.hpv, Programme.mmr]
62+
programmes: @programmes
3763
)
3864
end
3965

66+
def when_i_visit_the_session_page
67+
sign_in @team.users.first
68+
visit session_path(@session)
69+
end
70+
4071
def when_i_visit_the_school_page
4172
sign_in @team.users.first
4273
visit school_sessions_path(@location)
4374
end
4475

76+
def and_i_click_on_edit_session
77+
click_on "Edit session"
78+
end
79+
80+
def and_i_add_the_mmr_programme
81+
click_on "Change programmes"
82+
check "MMR"
83+
click_on "Continue"
84+
end
85+
4586
def and_i_create_a_new_session
4687
click_on "Add a new session"
4788
end
@@ -83,6 +124,10 @@ def then_i_see_the_warning_panel_about_unvaccinated_patients
83124
end
84125

85126
def when_i_click_continue
127+
click_on "Continue"
128+
end
129+
130+
def when_i_click_keep_session_dates
86131
click_on "Keep session dates"
87132
end
88133

0 commit comments

Comments
 (0)