@@ -157,8 +157,8 @@ def render_timeline(*event_names, truncate_columns: false)
157157 end
158158
159159 def additional_events ( patient )
160- patient_imports = patient_events ( patient ) [ :class_imports ]
161- patient_sessions = patient_events ( patient ) [ :sessions ]
160+ patient_imports = @ patient_events[ :class_imports ]
161+ patient_sessions = @ patient_events[ :sessions ]
162162 patient_locations =
163163 Location . joins ( :sessions ) . where ( sessions : { id : patient_sessions } )
164164 class_imports = ClassImport . where ( location_id : patient_locations )
@@ -168,22 +168,22 @@ def additional_events(patient)
168168 {
169169 class_imports :
170170 class_imports
171- . group_by ( &:location_id )
172- . transform_values { |imports | imports . map ( &:id ) } ,
171+ . pluck ( :location_id , :id )
172+ . group_by ( &:first )
173+ . transform_values { |ids | ids . map ( &:last ) } ,
173174 cohort_imports :
174- patient
175- . teams
176- . flat_map ( &:cohort_imports )
177- . map ( &:id )
178- . reject { |id | patient_events ( patient ) [ :cohort_imports ] . include? ( id ) }
175+ CohortImport
176+ . where ( team_id : patient . teams . select ( :id ) )
177+ . where . not ( id : @patient_events [ :cohort_imports ] )
178+ . pluck ( :id )
179179 }
180180 end
181181
182182 def patient_events ( patient )
183183 {
184- class_imports : patient . class_imports . map ( & :id ) ,
185- cohort_imports : patient . cohort_imports . map ( & :id ) ,
186- sessions : patient . sessions . map ( & :id )
184+ class_imports : patient . class_imports . pluck ( :id ) ,
185+ cohort_imports : patient . cohort_imports . pluck ( :id ) ,
186+ sessions : patient . sessions . pluck ( :id )
187187 }
188188 end
189189
0 commit comments