Skip to content

Commit 81dae9b

Browse files
committed
Only select schools with year groups
This fixes an issue where schools that don't have children in year groups elligible were being added to the cohort import when using user-provided school year groups.
1 parent 5df846c commit 81dae9b

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

lib/generate/cohort_imports.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,23 @@ def programme_year_groups
132132

133133
def schools_with_year_groups
134134
@schools_with_year_groups ||=
135-
if school_year_groups.present?
136-
urns.map do |urn|
137-
Location.new(urn:, year_groups: school_year_groups[urn])
138-
end
139-
else
140-
organisation
141-
.locations
142-
.where(urn: urns)
143-
.includes(:organisation, :sessions)
144-
.select { (it.year_groups & programme_year_groups).any? }
135+
begin
136+
locations =
137+
if school_year_groups.present?
138+
urns.map do |urn|
139+
Location.new(urn:, year_groups: school_year_groups[urn])
140+
end
141+
else
142+
organisation
143+
.locations
144+
.where(urn: urns)
145+
.includes(:organisation, :sessions)
146+
end
147+
locations.select { (it.year_groups & programme_year_groups).any? }
145148
end
146149
end
147150

148-
def build_patient(year_group: nil)
151+
def build_patient
149152
school = schools_with_year_groups.sample
150153
year_group ||= (school.year_groups & programme_year_groups).sample
151154
nhs_number = nil

0 commit comments

Comments
 (0)