Created
August 24, 2011 12:32
-
-
Save marklocklear/1167966 to your computer and use it in GitHub Desktop.
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
namespace :db do | |
desc "populate random data for testing" | |
task :create_data => :environment do | |
require 'populator' | |
require 'faker' | |
#NOTE These deletions may not work on heroku. You will need to reset/load db for primary key ids to reset | |
#[Site, Therapist, PatientAuthorization, Patient, Visit].each(&:delete_all) | |
#user 1 | |
Site.populate 10 do |site| | |
site.site_name = 'ml' + Populator.words(1..2).titleize | |
site.user_id = 1 | |
end | |
Therapist.populate 5 do |therapist| | |
therapist.user_id = 1 | |
therapist.first_name = 'ml' + Populator.words(1).titleize | |
therapist.middle_name = Populator.words(1).titleize | |
therapist.last_name = Populator.words(1).titleize | |
therapist.address_1 = Faker::Address.street_name | |
therapist.address_2 = Faker::Address.street_name | |
therapist.city = Faker::Address.city | |
therapist.state = Faker::Address.us_state_abbr | |
therapist.zip = Populator.value_in_range(28363..82334) | |
therapist.phone = Faker::PhoneNumber.phone_number | |
therapist.created_at = 2.years.ago..Time.now | |
end | |
Patient.populate 500 do |patient| | |
patient.therapist_id = Populator.value_in_range(1..5) | |
patient.first_name = 'ml' + Populator.words(1).titleize | |
patient.middle_name = Populator.words(1).titleize | |
patient.last_name = Populator.words(1).titleize | |
patient.contact = Populator.words(2).titleize | |
patient.medicaid_number = Populator.value_in_range(111111111..999999999) | |
patient.address_1 = Faker::Address.street_address | |
patient.address_2 = ['', 'Apartment 2', 'Box 8', 'Apt. 302'] | |
patient.city = Faker::Address.city | |
patient.state = Faker::Address.us_state_abbr | |
patient.zip = Populator.value_in_range(27773..89223) | |
patient.phone = Faker::PhoneNumber.phone_number | |
patient.dob = 80.years.ago..5.years.ago | |
patient.created_at = 2.years.ago..Time.now | |
PatientAuthorization.populate 1 do |pat_auth| | |
pat_auth.patient_id = patient.id | |
pat_auth.from_date = 2.years.ago..Time.now | |
pat_auth.to_date = pat_auth.from_date..Time.now | |
pat_auth.initial_number_visits = Populator.value_in_range(10..30) | |
pat_auth.active = true | |
Visit.populate pat_auth.initial_number_visits - 1 do |visit| | |
visit.site_id = Populator.value_in_range(1..10) | |
visit.patient_authorization_id = pat_auth.id | |
visit.visit_date = pat_auth.from_date..pat_auth.to_date | |
visit.visit_notes = Populator.sentences(5..10) | |
visit.created_at = visit.visit_date | |
visit.session_length = Populator.value_in_range(30..60) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment