Skip to content

Instantly share code, notes, and snippets.

@itsaliu90
itsaliu90 / ps_single_cp_split.rb
Last active September 25, 2018 21:00
ps_single_cp_split
i="[cp_id]"
echo "splitting care provider: $i"
echo "splitting care provider: $i" >> /var/www/banff/patient_splitting_output.log
date >> /var/www/banff/patient_splitting_output.log
bin/rake "migrate:split_patients[$i]" >> /var/www/banff/patient_splitting_output.log
echo "done" >> /var/www/banff/patient_splitting_output.log
echo "" >> /var/www/banff/patient_splitting_output.log
echo "" >> /var/www/banff/patient_splitting_output.log
def sanity_check(cp_id)
patient_count = Patient.where(care_provider_ids: cp_id).count
encounter_count = Encounter.where(care_provider_id: cp_id).count
patient_interaction_count = PatientInteraction.where(care_provider_id: cp_id).count
patient_issue_count = PatientIssue.where(care_provider_id: cp_id).count
archived_call_attempt_count = ArchivedCallAttempt.where(care_provider_id: cp_id).count
puts "#{patient_count}\t#{encounter_count}\t#{patient_interaction_count}\t#{patient_issue_count}\t#{archived_call_attempt_count}"
end
@itsaliu90
itsaliu90 / patient_splitting.sh
Last active February 15, 2019 18:24
ps_multiple_cps
cps=(
560188d45241493461290200 # example, can have more
)
for i in "${cps[@]}"
do
echo "splitting care provider: $i"
echo "splitting care provider: $i" >> /var/www/banff/patient_splitting_output.log
date >> /var/www/banff/patient_splitting_output.log
bin/rake "migrate:split_patients[$i, 1.5]" >> /var/www/banff/patient_splitting_output.log
hfhs-dcc-1
=============
2018-04-22 17:09:29 UTC
2018-04-22 18:09:29 UTC
2018-04-22 19:09:29 UTC
2018-04-22 20:09:29 UTC
2018-04-22 21:09:29 UTC
2018-04-22 22:09:29 UTC
2018-04-22 23:09:29 UTC
2018-04-23 00:09:29 UTC
hfhs-dcc-1
=============
2018-04-24 03:09:31 UTC
2018-04-24 04:09:31 UTC
2018-04-24 05:09:31 UTC
2018-04-24 06:09:31 UTC
2018-04-24 07:09:32 UTC
2018-04-24 08:09:31 UTC
2018-04-24 09:09:31 UTC
2018-04-24 10:09:31 UTC
[31] pry(main)> CallHourInfo.where(date: Date.today, hour: 16).sum(:scheduled_count)
7315
[32] pry(main)> CallHourInfo.where(date: Date.today, hour: 16).sum(:launched_count)
2324
[33] pry(main)> CallHourInfo.where(date: Date.today, hour: 16).sum(:launched_count)
3350
@itsaliu90
itsaliu90 / gist:8f765a1275d3517b0c033e9be8982d75
Last active April 17, 2018 20:47
Locations Migration Testing
bin/rake locations_migrations:setup_script
bin/rake orchid:patients_as_units_to_locations['54de417552414945b5070000']
[18] pry(main)> SurveyDeviceQuery.in(cp).non_patient_devices.active.gt(last_login_at: 7.days.ago).each do |device|
[18] pry(main)* puts device.name
[18] pry(main)* puts "============="
[18] pry(main)* puts Ahoy::Event.where(survey_device_id: device.id, name: "surveys#sync").gt(time: 120.hours.ago).map(&:time)
[18] pry(main)* puts "============="
[18] pry(main)* puts ""
[18] pry(main)* end
hfhs-dnw-2
=============
2018-03-26 11:31:48 UTC
@itsaliu90
itsaliu90 / hfhs_daily_task.rb
Last active March 30, 2018 12:52
Daily Task for HFHS
hfhs = CareProvider.find('54130e4261706f24c3040000')
devices = SurveyDeviceQuery.in(hfhs).non_patient_devices.active.distinct(:_id.to_s)
devices_set = Set.new(devices.map(&:to_s))
sessions = MongoidSessionStore::Session.all.each_with_index.select { |session, i|
puts i if i % 10_000 == 0
devices_set.member?(session.data['current_survey_device_id'].to_s)
}.map(&:first)
sessions.map { |session| session.set(updated_at: Time.now + 2.weeks) }
[38] pry(main)> MongoidSessionStore::Session.first
#<MongoidSessionStore::Session:0x0001004c60caa0> {
:_id => "0000003be350a2878805642c498689d6",
:created_at => 2018-03-21 15:08:15 UTC,
:data => <BSON::Binary:0x550396521800 type=generic data=0x04087b0649221a63...>,
:updated_at => 2018-03-21 15:08:15 UTC
}
[39] pry(main)> MongoidSessionStore::Session.first.data
{
"current_care_provider" => BSON::ObjectId('59516787d27cbede1924d757')