Skip to content

Commit f7793c0

Browse files
committed
Ensure aged-out patients are not counted in schools index
This fixes a bug where the count of children in each school would include the aged-out children, who are then not shown by default when you view the list of children in the school. This was particularly noticeable for the unknown school, where children are automatically moved there when they age out. Jira-Issue: MAV-5059
1 parent 6c618f7 commit f7793c0

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

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

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)