Skip to content

Commit

Permalink
Add data migration to cleanup a Bangladesh facility (#5354)
Browse files Browse the repository at this point in the history
## Because

We need to remove all this data with one of our partners integrating
with the import API.
  • Loading branch information
tfidfwastaken authored Dec 19, 2023
1 parent 55f8c07 commit ab74f49
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions db/data/20231213121605_cleanup_bd_org_data.rb
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

0 comments on commit ab74f49

Please sign in to comment.