-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Story card:** [sc-14511](https://app.shortcut.com/simpledotorg/story/14511/enable-sms-for-uhcs-in-bd) ## Because We need to resume sending SMSs in BD ## This addresses Generating a `data_migration` to setup SMSs in BD ## Test instructions n/a
- Loading branch information
Showing
1 changed file
with
68 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,68 @@ | ||
# frozen_string_literal: true | ||
|
||
class SetupBdh12025SmsSchedule < ActiveRecord::Migration[6.1] | ||
EXPERIMENTS_DATA = %w[Jan Feb Mar Apr May Jun].map do |month| | ||
{ | ||
current_experiment_name: "Current patients #{month} 2025", | ||
stale_experiment_name: "Stale patients #{month} 2025", | ||
start_time: "#{month} 2025".to_datetime.beginning_of_month, | ||
end_time: "#{month} 2025".to_datetime.end_of_month | ||
} | ||
end | ||
|
||
MAX_PATIENTS_PER_DAY = 5000 | ||
|
||
INCLUDED_FACILITY_SLUG = Facility | ||
.where(facility_type: "UHC") | ||
.where.not(slug: [ | ||
"uhc-fatikchori", | ||
"uhc-parsuram", | ||
"uhc-daganbhuiya" | ||
]) | ||
.pluck(:slug) | ||
|
||
REGION_FILTERS = { | ||
"facilities" => {"include" => INCLUDED_FACILITY_SLUG} | ||
}.freeze | ||
|
||
def up | ||
return unless CountryConfig.current_country?("Bangladesh") && SimpleServer.env.production? | ||
EXPERIMENTS_DATA.each do |experiment_data| | ||
ActiveRecord::Base.transaction do | ||
Experimentation::Experiment.current_patients.create!( | ||
name: (experiment_data[:current_experiment_name]).to_s, | ||
start_time: experiment_data[:start_time], | ||
end_time: experiment_data[:end_time], | ||
max_patients_per_day: MAX_PATIENTS_PER_DAY, | ||
filters: REGION_FILTERS | ||
).tap do |experiment| | ||
treatment_group = experiment.treatment_groups.create!(description: "cascade_free") | ||
treatment_group.reminder_templates.create!(message: "notifications.set03.free", remind_on_in_days: 1) | ||
treatment_group.reminder_templates.create!(message: "notifications.set03.free", remind_on_in_days: 3) | ||
end | ||
end | ||
|
||
ActiveRecord::Base.transaction do | ||
Experimentation::Experiment.stale_patients.create!( | ||
name: (experiment_data[:stale_experiment_name]).to_s, | ||
start_time: experiment_data[:start_time], | ||
end_time: experiment_data[:end_time], | ||
max_patients_per_day: MAX_PATIENTS_PER_DAY, | ||
filters: REGION_FILTERS | ||
).tap do |experiment| | ||
treatment_group = experiment.treatment_groups.create!(description: "cascade_free") | ||
treatment_group.reminder_templates.create!(message: "notifications.set02.free", remind_on_in_days: 0) | ||
treatment_group.reminder_templates.create!(message: "notifications.set03.free", remind_on_in_days: 3) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def down | ||
return unless CountryConfig.current_country?("Bangladesh") && SimpleServer.env.production? | ||
EXPERIMENTS_DATA.each do |experiment_data| | ||
Experimentation::Experiment.current_patients.find_by_name(experiment_data[:current_experiment_name])&.cancel | ||
Experimentation::Experiment.stale_patients.find_by_name(experiment_data[:stale_experiment_name])&.cancel | ||
end | ||
end | ||
end |