Skip to content

Commit 4c4d3eb

Browse files
authored
Merge pull request #4458 from nhsuk/fix-delegation-psd-bulk-add
Fix bulk PSDs getting added to injection patients
2 parents 3367e8e + acf1b7e commit 4c4d3eb

File tree

5 files changed

+78
-33
lines changed

5 files changed

+78
-33
lines changed

app/controllers/sessions/patient_specific_directions_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def patient_sessions_allowed_psd
7272
@patient_sessions_allowed_psd ||=
7373
@session
7474
.patient_sessions
75-
.has_consent_status("given", programme: @programme)
75+
.has_consent_status(
76+
"given",
77+
programme: @programme,
78+
vaccine_method: "nasal"
79+
)
7680
.has_triage_status("not_required", programme: @programme)
7781
.without_patient_specific_direction(programme: @programme)
7882
end

app/models/patient.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,20 @@ class Patient < ApplicationRecord
217217
end
218218

219219
scope :has_consent_status,
220-
->(status, programme:, academic_year:) do
221-
where(
222-
Patient::ConsentStatus
223-
.where("patient_id = patients.id")
224-
.where(status:, programme:, academic_year:)
225-
.arel
226-
.exists
227-
)
220+
->(status, programme:, academic_year:, vaccine_method: nil) do
221+
consent_status_scope =
222+
Patient::ConsentStatus.where("patient_id = patients.id").where(
223+
status:,
224+
programme:,
225+
academic_year:
226+
)
227+
228+
if vaccine_method
229+
consent_status_scope =
230+
consent_status_scope.has_vaccine_method(vaccine_method)
231+
end
232+
233+
where(consent_status_scope.arel.exists)
228234
end
229235

230236
scope :has_triage_status,

app/models/patient_session.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ class PatientSession < ApplicationRecord
166166
end
167167

168168
scope :has_consent_status,
169-
->(status, programme:) do
170-
joins(:session).where(
169+
->(status, programme:, vaccine_method: nil) do
170+
consent_status_scope =
171171
Patient::ConsentStatus
172172
.where("patient_id = patient_sessions.patient_id")
173173
.where("academic_year = sessions.academic_year")
174174
.where(status:, programme:)
175-
.arel
176-
.exists
177-
)
175+
176+
if vaccine_method
177+
consent_status_scope =
178+
consent_status_scope.has_vaccine_method(vaccine_method)
179+
end
180+
181+
joins(:session).where(consent_status_scope.arel.exists)
178182
end
179183

180184
scope :has_registration_status,

app/views/sessions/patient_specific_directions/new.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<p class="nhsuk-body">This cannot be undone.</p>
1212

13-
<div class="app-button-group">
13+
<div class="nhsuk-button-group">
1414
<%= govuk_button_to "Yes, add PSDs",
15-
session_patient_specific_directions_path(@session) %>
15+
session_patient_specific_directions_path(@session), class: "nhsuk-u-margin-right-4" %>
1616

1717
<%= govuk_link_to "No, return to session",
1818
new_session_patient_specific_directions_path(@session) %>

spec/features/patient_specific_directions_spec.rb

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@
55

66
scenario "prescriber can bulk add PSDs to patients that don't require triage" do
77
given_a_flu_programme_with_a_running_session(user_type: :with_one_nurse)
8-
and_a_patient_who_doesnt_need_triage_exists
8+
and_a_patient_with_consent_given_nasal_only_triage_not_needed
9+
and_a_patient_with_consent_given_injection_only_triage_not_needed
910
and_i_am_signed_in
1011

1112
when_i_go_to_the_session_psds_tab
12-
then_the_patient_should_have_psd_status_not_added
13+
then_the_patients_should_have_psd_status_not_added
14+
and_i_should_only_see_one_child_eligible_for_bulk_adding_psd
1315
and_i_should_see_one_child_eligible_for_psd
1416

1517
when_i_click_add_new_psds
1618
and_should_see_again_one_child_eligible_for_psd
1719

1820
when_i_click_on_button_to_bulk_add_psds
19-
then_the_patient_should_have_psd_status_added
21+
then_the_nasal_patient_should_have_psd_status_added
22+
and_the_injection_patient_should_have_psd_status_not_added
2023
and_zero_children_should_be_eligible_for_psd
2124
end
2225

2326
scenario "admin cannot bulk add PSDs to patients" do
2427
given_a_flu_programme_with_a_running_session(user_type: :with_one_admin)
25-
and_a_patient_who_doesnt_need_triage_exists
28+
and_a_patient_with_consent_given_nasal_only_triage_not_needed
2629
and_i_am_signed_in(role: :admin)
2730

2831
when_i_go_to_the_session_psds_tab
@@ -33,7 +36,7 @@
3336
given_a_flu_programme_with_a_running_session(
3437
user_type: :with_one_healthcare_assistant
3538
)
36-
and_a_patient_who_doesnt_need_triage_exists
39+
and_a_patient_with_consent_given_nasal_only_triage_not_needed
3740
and_i_am_signed_in(role: :healthcare_assistant)
3841

3942
when_i_go_to_the_session_psds_tab
@@ -45,22 +48,33 @@ def given_delegation_feature_flag_is_enabled
4548
end
4649

4750
def given_a_flu_programme_with_a_running_session(user_type:)
48-
programmes = [create(:programme, :flu)]
49-
@team = create(:team, user_type, programmes:)
51+
@programmes = [create(:programme, :flu)]
52+
@team = create(:team, user_type, programmes: @programmes)
5053

5154
@batch =
52-
create(:batch, team: @team, vaccine: programmes.first.vaccines.first)
55+
create(:batch, team: @team, vaccine: @programmes.first.vaccines.first)
5356

54-
@session = create(:session, team: @team, programmes:)
57+
@session = create(:session, team: @team, programmes: @programmes)
5558
end
5659

57-
def and_a_patient_who_doesnt_need_triage_exists
58-
@patient_triage_not_needed =
60+
def and_a_patient_with_consent_given_nasal_only_triage_not_needed
61+
@nasal_patient =
5962
create(
60-
:patient_session,
61-
:consent_given_triage_not_needed,
63+
:patient,
64+
:consent_given_nasal_only_triage_not_needed,
65+
programmes: @programmes,
6266
session: @session
63-
).patient
67+
)
68+
end
69+
70+
def and_a_patient_with_consent_given_injection_only_triage_not_needed
71+
@injection_patient =
72+
create(
73+
:patient,
74+
:consent_given_injection_only_triage_not_needed,
75+
programmes: @programmes,
76+
session: @session
77+
)
6478
end
6579

6680
def and_i_am_signed_in(role: :nurse)
@@ -72,12 +86,16 @@ def when_i_go_to_the_session_psds_tab
7286
visit session_patient_specific_directions_path(@session)
7387
end
7488

75-
def then_the_patient_should_have_psd_status_not_added
89+
def then_the_patients_should_have_psd_status_not_added
7690
expect(page).to have_text("PSD not added")
7791
end
7892

79-
def then_the_patient_should_have_psd_status_added
80-
expect(page).to have_text("PSD added")
93+
def then_the_nasal_patient_should_have_psd_status_added
94+
expect_patient_to_have_psd_status(@nasal_patient, "PSD added")
95+
end
96+
97+
def and_the_injection_patient_should_have_psd_status_not_added
98+
expect_patient_to_have_psd_status(@injection_patient, "PSD not added")
8199
end
82100

83101
def and_i_should_see_one_child_eligible_for_psd
@@ -103,4 +121,17 @@ def when_i_click_on_button_to_bulk_add_psds
103121
def then_i_should_not_see_link_to_bulk_add_psds
104122
expect(page).not_to have_text("Add new PSDs")
105123
end
124+
125+
def and_i_should_only_see_one_child_eligible_for_bulk_adding_psd
126+
expect(page).to have_text(
127+
"There are 1 children with consent for the nasal flu vaccine"
128+
)
129+
end
130+
131+
def expect_patient_to_have_psd_status(patient, status)
132+
full_name = "#{patient.family_name.upcase}, #{patient.given_name}"
133+
patient_link = page.find("a", text: full_name)
134+
patient_card = patient_link.ancestor(".nhsuk-card")
135+
expect(patient_card).to have_css(".nhsuk-tag", text: status)
136+
end
106137
end

0 commit comments

Comments
 (0)