Skip to content

Commit 30b3878

Browse files
authored
Merge pull request #4198 from nhsuk/aged-out-filter
Add filter to view children who have aged out
2 parents 1464136 + 9037de1 commit 30b3878

File tree

9 files changed

+287
-34
lines changed

9 files changed

+287
-34
lines changed

app/components/app_patient_search_form_component.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ class AppPatientSearchFormComponent < ViewComponent::Base
157157
multiple: false,
158158
link_errors: true,
159159
label: { text: "Children missing an NHS number" } %>
160+
161+
<%= f.govuk_check_box :aged_out_of_programmes,
162+
1, 0,
163+
checked: form.aged_out_of_programmes,
164+
multiple: false,
165+
link_errors: true,
166+
label: { text: "Children aged out of programmes" } %>
160167
<% end %>
161168
162169
<% if show_buttons_in_details? %>
@@ -223,7 +230,7 @@ def initialize(
223230
def open_details?
224231
@form.date_of_birth_year.present? || @form.date_of_birth_month.present? ||
225232
@form.date_of_birth_day.present? || @form.missing_nhs_number ||
226-
@form.archived
233+
@form.archived || @form.aged_out_of_programmes
227234
end
228235

229236
def show_buttons_in_details?

app/controllers/concerns/patient_search_form_concern.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def set_patient_search_form
2121
def patient_search_form_params
2222
params.permit(
2323
:_clear,
24+
:aged_out_of_programmes,
2425
:archived,
2526
:date_of_birth_day,
2627
:date_of_birth_month,

app/forms/patient_search_form.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class PatientSearchForm < SearchForm
44
attr_accessor :current_user
55
attr_writer :academic_year
66

7+
attribute :aged_out_of_programmes, :boolean
78
attribute :archived, :boolean
89
attribute :consent_statuses, array: true
910
attribute :date_of_birth_day, :integer
@@ -49,6 +50,7 @@ def programmes
4950
def apply(scope)
5051
scope = filter_name(scope)
5152
scope = filter_year_groups(scope)
53+
scope = filter_aged_out_of_programmes(scope)
5254
scope = filter_archived(scope)
5355
scope = filter_date_of_birth_year(scope)
5456
scope = filter_nhs_number(scope)
@@ -82,6 +84,18 @@ def filter_year_groups(scope)
8284
end
8385
end
8486

87+
def filter_aged_out_of_programmes(scope)
88+
if aged_out_of_programmes
89+
scope.not_appear_in_programmes(team.programmes, academic_year:)
90+
elsif @session || archived
91+
scope
92+
else
93+
# Archived patients won't appear in programmes, so we need to
94+
# skip this check if we're trying to view archived patients.
95+
scope.appear_in_programmes(team.programmes, academic_year:)
96+
end
97+
end
98+
8599
def filter_archived(scope)
86100
if archived
87101
scope.archived(team:)

app/models/patient.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ class Patient < ApplicationRecord
152152
)
153153
end
154154

155+
scope :not_appear_in_programmes,
156+
->(programmes, academic_year:) do
157+
where.not(
158+
PatientSession
159+
.joins(:session)
160+
.where(sessions: { academic_year: })
161+
.where("patient_id = patients.id")
162+
.appear_in_programmes(programmes)
163+
.arel
164+
.exists
165+
)
166+
end
167+
155168
scope :with_pending_changes, -> { where.not(pending_changes: {}) }
156169

157170
scope :search_by_name,

spec/features/edit_vaccination_record_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def and_an_hpv_programme_is_underway
233233
@replacement_batch =
234234
create(:batch, :not_expired, team: @team, vaccine: @vaccine)
235235

236-
location = create(:school)
236+
location = create(:school, team: @team)
237237

238238
@session =
239239
create(

spec/features/manage_children_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
then_i_see_the_activity_log
1818
end
1919

20+
scenario "Viewing children who have aged out" do
21+
given_patients_exist
22+
and_todays_date_is_in_the_far_future
23+
24+
when_i_click_on_children
25+
then_i_see_no_children
26+
27+
when_i_click_on_view_aged_out_children
28+
then_i_see_the_children
29+
end
30+
2031
scenario "Adding an NHS number" do
2132
given_patients_exist
2233
and_sync_vaccination_records_to_nhs_feature_is_enabled
@@ -198,6 +209,10 @@ def and_the_vaccination_has_been_synced_to_nhs
198209
perform_enqueued_jobs(only: SyncVaccinationRecordToNHSJob)
199210
end
200211

212+
def and_todays_date_is_in_the_far_future
213+
travel 13.years
214+
end
215+
201216
def when_a_deceased_patient_exists
202217
session = create(:session, team: @team, programmes: [@programme])
203218

@@ -227,6 +242,16 @@ def then_i_see_the_children
227242
expect(page).to have_content(/\d+ children/)
228243
end
229244

245+
def then_i_see_no_children
246+
expect(page).to have_content("No children")
247+
end
248+
249+
def when_i_click_on_view_aged_out_children
250+
find(".nhsuk-details__summary").click
251+
check "Children aged out of programmes"
252+
click_on "Search"
253+
end
254+
230255
def when_i_click_on_a_child
231256
click_on "SMITH, John"
232257
end

spec/features/parental_consent_manual_matching_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
when_i_choose_a_consent_response
3636
then_i_am_on_the_consent_matching_page
3737

38-
when_i_search_for_the_child
38+
when_i_search_for_the_aged_out_child
3939
and_i_select_the_child_record
4040
then_i_can_review_the_match
4141

@@ -112,6 +112,13 @@ def when_i_search_for_the_child
112112
click_button "Search"
113113
end
114114

115+
def when_i_search_for_the_aged_out_child
116+
fill_in "Search", with: @patient.given_name
117+
find(".nhsuk-details__summary").click
118+
check "Children aged out of programmes"
119+
click_button "Search"
120+
end
121+
115122
def and_i_select_the_child_record
116123
click_link @patient.full_name
117124
end

0 commit comments

Comments
 (0)