From d9fc812024357bbc05b4fb2b9df0509183089833 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sun, 15 Mar 2020 12:41:30 -0600 Subject: Record consumptions --- rvh/app/models/consumption.rb | 4 ++++ rvh/app/models/item.rb | 3 +++ rvh/db/migrate/20200315183805_create_items.rb | 11 ++++++++++ .../migrate/20200315183903_create_consumptions.rb | 13 ++++++++++++ rvh/db/schema.rb | 24 +++++++++++++++++++++- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 rvh/app/models/consumption.rb create mode 100644 rvh/app/models/item.rb create mode 100644 rvh/db/migrate/20200315183805_create_items.rb create mode 100644 rvh/db/migrate/20200315183903_create_consumptions.rb diff --git a/rvh/app/models/consumption.rb b/rvh/app/models/consumption.rb new file mode 100644 index 0000000..bffa146 --- /dev/null +++ b/rvh/app/models/consumption.rb @@ -0,0 +1,4 @@ +class Consumption < ApplicationRecord + belongs_to :patient + belongs_to :item +end diff --git a/rvh/app/models/item.rb b/rvh/app/models/item.rb new file mode 100644 index 0000000..ad849b9 --- /dev/null +++ b/rvh/app/models/item.rb @@ -0,0 +1,3 @@ +class Item < ApplicationRecord + has_many :consumptions +end diff --git a/rvh/db/migrate/20200315183805_create_items.rb b/rvh/db/migrate/20200315183805_create_items.rb new file mode 100644 index 0000000..98242b1 --- /dev/null +++ b/rvh/db/migrate/20200315183805_create_items.rb @@ -0,0 +1,11 @@ +class CreateItems < ActiveRecord::Migration[6.0] + def change + create_table :items do |t| + t.string :sku, null: false + t.text :description + t.decimal :unit_cost, null: false + + t.timestamps + end + end +end diff --git a/rvh/db/migrate/20200315183903_create_consumptions.rb b/rvh/db/migrate/20200315183903_create_consumptions.rb new file mode 100644 index 0000000..5da1833 --- /dev/null +++ b/rvh/db/migrate/20200315183903_create_consumptions.rb @@ -0,0 +1,13 @@ +class CreateConsumptions < ActiveRecord::Migration[6.0] + def change + create_table :consumptions do |t| + t.references :patient, null: false, foreign_key: true + t.references :item, null: false, foreign_key: true + t.datetime :consumed_at, null: false + t.integer :quantity, null: false + t.decimal :total_cost, null: false + + t.timestamps + end + end +end diff --git a/rvh/db/schema.rb b/rvh/db/schema.rb index 55cd78a..1b8e238 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_183345) do +ActiveRecord::Schema.define(version: 2020_03_15_183903) do create_table "accounts", force: :cascade do |t| t.string "name", null: false @@ -41,6 +41,18 @@ ActiveRecord::Schema.define(version: 2020_03_15_183345) do t.index ["employee_type", "employee_id"], name: "index_care_centres_on_employee_type_and_employee_id" end + create_table "consumptions", force: :cascade do |t| + t.integer "patient_id", null: false + t.integer "item_id", null: false + t.datetime "consumed_at", null: false + t.integer "quantity", null: false + t.decimal "total_cost", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["item_id"], name: "index_consumptions_on_item_id" + t.index ["patient_id"], name: "index_consumptions_on_patient_id" + end + create_table "employees", force: :cascade do |t| t.integer "account_id", null: false t.string "type" @@ -51,6 +63,14 @@ ActiveRecord::Schema.define(version: 2020_03_15_183345) do t.index ["type"], name: "index_employees_on_type" end + create_table "items", force: :cascade do |t| + t.string "sku", null: false + t.text "description" + t.decimal "unit_cost", null: false + 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 @@ -93,6 +113,8 @@ ActiveRecord::Schema.define(version: 2020_03_15_183345) do add_foreign_key "beds", "care_centres" add_foreign_key "beds", "patients" + add_foreign_key "consumptions", "items" + add_foreign_key "consumptions", "patients" add_foreign_key "employees", "accounts" add_foreign_key "patients", "accounts" add_foreign_key "shifts", "care_centres" -- cgit v1.2.3