Skip to content

Commit bbec131

Browse files
Refactor reset_national_reporting to use PatientDeleter
Jira-Issue: MAV-7067
1 parent c0eaa82 commit bbec131

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

app/lib/mavis_cli/teams/reset_national_reporting.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,17 @@ def reset_team(team)
145145

146146
patients_to_destroy =
147147
find_patients_without_team(patient_ids_of_not_synced_records)
148-
# We need to ensure we only update statuses for patients who are not
149-
# destroyed. This should be the same as the list of patients _with_
150-
# a team, but it's fine to use this subtraction to be safe.
148+
151149
patient_ids_to_update +=
152150
patient_ids_of_not_synced_records - patients_to_destroy.ids
153151
puts " - Found #{patients_to_destroy.count}" \
154152
" patient(s) who were in the imports, and no longer have teams"
155153

156-
access_log_entries =
157-
AccessLogEntry.where(patient_id: patients_to_destroy.ids)
158-
puts " - Found #{access_log_entries.count} access_log_entries for" \
159-
" patients without teams"
160-
161-
puts "Destroying access-log-entries..."
162-
access_log_entries.destroy_all
163-
164-
puts "Destroying patients..."
165-
patients_to_destroy.destroy_all
154+
puts "Destroying #{patients_to_destroy.count} patients..."
155+
PatientDeleter.call(
156+
patients: patients_to_destroy,
157+
confirm_production_delete: true
158+
)
166159
end
167160

168161
puts "Enqueueing jobs to update statuses for" \

0 commit comments

Comments
 (0)