@@ -69,6 +69,9 @@ def initialize(team:, patient:, session: nil)
6969 session ? scope . where ( location : session . location ) : scope
7070 end
7171
72+ @patient_merge_log_entries =
73+ @patient . patient_merge_log_entries . includes ( :user )
74+
7275 @patient_specific_directions =
7376 @patient
7477 . patient_specific_directions
@@ -105,6 +108,7 @@ def initialize(team:, patient:, session: nil)
105108 :notify_log_entries ,
106109 :patient ,
107110 :patient_locations ,
111+ :patient_merge_log_entries ,
108112 :patient_specific_directions ,
109113 :pre_screenings ,
110114 :attendance_records ,
@@ -124,6 +128,7 @@ def all_events
124128 gillick_assessment_events ,
125129 note_events ,
126130 notify_events ,
131+ patient_merge_events ,
127132 patient_specific_direction_events ,
128133 pre_screening_events ,
129134 session_events ,
@@ -309,6 +314,21 @@ def notify_events
309314 end
310315 end
311316
317+ def patient_merge_events
318+ patient_merge_log_entries . map do |patient_merge_log_entry |
319+ {
320+ title : "Child record merged" ,
321+ body :
322+ "The record for #{ patient_merge_log_entry . merged_patient_name } (date of birth " \
323+ "#{ patient_merge_log_entry . merged_patient_dob . to_fs ( :long ) } ) was merged with the record for " \
324+ "#{ patient . full_name } (date of birth #{ patient . date_of_birth . to_fs ( :long ) } ) because they have the same " \
325+ "NHS number (#{ patient_merge_log_entry . merged_patient_nhs_number } )." ,
326+ at : patient_merge_log_entry . created_at ,
327+ by : patient_merge_log_entry . user
328+ }
329+ end
330+ end
331+
312332 def patient_specific_direction_events
313333 patient_specific_directions . flat_map do |patient_specific_direction |
314334 events = [ ]
0 commit comments