summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-15 14:38:00 -0600
committermo khan <mo.khan@gmail.com>2020-03-15 14:38:00 -0600
commitedffd650265c6cccc7f359d2f6213447680b76c3 (patch)
treebab9312142c631f5f81c10f95f5a5644c23c9665
parent863d9a4928309d36b99ff63a7a214d6e5c3df80c (diff)
Try to build seed data
-rw-r--r--rvh/app/models/bed.rb2
-rw-r--r--rvh/app/models/care_centre.rb2
-rw-r--r--rvh/app/models/employee.rb2
-rw-r--r--rvh/db/migrate/20200315180103_create_patients.rb2
-rw-r--r--rvh/db/migrate/20200315180939_create_care_centres.rb2
-rw-r--r--rvh/db/migrate/20200315181211_create_employees.rb2
-rw-r--r--rvh/db/migrate/20200315190540_create_volunteers.rb2
-rw-r--r--rvh/db/schema.rb11
-rw-r--r--rvh/db/seeds.rb43
9 files changed, 55 insertions, 13 deletions
diff --git a/rvh/app/models/bed.rb b/rvh/app/models/bed.rb
index 592bd8d..5ef472e 100644
--- a/rvh/app/models/bed.rb
+++ b/rvh/app/models/bed.rb
@@ -1,6 +1,6 @@
class Bed < ApplicationRecord
belongs_to :care_centre
- belongs_to :patient
+ belongs_to :patient, optional: true
def available?
patient.blank?
diff --git a/rvh/app/models/care_centre.rb b/rvh/app/models/care_centre.rb
index 08767dc..465952a 100644
--- a/rvh/app/models/care_centre.rb
+++ b/rvh/app/models/care_centre.rb
@@ -1,3 +1,3 @@
class CareCentre < ApplicationRecord
- belongs_to :employee, polymorphic: true
+ belongs_to :employee, optional: true
end
diff --git a/rvh/app/models/employee.rb b/rvh/app/models/employee.rb
index 3a31c17..f33a29a 100644
--- a/rvh/app/models/employee.rb
+++ b/rvh/app/models/employee.rb
@@ -1,7 +1,7 @@
class Employee < ApplicationRecord
belongs_to :account
has_many :treatments
- attribute :qualifications, :string, array: true
+ serialize :qualifications, Array
end
class Nurse < Employee
diff --git a/rvh/db/migrate/20200315180103_create_patients.rb b/rvh/db/migrate/20200315180103_create_patients.rb
index f2ab2ca..f20b23f 100644
--- a/rvh/db/migrate/20200315180103_create_patients.rb
+++ b/rvh/db/migrate/20200315180103_create_patients.rb
@@ -1,7 +1,7 @@
class CreatePatients < ActiveRecord::Migration[6.0]
def change
create_table :patients do |t|
- t.references :account, null: false, foreign_key: true
+ t.references :account, null: false, foreign_key: true, index: { unique: true }
t.datetime :contacted_at, null: false
t.timestamps
diff --git a/rvh/db/migrate/20200315180939_create_care_centres.rb b/rvh/db/migrate/20200315180939_create_care_centres.rb
index 42c0884..14b60dd 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, polymorphic: true, null: false
+ t.references :employee, null: true
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 b7bfd5f..8580859 100644
--- a/rvh/db/migrate/20200315181211_create_employees.rb
+++ b/rvh/db/migrate/20200315181211_create_employees.rb
@@ -1,7 +1,7 @@
class CreateEmployees < ActiveRecord::Migration[6.0]
def change
create_table :employees do |t|
- t.references :account, null: false, foreign_key: true
+ t.references :account, null: false, foreign_key: true, index: { unique: true }
t.string :type
t.datetime :hired_at
t.text :qualifications, array: true # physician.specialty, technician.skill, nurse.certification
diff --git a/rvh/db/migrate/20200315190540_create_volunteers.rb b/rvh/db/migrate/20200315190540_create_volunteers.rb
index 923fc47..0ec2a03 100644
--- a/rvh/db/migrate/20200315190540_create_volunteers.rb
+++ b/rvh/db/migrate/20200315190540_create_volunteers.rb
@@ -1,7 +1,7 @@
class CreateVolunteers < ActiveRecord::Migration[6.0]
def change
create_table :volunteers do |t|
- t.references :account, null: false, foreign_key: true
+ t.references :account, null: false, foreign_key: true, index: { unique: true }
t.text :skill, null: false
t.timestamps
diff --git a/rvh/db/schema.rb b/rvh/db/schema.rb
index b7be0da..069ee00 100644
--- a/rvh/db/schema.rb
+++ b/rvh/db/schema.rb
@@ -33,13 +33,12 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do
end
create_table "care_centres", force: :cascade do |t|
- t.string "employee_type", null: false
- t.integer "employee_id", null: false
+ t.integer "employee_id"
t.string "name"
t.string "location"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
- t.index ["employee_type", "employee_id"], name: "index_care_centres_on_employee_type_and_employee_id"
+ t.index ["employee_id"], name: "index_care_centres_on_employee_id"
end
create_table "consumptions", force: :cascade do |t|
@@ -61,7 +60,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do
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"
+ t.index ["account_id"], name: "index_employees_on_account_id", unique: true
t.index ["type"], name: "index_employees_on_type"
end
@@ -78,7 +77,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do
t.datetime "contacted_at", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
- t.index ["account_id"], name: "index_patients_on_account_id"
+ t.index ["account_id"], name: "index_patients_on_account_id", unique: true
end
create_table "shifts", force: :cascade do |t|
@@ -118,7 +117,7 @@ ActiveRecord::Schema.define(version: 2020_03_15_190540) do
t.text "skill", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
- t.index ["account_id"], name: "index_volunteers_on_account_id"
+ t.index ["account_id"], name: "index_volunteers_on_account_id", unique: true
end
add_foreign_key "beds", "care_centres"
diff --git a/rvh/db/seeds.rb b/rvh/db/seeds.rb
index a788dba..b60228d 100644
--- a/rvh/db/seeds.rb
+++ b/rvh/db/seeds.rb
@@ -1 +1,44 @@
puts "Create seed data"
+
+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' },
+])
+
+CareCentre.find_each do |care_centre|
+ Bed.create!(10.times.map { |n| { care_centre: care_centre, room_number: n.to_s } })
+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']
+ }
+])