Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/components/app_patient_search_form_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ class AppPatientSearchFormComponent < ViewComponent::Base
<% end %>
<% end %>
<% end %>

<% if patient_specific_direction_statuses.any? %>
<%= f.govuk_radio_buttons_fieldset :patient_specific_direction_status, legend: { text: "PSD status", size: "s" } do %>
<%= f.govuk_radio_button :patient_specific_direction_status, "", checked: form.patient_specific_direction_status.blank?, label: { text: "Any" } %>

<% patient_specific_direction_statuses.each do |status| %>
<%= f.govuk_radio_button :patient_specific_direction_status,
status,
checked: form.patient_specific_direction_status == status,
label: { text: t(status, scope: %i[status patient_specific_direction label]) } %>
<% end %>
<% end %>
<% end %>

<% if vaccine_methods.any? %>
<%= f.govuk_radio_buttons_fieldset :vaccine_method, legend: { text: "Vaccination method", size: "s" } do %>
Expand Down Expand Up @@ -182,6 +195,7 @@ def initialize(
register_statuses: [],
triage_statuses: [],
vaccination_statuses: [],
patient_specific_direction_statuses: [],
vaccine_methods: [],
year_groups: [],
heading_level: 3,
Expand All @@ -197,6 +211,7 @@ def initialize(
@register_statuses = register_statuses
@triage_statuses = triage_statuses
@vaccination_statuses = vaccination_statuses
@patient_specific_direction_statuses = patient_specific_direction_statuses
@vaccine_methods = vaccine_methods
@year_groups = year_groups
@heading_level = heading_level
Expand All @@ -212,6 +227,7 @@ def initialize(
:register_statuses,
:triage_statuses,
:vaccination_statuses,
:patient_specific_direction_statuses,
:vaccine_methods,
:year_groups,
:heading_level,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/patient_search_form_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def patient_search_form_params
:date_of_birth_year,
:missing_nhs_number,
:vaccination_status,
:patient_specific_direction_status,
:q,
:register_status,
:triage_status,
Expand Down
15 changes: 15 additions & 0 deletions app/forms/patient_search_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PatientSearchForm < SearchForm
attribute :date_of_birth_year, :integer
attribute :missing_nhs_number, :boolean
attribute :vaccination_status, :string
attribute :patient_specific_direction_status, :string
attribute :programme_types, array: true
attribute :q, :string
attribute :register_status, :string
Expand Down Expand Up @@ -59,6 +60,7 @@ def apply(scope)
scope = filter_register_status(scope)
scope = filter_triage_status(scope)
scope = filter_vaccine_method(scope)
scope = filter_patient_specific_direction_status(scope)

scope.order_by_name
end
Expand Down Expand Up @@ -168,6 +170,19 @@ def filter_vaccination_statuses(scope)
end
end

def filter_patient_specific_direction_status(scope)
return scope if (status = patient_specific_direction_status&.to_sym).blank?

case status
when :added
scope.has_patient_specific_direction(programme: programmes)
when :not_added
scope.without_patient_specific_direction(programme: programmes)
else
scope
end
end

def filter_register_status(scope)
if (status = register_status&.to_sym).present?
scope.has_registration_status(status)
Expand Down
12 changes: 12 additions & 0 deletions app/models/patient_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ class PatientSession < ApplicationRecord
)
end

scope :has_patient_specific_direction,
->(programme:) do
joins(:session).where(
PatientSpecificDirection
.where("patient_id = patient_sessions.patient_id")
.where("academic_year = sessions.academic_year")
.where(programme:)
.arel
.exists
)
end

scope :destroy_all_if_safe,
-> do
includes(
Expand Down
48 changes: 28 additions & 20 deletions app/views/sessions/patient_specific_directions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,37 @@

<%= render "sessions/header" %>

<%= govuk_inset_text do %>
<span class="nhsuk-u-visually-hidden">Information: </span>
<p class="nhsuk-body">
There are <%= @eligible_for_bulk_psd_count %> children with consent for the nasal flu vaccine
who do not require triage and do not yet have a PSD in place.
</p>
<% if current_user.is_nurse? %>
<div class="nhsuk-action-link">
<%= link_to new_session_patient_specific_directions_path(@session), class: "nhsuk-action-link__link" do %>
<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">
<path d="M0 0h24v24H0z" fill="none"></path>
<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>
</svg>
<span class="nhsuk-action-link__text">Add new PSDs</span>
<% end %>
</div>
<% end %>
<% end %>

<div class="nhsuk-grid-row">
<div class="app-grid-column-filters"></div>
<div class="app-grid-column-filters">
<%= render AppPatientSearchFormComponent.new(
@form,
url: session_patient_specific_directions_path(@session),
programmes: @session.programmes,
patient_specific_direction_statuses: %w[added not_added],
year_groups: @session.year_groups,
) %>
</div>

<div class="app-grid-column-results">
<%= govuk_inset_text do %>
<span class="nhsuk-u-visually-hidden">Information: </span>
<p class="nhsuk-body">
There are <%= @eligible_for_bulk_psd_count %> children with consent for the nasal flu vaccine
who do not require triage and do not yet have a PSD in place.
</p>
<% if current_user.is_nurse? %>
<div class="nhsuk-action-link">
<%= link_to new_session_patient_specific_directions_path(@session), class: "nhsuk-action-link__link" do %>
<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">
<path d="M0 0h24v24H0z" fill="none"></path>
<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>
</svg>
<span class="nhsuk-action-link__text">Add new PSDs</span>
<% end %>
</div>
<% end %>
<% end %>

<%= render AppSessionNeedsReviewWarningComponent.new(session: @session) %>
<%= render AppSearchResultsComponent.new(@pagy, label: "children", heading: "Review PSDs") do %>
<% @patient_sessions.each do |patient_session| %>
Expand Down
46 changes: 46 additions & 0 deletions spec/forms/patient_search_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
let(:register_status) { nil }
let(:triage_status) { nil }
let(:vaccine_method) { nil }
let(:patient_specific_direction_status) { nil }
let(:year_groups) { %w[8 9 10 11] }

let(:params) do
Expand All @@ -46,6 +47,7 @@
date_of_birth_year:,
missing_nhs_number:,
vaccination_status:,
patient_specific_direction_status:,
programme_types:,
q:,
register_status:,
Expand Down Expand Up @@ -458,6 +460,50 @@
end
end

context "filtering on patient specific direction status" do
let(:consent_statuses) { nil }
let(:date_of_birth_day) { nil }
let(:date_of_birth_month) { nil }
let(:date_of_birth_year) { nil }
let(:missing_nhs_number) { nil }
let(:vaccination_status) { nil }
let(:programme_types) { nil }
let(:q) { nil }
let(:register_status) { nil }
let(:triage_status) { nil }
let(:year_groups) { nil }

let!(:patient_session_with_psd) do
create(:patient_session, session:).tap do |patient_session|
create(
:patient_specific_direction,
patient: patient_session.patient,
programme: programmes.first
)
end
end

let!(:patient_session_without_psd) { create(:patient_session, session:) }

context "when status is 'added'" do
let(:patient_specific_direction_status) { "added" }

it "finds the patient with the PSD" do
expect(form.apply(scope)).to contain_exactly(patient_session_with_psd)
end
end

context "when status is 'not_added'" do
let(:patient_specific_direction_status) { "not_added" }

it "finds the patient that has no PSD" do
expect(form.apply(scope)).to contain_exactly(
patient_session_without_psd
)
end
end
end

context "filtering on vaccine method" do
let(:consent_statuses) { nil }
let(:date_of_birth_day) { nil }
Expand Down