summaryrefslogtreecommitdiff
path: root/rvh
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-15 15:03:28 -0600
committermo khan <mo.khan@gmail.com>2020-03-15 15:03:28 -0600
commit0b9e665f1158bb31603f5ddd21bef7b46cb1d133 (patch)
tree22a6ba6c62592e3785ea944fc5ea7ae22bd584ad /rvh
parentedffd650265c6cccc7f359d2f6213447680b76c3 (diff)
Generate seed data
Diffstat (limited to 'rvh')
-rw-r--r--rvh/app/models/bed.rb2
-rw-r--r--rvh/app/models/care_centre.rb3
-rw-r--r--rvh/app/models/employee.rb11
-rw-r--r--rvh/app/models/laboratory.rb3
-rw-r--r--rvh/app/models/nurse.rb2
-rw-r--r--rvh/app/models/physician.rb2
-rw-r--r--rvh/app/models/technician.rb2
-rw-r--r--rvh/db/migrate/20200315180939_create_care_centres.rb2
-rw-r--r--rvh/db/migrate/20200315181211_create_employees.rb4
-rw-r--r--rvh/db/migrate/20200315204511_create_laboratories.rb10
-rw-r--r--rvh/db/schema.rb14
-rw-r--r--rvh/db/seeds.rb93
12 files changed, 95 insertions, 53 deletions
diff --git a/rvh/app/models/bed.rb b/rvh/app/models/bed.rb
index 5ef472e..0b0869e 100644
--- a/rvh/app/models/bed.rb
+++ b/rvh/app/models/bed.rb
@@ -2,6 +2,8 @@ class Bed < ApplicationRecord
belongs_to :care_centre
belongs_to :patient, optional: true
+ scope :available, -> { where(patient: nil) }
+
def available?
patient.blank?
end
diff --git a/rvh/app/models/care_centre.rb b/rvh/app/models/care_centre.rb
index 465952a..90bd3cc 100644
--- a/rvh/app/models/care_centre.rb
+++ b/rvh/app/models/care_centre.rb
@@ -1,3 +1,4 @@
class CareCentre < ApplicationRecord
- belongs_to :employee, optional: true
+ belongs_to :nurse_in_charge, class_name: Nurse.name, foreign_key: :employee_id
+ has_many :beds
end
diff --git a/rvh/app/models/employee.rb b/rvh/app/models/employee.rb
index f33a29a..89cba4c 100644
--- a/rvh/app/models/employee.rb
+++ b/rvh/app/models/employee.rb
@@ -2,13 +2,8 @@ class Employee < ApplicationRecord
belongs_to :account
has_many :treatments
serialize :qualifications, Array
-end
-
-class Nurse < Employee
-end
-
-class Physician < Employee
-end
-class Technician < Employee
+ delegate :name, to: :account
+ delegate :phone_number, to: :account
+ delegate :pager_number, to: :account
end
diff --git a/rvh/app/models/laboratory.rb b/rvh/app/models/laboratory.rb
new file mode 100644
index 0000000..5890c95
--- /dev/null
+++ b/rvh/app/models/laboratory.rb
@@ -0,0 +1,3 @@
+class Laboratory < ApplicationRecord
+ has_many :employees, -> { where(type: Technician.name) }
+end
diff --git a/rvh/app/models/nurse.rb b/rvh/app/models/nurse.rb
new file mode 100644
index 0000000..0c06dc1
--- /dev/null
+++ b/rvh/app/models/nurse.rb
@@ -0,0 +1,2 @@
+class Nurse < Employee
+end
diff --git a/rvh/app/models/physician.rb b/rvh/app/models/physician.rb
new file mode 100644
index 0000000..abec287
--- /dev/null
+++ b/rvh/app/models/physician.rb
@@ -0,0 +1,2 @@
+class Physician < Employee
+end
diff --git a/rvh/app/models/technician.rb b/rvh/app/models/technician.rb
new file mode 100644
index 0000000..b537f79
--- /dev/null
+++ b/rvh/app/models/technician.rb
@@ -0,0 +1,2 @@
+class Technician < Employee
+end
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