diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-15 15:03:28 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-03-15 15:03:28 -0600 |
| commit | 0b9e665f1158bb31603f5ddd21bef7b46cb1d133 (patch) | |
| tree | 22a6ba6c62592e3785ea944fc5ea7ae22bd584ad /rvh/db | |
| parent | edffd650265c6cccc7f359d2f6213447680b76c3 (diff) | |
Generate seed data
Diffstat (limited to 'rvh/db')
| -rw-r--r-- | rvh/db/migrate/20200315180939_create_care_centres.rb | 2 | ||||
| -rw-r--r-- | rvh/db/migrate/20200315181211_create_employees.rb | 4 | ||||
| -rw-r--r-- | rvh/db/migrate/20200315204511_create_laboratories.rb | 10 | ||||
| -rw-r--r-- | rvh/db/schema.rb | 14 | ||||
| -rw-r--r-- | rvh/db/seeds.rb | 93 |
5 files changed, 79 insertions, 44 deletions
diff --git a/rvh/db/migrate/20200315180939_create_care_centres.rb b/rvh/db/migrate/20200315180939_create_care_centres.rb index 14b60dd..c02846c 100644 --- a/rvh/db/migrate/20200315180939_create_care_centres.rb +++ b/rvh/db/migrate/20200315180939_create_care_centres.rb @@ -1,7 +1,7 @@ class CreateCareCentres < ActiveRecord::Migration[6.0] def change create_table :care_centres do |t| - t.references :employee, null: true + t.references :employee, null: false t.string :name t.string :location diff --git a/rvh/db/migrate/20200315181211_create_employees.rb b/rvh/db/migrate/20200315181211_create_employees.rb index 8580859..4dd6878 100644 --- a/rvh/db/migrate/20200315181211_create_employees.rb +++ b/rvh/db/migrate/20200315181211_create_employees.rb @@ -2,9 +2,11 @@ class CreateEmployees < ActiveRecord::Migration[6.0] def change create_table :employees do |t| t.references :account, null: false, foreign_key: true, index: { unique: true } + t.references :laboratory, null: true, foreign_key: true t.string :type t.datetime :hired_at - t.text :qualifications, array: true # physician.specialty, technician.skill, nurse.certification + # physician.specialty, technician.skill, nurse.certification + t.text :qualifications, array: true t.timestamps end add_index :employees, :type diff --git a/rvh/db/migrate/20200315204511_create_laboratories.rb b/rvh/db/migrate/20200315204511_create_laboratories.rb new file mode 100644 index 0000000..6a45e84 --- /dev/null +++ b/rvh/db/migrate/20200315204511_create_laboratories.rb @@ -0,0 +1,10 @@ +class CreateLaboratories < ActiveRecord::Migration[6.0] + def change + create_table :laboratories do |t| + t.string :name + t.string :location + + t.timestamps + end + end +end diff --git a/rvh/db/schema.rb b/rvh/db/schema.rb index 069ee00..d8c3627 100644 --- a/rvh/db/schema.rb +++ b/rvh/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_03_15_190540) do +ActiveRecord::Schema.define(version: 2020_03_15_204511) do create_table "accounts", force: :cascade do |t| t.string "name", null: false @@ -33,7 +33,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do end create_table "care_centres", force: :cascade do |t| - t.integer "employee_id" + t.integer "employee_id", null: false t.string "name" t.string "location" t.datetime "created_at", precision: 6, null: false @@ -55,12 +55,14 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do create_table "employees", force: :cascade do |t| t.integer "account_id", null: false + t.integer "laboratory_id" t.string "type" t.datetime "hired_at" t.text "qualifications" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["account_id"], name: "index_employees_on_account_id", unique: true + t.index ["laboratory_id"], name: "index_employees_on_laboratory_id" t.index ["type"], name: "index_employees_on_type" end @@ -72,6 +74,13 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do t.datetime "updated_at", precision: 6, null: false end + create_table "laboratories", force: :cascade do |t| + t.string "name" + t.string "location" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "patients", force: :cascade do |t| t.integer "account_id", null: false t.datetime "contacted_at", null: false @@ -125,6 +134,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do add_foreign_key "consumptions", "items" add_foreign_key "consumptions", "patients" add_foreign_key "employees", "accounts" + add_foreign_key "employees", "laboratories" add_foreign_key "patients", "accounts" add_foreign_key "shifts", "care_centres" add_foreign_key "shifts", "employees" diff --git a/rvh/db/seeds.rb b/rvh/db/seeds.rb index b60228d..d7507dd 100644 --- a/rvh/db/seeds.rb +++ b/rvh/db/seeds.rb @@ -1,44 +1,57 @@ -puts "Create seed data" +ApplicationRecord.transaction do + [ + { name: 'Intensive Care Unit', location: 'MT-M' }, + { name: 'Pshychiatry', location: 'FMC-2' }, + { name: 'Adult Outpatient Mental Health', location: 'SSB-2' }, + { name: 'Child & Adolescent Pshyciatry', location: 'SSB-2' }, + { name: 'Burns', location: 'FMC-3' }, + { name: 'Surgery - Head & Neck / Plastics', location: 'FMC-3' }, + { name: 'Acute Medicine', location: 'FMC-3' }, + { name: 'Medicine', location: 'SSB-3' }, + { name: 'Renal', location: 'SSB-3' }, + { name: 'Solid Organ Transplant', location: 'SSB-3' }, + { name: 'Ante Partum', location: 'FMC-4' }, + { name: 'Surgery - Short Stay', location: 'FMC-4' }, + { name: 'Gynecology / Gyne-Oncology', location: 'FMC-4' }, + { name: 'Trauma', location: 'MT-4' }, + { name: 'Medicine', location: 'SSB-4' }, + { name: 'Acute Medicine / Aphersis', location: 'SSB-4' }, + { name: 'Labour & Delivery', location: 'FMC-5' }, + { name: 'Post Partum', location: 'FMC-5' }, + { name: 'Orthopedics', location: 'MT-5' }, + { name: 'Neonatal Intensive Care Unit (NICU)', location: 'FMC-5' }, + { name: 'Hematology / Oncology / BMT', location: 'SSB-5' }, + { name: 'Hematology / BMT / Day Medicine', location: 'SSB-5' }, + { name: 'Neuro Rehab', location: 'SSB-5' }, + { name: 'Thoracic Surgery / Pulmonary Medicine', location: 'SSB-6' }, + { name: 'Medicine', location: 'FMC-6' }, + { name: 'Orthopedics', location: 'MT-6' }, + { name: 'Transition', location: 'FMC-7' }, + ].each do |attributes| + nurse = Nurse.create!({ + account: Account.create!({ name: "Nurse #{Time.now.nsec}", address: '123 1 street NW', birth_date: 30.years.ago }), + hired_at: 1.year.ago, + qualifications: ['medicine'] + }) + care_centre = CareCentre.create!(attributes.merge(nurse_in_charge: nurse)) + Bed.create!(rand(100).times.map { |n| { care_centre: care_centre, room_number: n.to_s } }) + end -CareCentre.create!([ - { name: 'Intensive Care Unit', location: 'MT-M' }, - { name: 'Pshychiatry', location: 'FMC-2' }, - { name: 'Adult Outpatient Mental Health', location: 'SSB-2' }, - { name: 'Child & Adolescent Pshyciatry', location: 'SSB-2' }, - { name: 'Burns', location: 'FMC-3' }, - { name: 'Surgery - Head & Neck / Plastics', location: 'FMC-3' }, - { name: 'Acute Medicine', location: 'FMC-3' }, - { name: 'Medicine', location: 'SSB-3' }, - { name: 'Renal', location: 'SSB-3' }, - { name: 'Solid Organ Transplant', location: 'SSB-3' }, - { name: 'Ante Partum', location: 'FMC-4' }, - { name: 'Surgery - Short Stay', location: 'FMC-4' }, - { name: 'Gynecology / Gyne-Oncology', location: 'FMC-4' }, - { name: 'Trauma', location: 'MT-4' }, - { name: 'Medicine', location: 'SSB-4' }, - { name: 'Acute Medicine / Aphersis', location: 'SSB-4' }, - { name: 'Labour & Delivery', location: 'FMC-5' }, - { name: 'Post Partum', location: 'FMC-5' }, - { name: 'Orthopedics', location: 'MT-5' }, - { name: 'Neonatal Intensive Care Unit (NICU)', location: 'FMC-5' }, - { name: 'Hematology / Oncology / BMT', location: 'SSB-5' }, - { name: 'Hematology / BMT / Day Medicine', location: 'SSB-5' }, - { name: 'Neuro Rehab', location: 'SSB-5' }, - { name: 'Thoracic Surgery / Pulmonary Medicine', location: 'SSB-6' }, - { name: 'Medicine', location: 'FMC-6' }, - { name: 'Orthopedics', location: 'MT-6' }, - { name: 'Transition', location: 'FMC-7' }, -]) + Physician.create!([ + { + account: Account.create!({ name: 'nini', address: '234 1 street NW', birth_date: 10.years.ago }), + hired_at: 1.month.ago, + qualifications: ['heart', 'brain'] + } + ]) -CareCentre.find_each do |care_centre| - Bed.create!(10.times.map { |n| { care_centre: care_centre, room_number: n.to_s } }) + Patient.create!([ ]) end -Employee.create!([ - { - account: Account.create!({ name: 'mo', address: '123 1 street NW', birth_date: 30.years.ago }), - type: 'Nurse', - hired_at: 1.year.ago, - qualifications: ['medicine'] - } -]) +CareCentre.find_each do |centre| + puts centre.name + puts "-" * 10 + puts "Nurse: #{centre&.nurse_in_charge&.name}" + puts "Beds: #{centre.beds.count}" + puts "Beds Available: #{centre.beds.available.count}" +end |
