Skip to content

Commit beac289

Browse files
committed
Add PSD filters to PSDs tab page
1 parent 4030b46 commit beac289

File tree

6 files changed

+118
-20
lines changed

6 files changed

+118
-20
lines changed

app/components/app_patient_search_form_component.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ class AppPatientSearchFormComponent < ViewComponent::Base
7979
<% end %>
8080
<% end %>
8181
<% end %>
82+
83+
<% if patient_specific_direction_statuses.any? %>
84+
<%= f.govuk_radio_buttons_fieldset :patient_specific_direction_status, legend: { text: "PSD status", size: "s" } do %>
85+
<%= f.govuk_radio_button :patient_specific_direction_status, "", checked: form.patient_specific_direction_status.blank?, label: { text: "Any" } %>
86+
87+
<% patient_specific_direction_statuses.each do |status| %>
88+
<%= f.govuk_radio_button :patient_specific_direction_status,
89+
status,
90+
checked: form.patient_specific_direction_status == status,
91+
label: { text: t(status, scope: %i[status patient_specific_direction label]) } %>
92+
<% end %>
93+
<% end %>
94+
<% end %>
8295
8396
<% if vaccine_methods.any? %>
8497
<%= f.govuk_radio_buttons_fieldset :vaccine_method, legend: { text: "Vaccination method", size: "s" } do %>
@@ -182,6 +195,7 @@ def initialize(
182195
register_statuses: [],
183196
triage_statuses: [],
184197
vaccination_statuses: [],
198+
patient_specific_direction_statuses: [],
185199
vaccine_methods: [],
186200
year_groups: [],
187201
heading_level: 3,
@@ -197,6 +211,7 @@ def initialize(
197211
@register_statuses = register_statuses
198212
@triage_statuses = triage_statuses
199213
@vaccination_statuses = vaccination_statuses
214+
@patient_specific_direction_statuses = patient_specific_direction_statuses
200215
@vaccine_methods = vaccine_methods
201216
@year_groups = year_groups
202217
@heading_level = heading_level
@@ -212,6 +227,7 @@ def initialize(
212227
:register_statuses,
213228
:triage_statuses,
214229
:vaccination_statuses,
230+
:patient_specific_direction_statuses,
215231
:vaccine_methods,
216232
:year_groups,
217233
:heading_level,

app/controllers/concerns/patient_search_form_concern.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def patient_search_form_params
2828
:date_of_birth_year,
2929
:missing_nhs_number,
3030
:vaccination_status,
31+
:patient_specific_direction_status,
3132
:q,
3233
:register_status,
3334
:triage_status,

app/forms/patient_search_form.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class PatientSearchForm < SearchForm
1212
attribute :date_of_birth_year, :integer
1313
attribute :missing_nhs_number, :boolean
1414
attribute :vaccination_status, :string
15+
attribute :patient_specific_direction_status, :string
1516
attribute :programme_types, array: true
1617
attribute :q, :string
1718
attribute :register_status, :string
@@ -59,6 +60,7 @@ def apply(scope)
5960
scope = filter_register_status(scope)
6061
scope = filter_triage_status(scope)
6162
scope = filter_vaccine_method(scope)
63+
scope = filter_patient_specific_direction_status(scope)
6264

6365
scope.order_by_name
6466
end
@@ -168,6 +170,19 @@ def filter_vaccination_statuses(scope)
168170
end
169171
end
170172

173+
def filter_patient_specific_direction_status(scope)
174+
return scope if (status = patient_specific_direction_status&.to_sym).blank?
175+
176+
case status
177+
when :added
178+
scope.has_patient_specific_direction(programme: programmes)
179+
when :not_added
180+
scope.without_patient_specific_direction(programme: programmes)
181+
else
182+
scope
183+
end
184+
end
185+
171186
def filter_register_status(scope)
172187
if (status = register_status&.to_sym).present?
173188
scope.has_registration_status(status)

app/models/patient_session.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@ class PatientSession < ApplicationRecord
266266
)
267267
end
268268

269+
scope :has_patient_specific_direction,
270+
->(programme:) do
271+
joins(:session).where(
272+
PatientSpecificDirection
273+
.where("patient_id = patient_sessions.patient_id")
274+
.where("academic_year = sessions.academic_year")
275+
.where(programme:)
276+
.arel
277+
.exists
278+
)
279+
end
280+
269281
scope :destroy_all_if_safe,
270282
-> do
271283
includes(

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,37 @@
88

99
<%= render "sessions/header" %>
1010

11-
<%= govuk_inset_text do %>
12-
<span class="nhsuk-u-visually-hidden">Information: </span>
13-
<p class="nhsuk-body">
14-
There are <%= @eligible_for_bulk_psd_count %> children with consent for the nasal flu vaccine
15-
who do not require triage and do not yet have a PSD in place.
16-
</p>
17-
<% if current_user.is_nurse? %>
18-
<div class="nhsuk-action-link">
19-
<%= link_to new_session_patient_specific_directions_path(@session), class: "nhsuk-action-link__link" do %>
20-
<svg class="nhsuk-icon nhsuk-icon__arrow-right-circle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" width="36" height="36">
21-
<path d="M0 0h24v24H0z" fill="none"></path>
22-
<path d="M12 2a10 10 0 0 0-9.95 9h11.64L9.74 7.05a1 1 0 0 1 1.41-1.41l5.66 5.65a1 1 0 0 1 0 1.42l-5.66 5.65a1 1 0 0 1-1.41 0 1 1 0 0 1 0-1.41L13.69 13H2.05A10 10 0 1 0 12 2z"></path>
23-
</svg>
24-
<span class="nhsuk-action-link__text">Add new PSDs</span>
25-
<% end %>
26-
</div>
27-
<% end %>
28-
<% end %>
29-
3011
<div class="nhsuk-grid-row">
31-
<div class="app-grid-column-filters"></div>
12+
<div class="app-grid-column-filters">
13+
<%= render AppPatientSearchFormComponent.new(
14+
@form,
15+
url: session_patient_specific_directions_path(@session),
16+
programmes: @session.programmes,
17+
patient_specific_direction_statuses: %w[added not_added],
18+
year_groups: @session.year_groups,
19+
) %>
20+
</div>
3221

3322
<div class="app-grid-column-results">
23+
<%= govuk_inset_text do %>
24+
<span class="nhsuk-u-visually-hidden">Information: </span>
25+
<p class="nhsuk-body">
26+
There are <%= @eligible_for_bulk_psd_count %> children with consent for the nasal flu vaccine
27+
who do not require triage and do not yet have a PSD in place.
28+
</p>
29+
<% if current_user.is_nurse? %>
30+
<div class="nhsuk-action-link">
31+
<%= link_to new_session_patient_specific_directions_path(@session), class: "nhsuk-action-link__link" do %>
32+
<svg class="nhsuk-icon nhsuk-icon__arrow-right-circle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" width="36" height="36">
33+
<path d="M0 0h24v24H0z" fill="none"></path>
34+
<path d="M12 2a10 10 0 0 0-9.95 9h11.64L9.74 7.05a1 1 0 0 1 1.41-1.41l5.66 5.65a1 1 0 0 1 0 1.42l-5.66 5.65a1 1 0 0 1-1.41 0 1 1 0 0 1 0-1.41L13.69 13H2.05A10 10 0 1 0 12 2z"></path>
35+
</svg>
36+
<span class="nhsuk-action-link__text">Add new PSDs</span>
37+
<% end %>
38+
</div>
39+
<% end %>
40+
<% end %>
41+
3442
<%= render AppSessionNeedsReviewWarningComponent.new(session: @session) %>
3543
<%= render AppSearchResultsComponent.new(@pagy, label: "children", heading: "Review PSDs") do %>
3644
<% @patient_sessions.each do |patient_session| %>

spec/forms/patient_search_form_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
let(:register_status) { nil }
3535
let(:triage_status) { nil }
3636
let(:vaccine_method) { nil }
37+
let(:patient_specific_direction_status) { nil }
3738
let(:year_groups) { %w[8 9 10 11] }
3839

3940
let(:params) do
@@ -46,6 +47,7 @@
4647
date_of_birth_year:,
4748
missing_nhs_number:,
4849
vaccination_status:,
50+
patient_specific_direction_status:,
4951
programme_types:,
5052
q:,
5153
register_status:,
@@ -458,6 +460,50 @@
458460
end
459461
end
460462

463+
context "filtering on patient specific direction status" do
464+
let(:consent_statuses) { nil }
465+
let(:date_of_birth_day) { nil }
466+
let(:date_of_birth_month) { nil }
467+
let(:date_of_birth_year) { nil }
468+
let(:missing_nhs_number) { nil }
469+
let(:vaccination_status) { nil }
470+
let(:programme_types) { nil }
471+
let(:q) { nil }
472+
let(:register_status) { nil }
473+
let(:triage_status) { nil }
474+
let(:year_groups) { nil }
475+
476+
let!(:patient_session_with_psd) do
477+
create(:patient_session, session:).tap do |patient_session|
478+
create(
479+
:patient_specific_direction,
480+
patient: patient_session.patient,
481+
programme: programmes.first
482+
)
483+
end
484+
end
485+
486+
let!(:patient_session_without_psd) { create(:patient_session, session:) }
487+
488+
context "when status is 'added'" do
489+
let(:patient_specific_direction_status) { "added" }
490+
491+
it "finds the patient with the PSD" do
492+
expect(form.apply(scope)).to contain_exactly(patient_session_with_psd)
493+
end
494+
end
495+
496+
context "when status is 'not_added'" do
497+
let(:patient_specific_direction_status) { "not_added" }
498+
499+
it "finds the patient that has no PSD" do
500+
expect(form.apply(scope)).to contain_exactly(
501+
patient_session_without_psd
502+
)
503+
end
504+
end
505+
end
506+
461507
context "filtering on vaccine method" do
462508
let(:consent_statuses) { nil }
463509
let(:date_of_birth_day) { nil }

0 commit comments

Comments
 (0)