-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data migration to cleanup a Bangladesh facility (#5354)
## Because We need to remove all this data with one of our partners integrating with the import API.
- Loading branch information
1 parent
55f8c07
commit ab74f49
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class CleanupIcddrbFacilityData < ActiveRecord::Migration[6.1] | ||
FACILITY_ID = "f472c5db-188f-4563-9bc7-9f86a6ed6403" | ||
|
||
def up | ||
unless CountryConfig.current_country?("Bangladesh") && ENV["SIMPLE_SERVER_ENV"] == "production" | ||
return print "CleanupIcddrbFacilityData is only for production Bangladesh" | ||
end | ||
|
||
ActiveRecord::Base.transaction do | ||
Appointment.where(facility_id: FACILITY_ID).delete_all | ||
PrescriptionDrug.where(facility_id: FACILITY_ID).delete_all | ||
MedicalHistory.joins(:patient).where(patient: {assigned_facility_id: FACILITY_ID}).delete_all | ||
BloodSugar.where(facility_id: FACILITY_ID).delete_all | ||
BloodPressure.where(facility_id: FACILITY_ID).delete_all | ||
Observation.joins(:encounter).where(encounters: {facility_id: FACILITY_ID}).delete_all | ||
Encounter.where(facility_id: FACILITY_ID).delete_all | ||
PatientPhoneNumber.joins(:patient).where(patient: {assigned_facility_id: FACILITY_ID}).delete_all | ||
PatientBusinessIdentifier.joins(:patient).where(patient: {assigned_facility_id: FACILITY_ID}).delete_all | ||
addresses = Address.joins("JOIN patients ON patients.address_id=addresses.id").where(patients: {assigned_facility_id: FACILITY_ID}) | ||
Patient.where(assigned_facility_id: FACILITY_ID).delete_all | ||
addresses.delete_all | ||
end | ||
end | ||
|
||
def down | ||
puts "This migration cannot be reversed." | ||
end | ||
end |