Skip to content

Commit 2390728

Browse files
committed
Fix bulk PSDs getting added to injection patients
We came across a bug where bulking adding PSDs would end up including patients who were consented for injection only. PSD's are only for HCAs to carry out nasal vaccinations.
1 parent dca13af commit 2390728

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
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

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_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_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)