Permalink
Browse files

in progress

  • Loading branch information...
MikeBlyth committed Jan 24, 2013
1 parent 91397e3 commit c8fb93b36f91a1d0bf499aa361a068bf4d0f9065
@@ -6,6 +6,11 @@ class AdmissionsController < ApplicationController
config.columns[:discharge_status].inplace_edit = true
config.columns[:discharge_status].options[:options] = Admission::DISCHARGE_STATUSES
config.columns[:discharge_status].form_ui = :select
+ as_no_inline = lambda do |action|
+ config.send(action).link.page = true
+ config.send(action).link.inline = false
+ end
+ %w(create update show).each &as_no_inline
end
def new
@@ -4,6 +4,40 @@ class LabRequestsController < ApplicationController
config.columns[:provider].inplace_edit = true
config.columns[:provider].form_ui = :select
config.columns[:comments].inplace_edit = true
+ as_no_inline = lambda do |action|
+ config.send(action).link.page = true
+ config.send(action).link.inline = false
+ end
+ %w(create update show).each &as_no_inline
+ end
+
+ def new
+ @lab_request = LabRequest.new(patient_id: params[:patient_id])
+ end
+
+ def edit
+ @lab_request = LabRequest.find params[:id]
+ @patient = Patient.find @lab_request.patient_id
+ end
+
+ def create
+ # selected_services = params.delete(:services)
+ add_services
+ if @record = LabRequest.create(params[:lab_request])
+ flash[:notice] = 'Successfully created lab request'
+ else
+ render :new
+ end
+ end
+
+ def update
+ @lab_request = lab_request.find(params[:id])
+ if @lab_request.update_attributes(params[:lab_request])
+ flash[:notice] = 'Lab request was successfully updated.'
+ redirect_to :action => 'show', :id => @lab_request
+ else
+ render :action => 'edit'
+ end
end
def create
@@ -1,7 +1,7 @@
#require 'std_to_activescaffold_adapter'
class LabResultsController < ApplicationController
active_scaffold :lab_result do |config|
- config.columns = [:lab_service, :date, :status, :result, :abnormal, :panic, :comments]
+ config.columns = [:patient, :lab_service, :date, :status, :result, :abnormal, :panic, :comments]
config.columns[:lab_service].clear_link
list.sorting = {:date => 'DESC'}
config.columns[:date].inplace_edit = true
@@ -12,13 +12,48 @@ class LabResultsController < ApplicationController
config.columns[:abnormal].inplace_edit = true
config.columns[:panic].inplace_edit = true
config.columns[:comments].inplace_edit = true
- config.show.link = false
config.delete.link = false
- config.update.link = false
+ as_no_inline = lambda do |action|
+ config.send(action).link.page = true
+ config.send(action).link.inline = false
+ end
+ %w(create update ).each &as_no_inline
# config.update.link.page = true # Note that if the update form is used, it will not work properly with
# AS at this point.
end
+ def new
+ @lab_result = LabResult.new(lab_request_id: params[:lab_request_id], patient_id: params[:patient_id]) #ToDO Error checking!
+ end
+
+ def create
+ @lab_result = LabResult.new(params[:lab_result])
+ # binding.pry
+ if @lab_result.save
+ flash[:notice] = "Created new lab_result #{@lab_result}"
+ @record = @lab_result # ToDo -- only while AS is handling :show
+ render :show
+ else
+ params=nil
+ render :new
+ end
+ end
+
+ def edit
+ @lab_result = LabResult.find params[:id]
+ end
+
+ def update
+ @lab_result = LabResult.find params[:id]
+ if @lab_result.update_attributes(params[:lab_result])
+ flash[:notice] = 'LabResult updated'
+ redirect_to lab_result_path(@lab_result.id)
+ else
+ render :update
+ end
+ end
+
+
def delete_authorized?(record)
false
end
@@ -8,6 +8,9 @@ class PatientsController < ApplicationController
config.columns.exclude :created_at, :updated_at
config.list.columns = :ident, :last_name, :first_name, :middle_name, :birth_date, :sex,
:lab_results, :visits, :admissions, :prescriptions
+ config.columns[:lab_results].associated_limit = 0
+ config.columns[:visits].associated_limit = 1
+ config.columns[:prescriptions].associated_limit = 1
config.show.link.inline = false
config.show.link.page = true
config.update.link.inline = false
@@ -27,7 +27,9 @@ def concat_list(alist, delim=', ', end_delim='. ', str_if_empty='' )
end
def patient_name_link(patient)
- link_to "#{patient.name} [#{patient.ident}]", patient_path(patient)
+ if patient
+ link_to "#{patient.name} [#{patient.ident}]", patient_path(patient)
+ end
end
def twitter_box(id, name, label, checked)
@@ -51,43 +53,6 @@ def twitter_box(id, name, label, checked)
SSIZE = SUFFIX.size
end
-
- def show_pe_findings(model)
- columns = Visit.content_columns
- pe_columns = []
- # Get list of all the columns (variables) with form like 'pe_mouth', excluding the matching
- # items, 'pe_mouth_ok' etc. This gives a list of the elements in the physical exam
- for column in Visit.content_columns
- if (column.name.slice(0,VSIZE) == VARBASE) && (column.name.slice(-3,3) != SUFFIX)
- pe_columns << column.name.slice(VSIZE,column.name.size-VSIZE)
- end
- end
- # First, generate list of all the items which have some text.
- s = ''
- for column in pe_columns
- s << ' ' if s > ''
- finding = model.send(VARBASE+column)
- s << (column.capitalize) + ': ' + finding.to_s + '.' unless finding.blank?
- end
- s_findings = s
- s_normal = ''
- # Second, generate a list of items ticked as normal. This could be optional.
- normal_count = 0
- for column in pe_columns
- if (model.send(VARBASE+column+SUFFIX) || 0) == 1 # append the name if ticked
- s_normal << ', ' if s_normal > ''
- s_normal << column
- normal_count = normal_count + 1
- end
- end
- if s_normal > ''
- s_normal << ' all' if normal_count > 1 # just for style, to say 'mouth, eyes ... all normal'
- s_normal << ' normal.'
- end
-
- return s_findings + ' ' + s_normal.capitalize
- end
-
# ToDo - Needs work (and tests)
def show_val(value,
str_if_empty='____',
@@ -1,7 +1,7 @@
module LabRequestsHelper
- def available_labs
- current_results = @record.lab_results
+ def available_labs(lab_request)
+ current_results = lab_request.lab_results
selected = current_results.map {|r| r.lab_service_id}
frozen = current_results.select {|r| r.status != 'pending'}.map {|r| r.lab_service_id}
available = {}
@@ -18,7 +18,7 @@ class LabRequest < ActiveRecord::Base
belongs_to :provider
has_many :lab_results, :dependent => :delete_all
has_many :lab_services, :through => :lab_results
- validates_presence_of :provider_id, :patient_id
+ validates_presence_of :provider_id, :patient_id, :date
before_validation :default_date
accepts_nested_attributes_for :lab_results
View
@@ -16,11 +16,11 @@
#
class LabResult < ActiveRecord::Base
- attr_accessible :comments, :lab_request_id, :lab_request, :result, :date,
+ attr_accessible :comments, :lab_request_id, :lab_request, :result, :date,:patient_id,
:lab_service_id, :lab_service, :status, :abnormal, :panic, :comments
belongs_to :lab_request
belongs_to :lab_service
- has_one :patient, through: :lab_request
+ belongs_to :patient
before_validation :set_default_status
validates_presence_of :lab_service_id
after_find :numerify_result
View
@@ -42,7 +42,7 @@ class Patient < ActiveRecord::Base
has_many :visits
has_many :lab_requests
- has_many :lab_results, through: :lab_requests
+ has_many :lab_results
has_many :problems, dependent: :delete_all
has_many :admissions
has_one :immunization, dependent: :delete
View
@@ -19,6 +19,7 @@ class Provider < ActiveRecord::Base
attr_accessible :first_name, :ident, :last_name, :middle_name, :title, :degree, :position
validates_presence_of :first_name, :last_name
+ validates_uniqueness_of :ident
has_many :visits
has_many :admissions
has_many :immunizations
@@ -1,17 +1,19 @@
-= simple_form_for(@admission, :html => {:class => 'form-vertical' }) do |form|
- = form.input :patient_id
- #adm-data
- = form.input :date, as: :string
- = form.input :ward
- = form.input :bed
- = form.association :provider
- = form.input :weight_admission
- = form.input :diagnosis_1
- = form.input :diagnosis_2
- = form.input :meds
- = form.input :comments
- #disch-data
- = form.input :discharge_date, as: :string
- = form.input :weight_discharge
- = form.input :discharge_status, collection: Admission::DISCHARGE_STATUSES
- = form.button :submit
+- patient = @admission.patient
+= simple_form_for @admission, {url: {patient_id: patient.id} } do |form|
+ .row-fluid.controls-row
+ .span3= form.input :date, as: :string, label: 'Adm. date', :input_html => {:class=>'input-small'}
+ .span3= form.input :discharge_date, as: :string , :input_html => {:class=>'input-small'}
+ .span2= form.input :discharge_status, collection: Admission::DISCHARGE_STATUSES, :input_html => {:class=>'input-small'}
+ .span2= form.input :weight_admission, label: 'Adm. weight', :input_html=>{:class=>'input-mini'}
+ .span2= form.input :weight_discharge, label: 'Disch. Weight', :input_html=>{:class=>'input-mini'}
+ .row-fluid.controls-row
+ .span3= form.association :provider
+ .span3= form.input :ward, :input_html => {:class=>'input-small'}
+ .span2= form.input :bed, :input_html=>{:class=>'input-mini'}
+ .row-fluid.controls-row
+ .span3= form.input :diagnosis_1
+ .span3= form.input :diagnosis_2
+ .span4= form.input :meds, :input_html=>{:class=>'input-xlarge'}
+ .row-fluid.control-row
+ .span6= form.input :comments, input_html: {class: 'input-block-level'}
+ = form.button :submit, class: 'btn btn-primary'
@@ -0,0 +1,25 @@
+- @admission = @record
+%h2= "Admission for #{patient_name_link(@admission.patient)}".html_safe
+= "Admitted: #{@admission.date}"
+%br
+= "Provider: #{@admission.provider}"
+%br
+= "Ward: #{@admission.ward || '--'}, bed #{@admission.bed || '--'}"
+%br
+= "Diagnoses: #{[@admission.diagnosis_1, @admission.diagnosis_2].compact.join('; ')}"
+%br
+= "Medications: #{@admission.meds}"
+%br
+= "Comments: #{@admission.comments}"
+%br
+- if @admission.discharge_date
+ = "Discharge #{@admission.discharge_date}, status #{@admission.discharge_status || '--'}"
+- elsif @admission.discharge_status
+ = "Discharge status #{@admission.discharge_status}, but no discharge date on record."
+- else
+ = "Still on admission."
+
+
+ %br
+= "Weight on admission #{@admission.weight_admission} kg." if @admission.weight_admission
+= "Weight on discharge #{@admission.weight_discharge} kg." if @admission.weight_discharge
@@ -1,6 +1,10 @@
-= render 'shared/form_header'
-= simple_fields_for @record do |form|
- - available_labs.each do |group, services|
+- @lab_request ||= @record
+= simple_form_for @lab_request, {url: {patient_id: @lab_request.patient_id} } do |form|
+ .row-fluid.controls-row
+ .span3= form.association :patient
+ .span3= form.input :date, as: :string
+ .span3= form.association :provider
+ - available_labs(@lab_request).each do |group, services|
.span3
.lab_group= group
= render partial: 'lab_results/select', collection: services, as: :service
@@ -0,0 +1,2 @@
+%h2 Edit Lab Request
+= render :partial => 'form'
@@ -0,0 +1,2 @@
+%h2 Create Lab Request
+= render :partial => 'form'
@@ -1,10 +1,14 @@
-lab_results/form
-results = @record
-= simple_fields_for @record do |form|
- = patient_name_link(@record.patient)
- = form.input :date, as: :string
- = form.input :result
- = form.input :status
- = form.input :abnormal
- = form.input :panic
- = form.input :comments
+- @lab_result ||= @record
+= simple_fields_for @lab_result do |form|
+ .controls-row.controls
+ .span4= form.association :patient, input_html: {:class => 'input-large'}
+ .controls-row.controls
+ .span2= form.input :date, as: :string, input_html: {class: 'input-small'}
+ .span3= form.association :lab_service, input_html: {class: 'input-medium'}
+ .span3= form.input :result, input_html: {class: 'input-medium'}
+ .span3= form.input :status, input_html: {class: 'input-small'}
+ .controls-row.controls
+ .span1= form.input :abnormal, input_html: {class: 'input-mini'}
+ .span1= form.input :panic, input_html: {class: 'input-mini'}
+ .span5= form.input :comments , input_html: {:class => 'input-xlarge'}
+
@@ -0,0 +1,2 @@
+%h2 Edit Lab Result
+= render :partial => 'form'
@@ -0,0 +1,2 @@
+%h2 Create Lab Result
+= render :partial => 'form'
@@ -0,0 +1,5 @@
+class AddPatientIdToLabResult < ActiveRecord::Migration
+ def change
+ add_column :lab_results, :patient_id, :integer
+ end
+end
View
@@ -80,10 +80,10 @@
audu_lab_1.save
LabResult.delete_all
-LabResult.create(lab_request: audu_lab_1, lab_service: cd4, result: '1500')
-LabResult.create(lab_request: audu_lab_1, lab_service: hct, result: '35')
-LabResult.create(lab_request: audu_lab_2, lab_service: cd4, result: '450')
-LabResult.create(lab_request: audu_lab_2, lab_service: hct, result: '28')
+LabResult.create(patient: audu, lab_request: audu_lab_1, lab_service: cd4, result: '1500')
+LabResult.create(patient: audu, lab_request: audu_lab_1, lab_service: hct, result: '35')
+LabResult.create(patient: audu, lab_request: audu_lab_2, lab_service: cd4, result: '450')
+LabResult.create(patient: audu, lab_request: audu_lab_2, lab_service: hct, result: '28')
Photo.delete_all
Photo.create(patient: audu, date: audu.birth_date+5.months)
View
@@ -368,7 +368,8 @@ CREATE TABLE lab_results (
panic boolean,
comments character varying(255),
created_at timestamp without time zone NOT NULL,
- updated_at timestamp without time zone NOT NULL
+ updated_at timestamp without time zone NOT NULL,
+ patient_id integer
);
@@ -1470,4 +1471,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130120192230');
INSERT INTO schema_migrations (version) VALUES ('20130122130641');
-INSERT INTO schema_migrations (version) VALUES ('20130122200043');
+INSERT INTO schema_migrations (version) VALUES ('20130122200043');
+
+INSERT INTO schema_migrations (version) VALUES ('20130124133253');

0 comments on commit c8fb93b

Please sign in to comment.