@@ -92,8 +92,15 @@ def update_registration_statuses!
9292 merge_patient_scope ( Patient ::RegistrationStatus )
9393 . joins ( session : :team_location )
9494 . where ( team_location : { academic_year : academic_years } )
95- . includes ( :attendance_records , :patient , :session , :vaccination_records )
96- . find_in_batches do |batch |
95+ . in_batches do |relation |
96+ batch =
97+ relation . includes (
98+ :attendance_records ,
99+ :patient ,
100+ :session ,
101+ :vaccination_records
102+ ) . to_a
103+
97104 batch . each ( &:assign_status )
98105
99106 Patient ::RegistrationStatus . import! (
@@ -106,23 +113,6 @@ def update_registration_statuses!
106113 end
107114 end
108115
109- def patient_statuses_to_import
110- @patient_statuses_to_import ||=
111- ( patient_scope || Patient . all )
112- . pluck ( :id , :birth_academic_year )
113- . flat_map do |patient_id , birth_academic_year |
114- academic_years . flat_map do |academic_year |
115- year_group = birth_academic_year . to_year_group ( academic_year :)
116-
117- programme_types_per_year_group
118- . fetch ( year_group , [ ] )
119- . map do |programme_type |
120- [ patient_id , programme_type , academic_year ]
121- end
122- end
123- end
124- end
125-
126116 def programme_statuses_to_import
127117 @programme_statuses_to_import ||=
128118 ( patient_scope || Patient . all )
@@ -161,19 +151,6 @@ def patient_location_statuses_to_import
161151 end
162152 end
163153
164- def programme_types_per_year_group
165- @programme_types_per_year_group ||=
166- Location ::ProgrammeYearGroup
167- . joins ( :location_year_group )
168- . where ( location_year_group : { academic_year : academic_years } )
169- . distinct
170- . pluck ( :programme_type , :"location_year_group.value" )
171- . each_with_object ( { } ) do |( programme_type , year_group ) , hash |
172- hash [ year_group ] ||= [ ]
173- hash [ year_group ] << programme_type
174- end
175- end
176-
177154 def programme_types_per_session_id_and_year_group
178155 @programme_types_per_session_id_and_year_group ||=
179156 Session ::ProgrammeYearGroup
0 commit comments