Commit 6c2df9df authored by Greg Gard's avatar Greg Gard

adding migrations, models, enums

parent ede6ca9f
class Admission < ApplicationRecord
belongs_to :facility
belongs_to :patient
has_many :diagnoses
has_many :symptoms
has_many :observations
end
\ No newline at end of file
class Allergy < ApplicationRecord
belongs_to :patient
end
\ No newline at end of file
class Diagnosis < ApplicationRecord
belongs_to :admission
end
\ No newline at end of file
class DiagnosticProcedure < ApplicationRecord
after_initialize :set_defaults
# *****************************
#
#
belongs_to :patient
def set_defaults
self.moment ||= Time.now
end
end
\ No newline at end of file
class Facility < ApplicationRecord
has_many :admissions
end
\ No newline at end of file
class MedicationOrder < ApplicationRecord
enum unit: {mg: 0}
enum route: {PO: 0, IM: 1, SC: 2}
after_initialize :set_defaults
belongs_to :patient
def set_defaults
self.unit ||= :mg
end
end
\ No newline at end of file
class Observation < ApplicationRecord
after_initialize :set_defaults
# *******************************
# instance methods
#
belongs_to :admission
def set_defaults
self.moment ||= Time.now
end
end
\ No newline at end of file
class OrderFrequency < ApplicationRecord
enum unit: {hour: 0}
after_initialize :set_defaults
def set_defaults
self.unit ||= :hour
end
end
\ No newline at end of file
class Patient < ApplicationRecord
enum gender: {male: 1, female: 2, other: 0}
has_many :admissions
has_many :allergies
has_many :medication_orders
has_many :diagnostic_procedures
has_many :treatments
end
\ No newline at end of file
class Symptom < ApplicationRecord
belongs_to :admission
end
\ No newline at end of file
class Treatment < ApplicationRecord
belongs_to :patient
end
\ No newline at end of file
......@@ -4,19 +4,72 @@
# - goal to create "functionally pure" methods with no external dependencies or side-effects.
# - rails' tag implementation does, under the hood, rely on an output buffer in the target class (eg presener).
# might be interesting to convert these to self-contained classes with *_ui delegation in target class maybe.
# - would also consider refactoring to return presenter(self) rather than buffer so you could chain
# eg tag.div("test").h4("foo").html # dump buffer and mark html_safe
# - inspired by React components.
#
module TransfersComponent
def transfer_template(opts = {})
tag.div(class: 'test') do
tag.h4(opts[:title])
tag._text "This is just some plain <div>text</div> that isn't html safe"
tag._html "<h1>This should be big with no tags in text</h1>"
tag.div do
tag.h3 opts[:time]
tag.a(opts[:link_label], href: opts[:link_url])
def transfer_template(facility:, patient:, **opts)
tag.div(class: 'transfer_form-34ld') do
tag.h3(opts[:title])
tag.h4 "Transferring Facility"
tag.div do
tag.label "Name"
tag.span facility.name
end
tag.h4 "Patient Information"
tag.div do
tag.label "First Name"
tag.span patient.first_name
end
tag.div do
tag.label "Middle Name"
tag.span patient.middle_name
end
tag.div do
tag.label "Last Name"
tag.span patient.last_name
end
end
end
tag.div do
tag.label "Medical Record (MR)"
tag.span patient.mr
end
tag.div do
tag.label "Summary"
tag.p do
tag._text %Q[This [patient.age] years old [patient.gender] was admitted to [facility.name]
on [patient.admission.date]
at [patient.admission.time]
due to [patient.admission.diagnoses | comma_separated | described_code].
The observed symptoms on admission were [patient.admission.symptoms |comma_separated | description].
[patient.admission.observations | comma_separated | description].
]
end
tag.p do
tag._text %Q[Upon asking about known allergies, the patient disclosed [patient.allergies | comma_separated | description].
Upon asking about chronic conditions, the patient disclosed [patient.chronic_conditions | comma_separated | described_code].
The patient was administered with
[patient.medications | comma_separated | space_separated | name, dosage, route, frequency, “to”, necessity].
]
end
tag.p do
tag._text %Q[The staff performed [patient.diagnostic_procedures | comma_separated | description, “at”, time],
revealing [patient.diagnoses | comma_separated | described_code].
Our team proceeded to [patient.treatments | comma_separated | space_separated | description, “to”, necessity]
]
end
end
end # tag wrapper
end
end
\ No newline at end of file
......@@ -3,7 +3,7 @@ class TransfersPresenter < ApplicationPresenter
include TransfersComponent
DEFAULTS = {
title: "Emergency Transfer Form",
title: "Emergency Transfer Summary (Form 34L-D)",
link_label: 'Foo',
link_url: 'http://gardwired.com'
}.freeze
......
class CreatePatient < ActiveRecord::Migration[5.2]
def change
create_table :patients do |t|
t.string :first_name, null: false
t.string :middle_name
t.string :last_name, null: false
t.string :mr, null: false
t.date :dob
t.integer :gender # enum
t.index [:last_name, :first_name]
t.index :mr, unique: true
t.timestamps null: false
end
end
end
class CreateFacility < ActiveRecord::Migration[5.2]
def change
create_table :facilities do |t|
t.string :name, null: false
t.text :description
t.timestamps null: false
end
end
end
class CreateAdmission < ActiveRecord::Migration[5.2]
def change
create_table :admissions do |t|
t.integer :facility_id, null: false
t.integer :patient_id, null: false
t.timestamp :moment, null: false
t.timestamps null: false
end
end
end
class CreateDiagnosis < ActiveRecord::Migration[5.2]
def change
create_table :diagnoses do |t|
t.integer :admission_id, null: false
t.string :code, null: false
t.text :description
t.timestamps null: false
t.index :admission_id
end
end
end
class CreateSymptom < ActiveRecord::Migration[5.2]
def change
create_table :symptoms do |t|
t.integer :admission_id
t.text :description
t.timestamps null: false
end
end
end
class CreateObservation < ActiveRecord::Migration[5.2]
def change
create_table :observations do |t|
t.integer :admission_id
t.text :description
t.timestamp :moment, null: false
t.timestamps null: false
end
end
end
class CreateAllergy < ActiveRecord::Migration[5.2]
def change
create_table :allergies do |t|
t.integer :patient_id, null: false
t.text :description
t.timestamps null:false
end
end
end
class CreateMedicationOrder < ActiveRecord::Migration[5.2]
def change
create_table :medication_orders do |t|
t.integer :patient_id, null: false
t.string :name, null: false
t.integer :unit, null: false # enum
t.decimal :dosage, null: false
t.integer :route, null: false # enum
t.string :frequency, null: false
t.timestamps null:false
end
end
end
class CreateOrderFrequency < ActiveRecord::Migration[5.2]
def change
create_table :order_frequencies do |t|
t.string :value, null: false
t.integer :unit, null: false # enum
t.timestamps null: false
end
end
end
class CreateDiagnosticProcedure < ActiveRecord::Migration[5.2]
def change
create_table :diagnostic_procedures do |t|
t.integer :patient_id, null: false
t.text :description, null: false
t.timestamp :moment, null: false
t.timestamps null: false
end
end
end
class CreateTreatment < ActiveRecord::Migration[5.2]
def change
create_table :treatments do |t|
t.integer :patient_id, null: false
t.text :description, null: false
t.text :necessity
end
end
end
......@@ -10,6 +10,97 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 2018_05_28_085156) do
create_table "admissions", force: :cascade do |t|
t.integer "facility_id", null: false
t.integer "patient_id", null: false
t.datetime "moment", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "allergies", force: :cascade do |t|
t.integer "patient_id", null: false
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "diagnoses", force: :cascade do |t|
t.integer "admission_id", null: false
t.string "code", null: false
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["admission_id"], name: "index_diagnoses_on_admission_id"
end
create_table "diagnostic_procedures", force: :cascade do |t|
t.integer "patient_id", null: false
t.text "description", null: false
t.datetime "moment", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "facilities", force: :cascade do |t|
t.string "name", null: false
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "medication_orders", force: :cascade do |t|
t.integer "patient_id", null: false
t.string "name", null: false
t.integer "unit", null: false
t.decimal "dosage", null: false
t.integer "route", null: false
t.string "frequency", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "observations", force: :cascade do |t|
t.integer "admission_id"
t.text "description"
t.datetime "moment", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "order_frequencies", force: :cascade do |t|
t.string "value", null: false
t.integer "unit", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "patients", force: :cascade do |t|
t.string "first_name", null: false
t.string "middle_name"
t.string "last_name", null: false
t.string "mr", null: false
t.date "dob"
t.integer "gender"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["last_name", "first_name"], name: "index_patients_on_last_name_and_first_name"
t.index ["mr"], name: "index_patients_on_mr", unique: true
end
create_table "symptoms", force: :cascade do |t|
t.integer "admission_id"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "treatments", force: :cascade do |t|
t.integer "patient_id", null: false
t.text "description", null: false
t.text "necessity"
end
end
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
# sqlite doesn't support truncate which would be much faster on large pg db.
[
Admission, Allergy,
Diagnosis, DiagnosticProcedure, Facility, MedicationOrder, Observation,
OrderFrequency, Patient, Symptom, Treatment
].each{|k| k.delete_all}
admission_time = Time.now - 30.days
# ********************************
# facilities
#
# Examples:
f = Facility.create!(
name: 'All Sports Clinic',
description: 'APS specializes in emergency care for sports-related injuries.'
)
# **************************************
# patients
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
p = Patient.create!(
first_name: 'Fred',
middle_name: 'A',
last_name: 'Johnson',
mr: 'STB-234',
dob: '3/4/1975',
gender: :male
)
p.allergies.create!(
description: 'Penicillin'
)
p.medication_orders.create!(
name: 'Tylenol with Codeine',
unit: 'mg',
dosage: 60,
route: 'PO',
frequency: '4'
)
p.diagnostic_procedures.create!(
description: 'XRay of lower left tibia',
moment: admission_time
)
p.treatments.create!(
description: 'Set fracture in cast',
necessity: 'Meets medical necessity based on AMA standards.'
)
# ******************************
# admissions
#
a = p.admissions.create!(
moment: admission_time,
facility_id: f.id
)
a.diagnoses.create!(
code: 'S82.3',
description: 'Fracture of lower end of tibia'
)
a.symptoms.create!(
description: 'Swelling'
)
a.observations.create!(
description: 'Patient alert and oriented x3 but in significant pain at admission'
)
# ***************************
# misc
#
(1..24).each do |h|
OrderFrequency.create!(
value: h,
unit: 'hour'
)
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment