Permalink
Browse files

Working on forms. Still plenty of errors -- not tested.

  • Loading branch information...
1 parent 2e84992 commit 91397e362b53f98047cb81fb8aa85a0ccbb0ce57 @MikeBlyth committed Jan 22, 2013
@@ -6,7 +6,7 @@ class PatientsController < ApplicationController
active_scaffold :patient do |config|
config.columns.exclude :created_at, :updated_at
- config.list.columns = :ident, :last_name, :first_name, :other_names, :birth_date, :sex,
+ config.list.columns = :ident, :last_name, :first_name, :middle_name, :birth_date, :sex,
:lab_results, :visits, :admissions, :prescriptions
config.show.link.inline = false
config.show.link.page = true
@@ -1,4 +1,43 @@
class ProvidersController < ApplicationController
- active_scaffold :provider do |conf|
+ active_scaffold :provider do |config|
+ config.list.columns = :last_name, :first_name, :middle_name, :ident, :title, :degree, :position
+ 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
+ %w(title degree position).each {|col| config.columns[col].inplace_edit = true}
end
+
+ def new
+ @provider = Provider.new #ToDO Error checking!
+ end
+
+ def create
+ @provider = Provider.new(params[:provider])
+ # binding.pry
+ if @provider.save
+ flash[:notice] = "Created new provider #{@provider}"
+ @record = @provider # ToDo -- only while AS is handling :show
+ render :show
+ else
+ params=nil
+ render :new
+ end
+ end
+
+ def edit
+ @provider = Provider.find params[:id]
+ end
+
+ def update
+ @provider = Provider.find params[:id]
+ if @provider.update_attributes(params[:provider])
+ flash[:notice] = 'Provider updated'
+ redirect_to provider_path(@provider.id)
+ else
+ render :update
+ end
+ end
+
end
@@ -1,10 +1,18 @@
module NamesHelper
def name
- initial = other_names.blank? ? '' : " #{other_names[0]}."
+ initial = middle_name.blank? ? '' : " #{middle_name[0]}."
return (first_name || '') + initial + ' ' + (last_name || '')
end
+ def with_title(a_name)
+ (self.respond_to? :title) && self.title.present? ? "#{title} #{a_name}" : a_name
+ end
+
+ def with_degree(a_name)
+ (self.respond_to? :degree) && self.degree.present? ? "#{a_name}, #{degree}" : a_name
+ end
+
def name_last_first
"#{last_name}, #{first_name}"
end
@@ -13,7 +13,7 @@
class LabRequest < ActiveRecord::Base
- attr_accessible :date, :hct, :patient_id, :provider_id, :patient, :provider, :lab_results_attributes
+ attr_accessible :date, :hct, :patient_id, :provider_id, :patient, :provider, :lab_results_attributes, :comments
belongs_to :patient
belongs_to :provider
has_many :lab_results, :dependent => :delete_all
View
@@ -5,7 +5,7 @@
# id :integer not null, primary key
# first_name :string(255)
# last_name :string(255)
-# other_names :string(255)
+# middle_name :string(255)
# birth_date :datetime
# death_date :date
# birth_date_exact :boolean
@@ -34,7 +34,7 @@ class Patient < ActiveRecord::Base
include DateValidators
include NamesHelper
- attr_accessible :first_name, :ident, :last_name, :other_names, :sex, :residence, :phone, :caregiver, :birth_date,
+ attr_accessible :first_name, :ident, :last_name, :middle_name, :sex, :residence, :phone, :caregiver, :birth_date,
:death_date, :birth_date_text, :birth_date_exact,:death_date,
:allergies, :hemoglobin_type, :hiv_status, :maternal_hiv_status
@@ -191,7 +191,7 @@ def alive
# Has HIV concern if own status is positive OR (mother's status is positive and own is not Negative)
def hiv?
return hiv_status == 'positive' ||
- (hiv_pos_mother && hiv_status != 'negative')
+ (age_years < 18.months && hiv_pos_mother && hiv_status != 'negative')
end
def hiv_pos
View
@@ -5,15 +5,18 @@
# id :integer not null, primary key
# last_name :string(255)
# first_name :string(255)
-# other_names :string(255)
+# middle_name :string(255)
+# title :string(255)
+# degree :string(255)
+# position :string(255)
# ident :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class Provider < ActiveRecord::Base
include NamesHelper
- attr_accessible :first_name, :ident, :last_name, :other_names
+ attr_accessible :first_name, :ident, :last_name, :middle_name, :title, :degree, :position
validates_presence_of :first_name, :last_name
has_many :visits
@@ -0,0 +1,15 @@
+= simple_form_for @provider do |form|
+ .controls-row
+ .span2= form.input :title, :input_html=>{:class=>'input-mini'}
+ .span3= form.input :last_name, :input_html=>{:class=>'input-medium'}
+ .span3= form.input :first_name, :input_html=>{:class=>'input-medium'}
+ .span3= form.input :middle_name, :input_html=>{:class=>'input-medium'}
+
+ .controls-row
+ .span2= form.input :degree, :input_html=>{:class=>'input-mini'}
+ .span3= form.input :position, :input_html=>{:class=>'input-medium'}
+ .span3= form.input :ident, :input_html=>{:class=>'input-medium'}, :label=>'Provider ID'
+
+ = form.error :base
+ = form.submit
+ = link_to "Cancel", request.referer
@@ -0,0 +1,2 @@
+%h2 Edit Provider
+= render :partial => 'form'
@@ -0,0 +1,2 @@
+%h2 Create New Provider
+= render :partial => 'form'
@@ -0,0 +1,2 @@
+- @provider ||= @record
+= render partial: 'shared/provider', object: @provider
@@ -6,5 +6,5 @@
.span3
= form.input :date, as: :string
.span3
- = form.input :provider
+ = @record.provider
%hr
@@ -0,0 +1,7 @@
+%h3= provider.with_degree(provider.name)
+- if provider.position
+ %br
+ = provider.position
+- if provider.ident
+ %br
+ = provider.ident
@@ -16,10 +16,11 @@
%p.span6#labs
Labs at this visit:
= visit_labs(@visit)
-.row-fluid
- %p.span6#hiv
- HIV status:
- = hiv_status_summary(@visit)
+-if @visit.patient.hiv?
+ .row-fluid
+ %p.span6#hiv
+ HIV status:
+ = hiv_status_summary(@visit)
.row-fluid
%p.span6#drugs
Drugs prescribed:
@@ -3,7 +3,7 @@ def change
create_table :patients do |t|
t.string :first_name
t.string :last_name
- t.string :other_names
+ t.string :middle_name
t.date :birth_date
t.date :death_date
t.boolean :birth_date_exact
@@ -3,7 +3,7 @@ def change
create_table :providers do |t|
t.string :last_name
t.string :first_name
- t.string :other_names
+ t.string :middle_name
t.string :ident
t.timestamps
@@ -0,0 +1,9 @@
+class AddLevelsToProvider < ActiveRecord::Migration
+ def change
+ add_column :providers, :title, :string
+ add_column :providers, :position, :string
+ add_column :providers, :degree, :string
+ rename_column :providers, :middle_name, :middle_name
+ rename_column :patients, :middle_name, :middle_name
+ end
+end
View
@@ -505,7 +505,7 @@ CREATE TABLE patients (
id integer NOT NULL,
first_name character varying(255),
last_name character varying(255),
- other_names character varying(255),
+ middle_name character varying(255),
birth_date timestamp without time zone,
death_date date,
birth_date_exact boolean,
@@ -772,10 +772,13 @@ CREATE TABLE providers (
id integer NOT NULL,
last_name character varying(255),
first_name character varying(255),
- other_names character varying(255),
+ middle_name character varying(255),
ident 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,
+ title character varying(255),
+ "position" character varying(255),
+ degree character varying(255)
);
@@ -1465,4 +1468,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130120135959');
INSERT INTO schema_migrations (version) VALUES ('20130120192230');
-INSERT INTO schema_migrations (version) VALUES ('20130122130641');
+INSERT INTO schema_migrations (version) VALUES ('20130122130641');
+
+INSERT INTO schema_migrations (version) VALUES ('20130122200043');
@@ -191,7 +191,7 @@
factory :provider, aliases: [:prescriber] do
last_name 'Hertz'
first_name 'Joshua'
- other_names 'Kernigan'
+ middle_name 'Kernigan'
sequence(:ident) {|n| "Prov #{n}" }
end
@@ -8,7 +8,7 @@ class LatestParametersFactory < LatestParameters
def initialize(options={})
self[:patient] = options[:patient] || Patient.new(
- {id: 88, first_name: "Mohammed", last_name: "Audu", other_names: nil,
+ {id: 88, first_name: "Mohammed", last_name: "Audu", middle_name: nil,
birth_date: "2003-09-15", death_date: nil, birth_date_exact: nil,
ident: "P002", sex: "M"}
)
@@ -5,7 +5,7 @@
# id :integer not null, primary key
# first_name :string(255)
# last_name :string(255)
-# other_names :string(255)
+# middle_name :string(255)
# birth_date :datetime
# death_date :date
# birth_date_exact :boolean
@@ -58,7 +58,7 @@
end
it 'uses first and last name with middle initial' do
- patient.other_names = 'Artexerxes'
+ patient.middle_name = 'Artexerxes'
patient.name.should eq 'Bernard A. Jones'
end
@@ -5,7 +5,7 @@
# id :integer not null, primary key
# last_name :string(255)
# first_name :string(255)
-# other_names :string(255)
+# middle_name :string(255)
# ident :string(255)
# created_at :datetime not null
# updated_at :datetime not null

0 comments on commit 91397e3

Please sign in to comment.