Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
MAT-1977 Create Ruby script to Pull Patient Data from Bonnie (#1578)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Ilin authored Oct 9, 2020
1 parent dfadf9c commit d6890fe
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/tasks/bonnie.rake
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,45 @@ namespace :bonnie do
puts 'Done!'
end

task :export_patients_for_user => :environment do
# Grab user account
user_email = ENV['EMAIL']
raise "#{user_email} not found" unless user = User.find_by(email: user_email)

# Grab the patients
patients = CQM::Patient.where(user_id: user._id)

# Write patient objects to file in JSON format
puts 'Exporting patients...'
raise 'FILENAME not specified' unless output_file = ENV['FILENAME']
File.open(File.join(Rails.root, output_file), 'w') do |f|
patients.each do |patient|
f.puts(patient.as_document.to_json)
end
end

puts 'Done!'
end

task :export_all_patients => :environment do
# Grab the patients
patients = CQM::Patient.all

# Write patient objects to file in JSON format
puts 'Exporting patients...'
raise 'FILENAME not specified' unless output_file = ENV['FILENAME']
File.open(File.join(Rails.root, output_file), 'w') do |f|
# f.puts('[')
patients.each do |patient|
f.puts(patient.as_document.to_json)
# f.puts(patient.as_document.to_json + ',')
end
# f.puts(']')
end

puts 'Done!'
end

desc %{Import Bonnie patients from a JSON file.
The JSON file must be the one that is generated using the export_patients rake task.
Expand Down

0 comments on commit d6890fe

Please sign in to comment.