Skip to content

Commit 431b6e4

Browse files
Add script to fix which schools are attributed to BLMK and N&W
These SAIS teams are currently configured with all teams in their area wheareas they should be configured with only a limited selection of schools. This change amends them to have only and exactly the schools that they should have. Jira-Issue: MAV-2352 Jira-Issue: MAV-2353
1 parent 686f393 commit 431b6e4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

app/lib/school_removal.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class SchoolRemoval
2+
include ActiveModel::Model
3+
4+
def self.perform
5+
new.perform
6+
end
7+
8+
def perform
9+
ActiveRecord::Base.transaction do
10+
remove_existing_schools!(subteams: [bedfordshire_luton_and_milton_keynes, norfolk_and_waveney])
11+
add_correct_schools!(subteam: bedfordshire_luton_and_milton_keynes, schools: correct_blkm_schools)
12+
add_correct_schools!(subteam: norfolk_and_waveney, schools: correct_n_and_w_schools)
13+
remove_hanging_sessions(teams: [bedfordshire_luton_and_milton_keynes.team, norfolk_and_waveney.team])
14+
end
15+
end
16+
17+
private
18+
19+
def remove_existing_schools!(subteams:)
20+
Location.school.where(subteam: subteams).update_all(subteam_id: nil)
21+
end
22+
23+
def add_correct_schools!(subteam:, schools:)
24+
schools.each do |location|
25+
warn "URN #{location.urn} previously belonged to #{location.subteam.name}" if location.subteam
26+
27+
location.update!(subteam:)
28+
location.sessions.update_all(team_id: subteam.team.id)
29+
end
30+
end
31+
32+
def remove_hanging_sessions(teams:)
33+
Session.where(team: teams)
34+
.select { |s| s.location.subteam.nil? }
35+
.each(&:destroy)
36+
end
37+
38+
def bedfordshire_luton_and_milton_keynes
39+
@blmk ||= Subteam.find_by(name: "Bedfordshire, Luton and Milton Keynes School Age Immunisation Service")
40+
end
41+
42+
def norfolk_and_waveney
43+
@n_and_w ||= Subteam.find_by(name: "Norfolk and Waveney School Age Immunisation Service")
44+
end
45+
46+
def correct_blkm_schools
47+
@correct_blkm_schools ||= [140281, 140286, 140734, 140835, 141271, 141520, 142036, 142263, 142264, 142310, 142322, 142387, 142672, 142907, 143084, 143263, 143265, 143561, 143766, 143770, 143850, 143926, 144010, 144039, 144137, 144311, 144312, 144342, 144357, 144424, 144424, 144458, 144528, 144545, 144546, 144595, 144746, 145043, 145063, 145219, 145324, 145325, 145426, 145427, 145736, 145805, 145861, 145872, 146269, 146462, 146685, 146714, 146751, 147081, 147112, 147154, 147183, 147269, 147376, 147376, 147380, 147381, 147690, 147803, 147804, 147860, 147891, 147891, 147994, 148104, 148193, 148227, 148229, 148234, 148297, 148334, 148411, 148420, 148551, 148640, 148692, 148835, 148982, 149106, 149107, 149208, 149324, 149404, 149460, 149470, 149542, 149662, 150145, 150335, 150413, 150474, 150593, 150595, 150629, 150792, 150796, 151041, 151042, 151047, 151125, 151126, 151151, 151210, 151218, 151293, 151368, 151371, 151372, 151526, 151796, 151840, 151866, 152290, 152290].map do |urn|
48+
Location.school.find_by_urn_and_site!(urn)
49+
end
50+
end
51+
52+
def correct_n_and_w_schools
53+
@correct_n_and_w_schools ||= [141663, 144427, 140914, 140990, 141050, 141161, 141168, 141172, 141192, 141226, 141227, 141228, 141314, 141356, 141357, 141358, 141359, 141360, 145629, 138797, 139491, 120765, 120766, 120767, 120777, 120781, 120783, 120784, 120788, 120789, 120794, 120795, 120796, 120797, 120798, 120808, 120809, 120812, 120815, 120816, 120817, 120818, 120821, 120822, 120825, 120827, 120830, 120835, 120836, 120840, 120841, 120843, 120847, 120848, 120851, 120852, 120853, 120856, 120859, 120862, 120863, 120866, 120867, 120883, 120884, 120887, 120890, 120896, 120899, 120903, 120904, 120905, 120906, 120908, 120910, 120911, 120912, 120913, 120914, 120917, 120918, 120920, 120922, 120928, 120932, 120954, 120958, 120972, 120973, 120982, 120984, 120987, 120988, 120990, 120995, 120999, 121000, 121011, 121013, 121019, 121022, 121026, 121027, 121035, 121036, 121037, 121040, 121041, 121042, 121050, 121051, 121053, 121054, 121059, 121061, 121062, 121063, 121066, 121067, 121069, 121081, 121082, 121083, 121086, 121087, 121090, 121092, 121093, 121095, 121096, 121097, 121108, 121110, 121113, 121117, 121123, 121128, 121134, 121135, 121146, 121147, 121149, 121150, 121190, 121192, 121197, 121199, 121202, 121203, 121205, 121206, 121239, 121260, 121265, 141464, 141465, 141496, 141584, 141640, 141661, 141662, 141691, 141702, 141721, 141736, 141758, 141778, 141780, 141845, 141895, 141918, 141983, 141984, 141991, 142005, 142016, 142017, 142057, 124574, 124676, 124727, 124748, 124751, 124868, 124885, 142187, 142395, 142465, 142466, 142467, 142468, 142526, 142580, 142588, 142589, 142599, 142633, 142634, 142730, 142732, 142737, 142751, 142770, 142786, 142806, 142837, 142840, 142842, 142852, 142871, 142968, 143053, 143066, 143135, 110643, 121017, 121018, 143279, 143280, 143459, 143460, 143461, 143462, 143463, 143491, 143492, 143522, 143671, 143824, 143949, 143956, 143961, 143988, 143990, 144017, 144019, 144020, 144021, 144143, 144144, 144145, 144146, 144147, 144313, 144314, 144315, 144317, 144360, 144361, 144425, 144426, 144428, 144442, 144443, 144444, 144445, 144532, 144565, 144574, 144640, 144825, 144826, 144827, 144828, 144839, 144849, 144884, 144972, 144973, 144974, 144975, 145028, 145029, 145159, 145209, 145301, 145299, 145304, 145441, 145442, 145530, 145531, 145532, 145533, 145534, 145535, 145541, 145559, 145628, 145694, 145695, 145737, 145738, 145749, 145914, 145975, 146060, 146061, 146062, 146065, 146084, 146319, 146479, 146550, 146558, 146684, 146692, 146711, 146757, 146880, 147092, 147247, 147321, 147322, 147415, 147567, 147857, 147940, 147969, 148119, 148151, 148152, 148232, 148237, 148425, 148668, 148821, 148822, 148994, 148995, 148996, 149415, 149502, 149516, 149636, 149744, 149877, 149878, 149879, 149896, 150063, 150067, 150160, 150175, 150249, 150451, 150490, 150582, 150583, 150625, 150665, 150666, 150734, 150806, 151195, 151308, 151432, 151635, 151650, 130819, 133239, 133505, 133506, 133507, 133508, 134043, 134958, 134960, 134964, 134965, 131287, 135148, 136356, 136536, 137311, 137459, 137541, 138138, 138642, 138793, 138795, 138796, 138880, 139058, 139580, 139736, 139804, 139929, 140016, 140033, 140189, 140363, 140545, 140573, 140663, 140681, 140712, 140819, 140823, 140852, 140870].map do |urn|
54+
Location.school.find_by_urn_and_site!(urn)
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)