Skip to content

Commit 80a52a5

Browse files
authored
Merge pull request #6427 from NHSDigital/fix-schools-children-count
Ensure aged-out patients are not counted in schools index
2 parents 6c618f7 + 50c558a commit 80a52a5

5 files changed

Lines changed: 16 additions & 12 deletions

File tree

app/controllers/patients_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def set_programme_statuses
9696
[]
9797
else
9898
Patient::ProgrammeStatus.statuses.keys -
99-
%w[not_eligible needs_consent_follow_up_requested]
99+
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys -
100+
%w[needs_consent_follow_up_requested]
100101
end
101102
end
102103

app/controllers/schools/patients_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def index
5454
def set_programme_statuses
5555
@programme_statuses =
5656
Patient::ProgrammeStatus.statuses.keys -
57-
%w[not_eligible needs_consent_follow_up_requested]
57+
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys -
58+
%w[needs_consent_follow_up_requested]
5859
end
5960
end

app/controllers/schools_controller.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ def index
1717

1818
@pagy, @locations = pagy(locations)
1919

20+
academic_year = AcademicYear.pending
21+
2022
@patient_count_by_school_id =
2123
Patient
2224
.joins(:patient_locations)
23-
.where(
24-
patient_locations: {
25-
location: @locations,
26-
academic_year: AcademicYear.pending
27-
}
28-
)
25+
.where(patient_locations: { location: @locations, academic_year: })
2926
.not_archived(team: current_team)
27+
.appear_in_programmes(current_team.programmes, academic_year:)
3028
.distinct
3129
.group(:school_id)
3230
.count

app/controllers/sessions/base_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def set_session
1717
def set_programme_statuses
1818
@programme_statuses =
1919
Patient::ProgrammeStatus.statuses.keys -
20-
%w[not_eligible needs_consent_follow_up_requested]
20+
Patient::ProgrammeStatus::NOT_ELIGIBLE_STATUSES.keys -
21+
%w[needs_consent_follow_up_requested]
2122
end
2223
end

spec/features/schools_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
describe "Schools" do
4-
scenario "Filtering on schools and viewing sessions" do
4+
scenario "filtering on schools and viewing sessions" do
55
given_a_team_exists_with_a_few_schools
66
and_i_am_signed_in
77

@@ -29,7 +29,7 @@
2929
then_i_see_the_secondary_sessions
3030
end
3131

32-
scenario "Sending clinic invitations to children in no known school" do
32+
scenario "sending clinic invitations to children in no known school" do
3333
given_a_team_with_no_known_school_children
3434
and_i_am_signed_in
3535

@@ -65,13 +65,16 @@ def given_a_team_exists_with_a_few_schools
6565
@secondary_patient =
6666
create(:patient, year_group: 7, session: @secondary_session)
6767

68-
@patient_in_both_schools = create(:patient, school: @secondary_school)
68+
@patient_in_both_schools = create(:patient, session: @secondary_session)
6969
create(
7070
:patient_location,
7171
patient: @patient_in_both_schools,
7272
session: @primary_session
7373
)
7474

75+
@aged_out_patient =
76+
create(:patient, year_group: 13, session: @secondary_session)
77+
7578
@nurse = create(:nurse, team: @team)
7679
end
7780

0 commit comments

Comments
 (0)