Commit 9a9ec322 authored by Greg Gard's avatar Greg Gard

adding transfer form style and some data points

parent f440f80d
class TransfersController < ApplicationController
def dashboard
end
#
def index
@transfers = Transfer.kept.order(created_at: 'desc').page params[:page]
end
#
def new
......@@ -33,6 +38,13 @@ class TransfersController < ApplicationController
redirect_to transfers_path, notice: "That view isn't implemented."
end
# render the transfer html
def form
set_resource
render html: @transfer.build_form(Admission.last)
end
#
def edit
......
......@@ -37,4 +37,12 @@ module EMT
[UserError, ::ActiveRecord::RecordInvalid]
end
# https://stackoverflow.com/questions/819263/get-persons-age-in-ruby
# - modified to return nil if negative
def self.age(dob, as_of = Time.now)
now = as_of.utc.to_date
return nil if dob > now
now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
end
end
......@@ -34,6 +34,22 @@ class Admission < ApplicationRecord
has_many :symptoms
has_many :observations
# ****************************
# clinical
#
def admitting_diagnoses
diagnoses.map{|d| [d.code, d.description].reject(&:blank?)}.
reject(&:blank?).flatten.join(', ').presence || nil
end
def admitting_symptoms
symptoms.map{|s| s.description}.reject(&:blank?).join(', ').presence || nil
end
# *****************************
# utils
#
def fmt_patient_name
patient&.name || EMT::UKNOWN
end
......@@ -43,8 +59,8 @@ class Admission < ApplicationRecord
end
#
def fmt_moment(default = created_at)
(moment || created_at).fmt(:mdy12)
def fmt_moment(fmt = :mdy12)
(moment || created_at).fmt(fmt)
end
def ajax_attributes
......
......@@ -36,6 +36,10 @@ class Patient < ApplicationRecord
# instance methods
#
has_many :admissions
has_many :diagnoses, :through => :admissions
has_many :symptoms, :through => :admissions
has_many :observations, :through => :admissions
has_many :transfers
has_many :allergies
has_many :medication_orders
......@@ -67,7 +71,19 @@ class Patient < ApplicationRecord
def fmt_dob
dob&.to_formatted_s(:dob)
end
# return nil instead of negative
def age
dob && EMT::age(dob)
end
# ******************************
# clinical
#
# *************************
# utils
#
# would turn off ssn, user_id, password etc
def ajax_attributes
attributes
......
......@@ -2,6 +2,8 @@ class Transfer < ApplicationRecord
include Discard::Model
serialize :data # would use jsonb in pg
def self.params_whitelist
[:patient_id, :facility_id, :form_sent_at, :notes]
end
......@@ -57,7 +59,21 @@ class Transfer < ApplicationRecord
def set_defaults
self.form_sent_at ||= Time.now
end
# ********************************
# transfer form data
#
def get_data(k)
(self.data ||= {})[k.to_s.downcase]
end
def set_data(k, v)
(self.data ||= {})[k.to_s.downcase] = v
end
def build_form(_admission)
TransfersPresenter.new.transfer_template(_admission)
end
end
\ No newline at end of file
......@@ -9,67 +9,99 @@
# - inspired by React components.
#
module TransfersComponent
def transfer_template(facility:, patient:, **opts)
DEFAULTS = {
title: "Emergency Transfer Summary (Form 34L-D)",
link_label: 'Foo',
link_url: 'http://gardwired.com'
}.freeze
BLANK = "&nbsp;".html_safe
NO_DX = "-- diagnoses not reported"
NO_SX = "-- symtptoms not reported"
def transfer_template(admission, **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
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].
]
opts = DEFAULTS.merge(opts)
patient = admission.patient
facility = admission.facility
tag.div(class: 'form-34ld') do
tag.style %Q[
.form-34ld table {width: 100%; border: solid 1px #000; border-collapse: collapse;}
.form-34ld table tr, .form-34ld td {border: solid 1px #000; width: 20%; vertical-align: top;}
]
tag.table do
tag.tr do
tag.td opts[:title], colspan: 5
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].
]
tag.tr do
tag.td "Transferring Facility", colspan: 5
end
tag.tr do
tag.td do
tag.div "Name"
tag.div facility.name
end
tag.td BLANK, colspan: 4
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]
]
tag.tr do
tag.td "Patient Information", colspan: 5
end
end
end # tag wrapper
tag.tr do
tag.td do
tag.div "First Name"
tag.div patient.first_name
end
tag.td do
tag.div "Middle Name"
tag.div patient.middle_name.presence || BLANK
end
tag.td do
tag.div "Last Name"
tag.div patient.last_name
end
tag.td do
tag.div "Medical Record (MR)"
tag.div patient.mr
end
tag.td BLANK
end
tag.tr do
tag.td colspan: 5 do
tag.div "Summary"
tag.p do
tag._text %Q[This #{patient.age} years old #{patient.gender} was admitted to #{facility.name}
on #{admission.fmt_moment(:mdy)} at #{admission.fmt_moment(:hm12)}
due to #{admission.admitting_diagnoses || NO_DX}.
The observed symptoms on admission were #{admission.admitting_symptoms || NO_SX}.
[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 # td
end # tr
end # table
end # wrapper div
end
end
\ No newline at end of file
......@@ -2,26 +2,5 @@
class TransfersPresenter < ApplicationPresenter
include TransfersComponent
DEFAULTS = {
title: "Emergency Transfer Summary (Form 34L-D)",
link_label: 'Foo',
link_url: 'http://gardwired.com'
}.freeze
def transfers
transfer_template DEFAULTS
end
def edit_transfer
end
def update_transfer
end
def delete_transfer
end
end
\ No newline at end of file
......@@ -9,6 +9,7 @@
<th>Patient Name</th>
<th>Referring Facility</th>
<th>Notes</th>
<th>Actions</th>
</tr>
<% @transfers.each_with_index do |f, idx| %>
......@@ -18,6 +19,7 @@
<td><%= f.fmt_patient_name %></td>
<td><%= f.fmt_facility_name %></td>
<td><%= f.notes %></td>
<td><%= link_to "View Form", form_transfer_path(f), class: 'emt-btn emt-brand' %></td>
</tr>
<% end %>
......
......@@ -9,7 +9,8 @@ module EMT
COMMON_TIME_FORMATS = {
mdy: '%-m/%-d/%Y',
mdy12: '%-m/%-d/%Y %l:%M %p',
dob: '%-m/%-d/%Y'
dob: '%-m/%-d/%Y',
hm12: '%l:%M %p'
}
TIME_FORMATS = {
......
......@@ -28,6 +28,7 @@ Rails.application.routes.draw do
resources :transfers do
get 'dashboard', on: :collection
get 'form', on: :member
resources :patients
resources :admissions
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