Skip to content

Commit

Permalink
Add patient_sessions:add_to_clinic (#3113)
Browse files Browse the repository at this point in the history
This adds a Rake task that helps with the post-deploy tasks for version
2.0.0 where all patients are expected to be found in the community
clinics session. Once this has been run in all environments we can
delete this Rake task.
  • Loading branch information
thomasleese authored Feb 28, 2025
2 parents 6fcd8d6 + 4cc2792 commit 427ea8f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/tasks/patient_sessions.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

namespace :patient_sessions do
desc "Ensures all patients exist in both schools and clinics."
task add_to_clinic: :environment do |_task, _args|
count = PatientSession.count
puts "#{count} existing patient sessions."

to_import =
PatientSession
.includes(session: :organisation)
.map do
PatientSession.new(
patient_id: it.patient_id,
session: it.session.organisation.generic_clinic_session
)
end

PatientSession.import(to_import, on_duplicate_key_ignore: :all)

puts "#{PatientSession.count - count} new patient sessions created."
end
end

0 comments on commit 427ea8f

Please sign in to comment.