Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: MikeBlyth/ptbase
...
head fork: MikeBlyth/ptbase
  • 2 commits
  • 15 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 17, 2013
Mike Blyth in progress a8bfddc
Commits on Jan 18, 2013
Mike Blyth Added some time zone stuff. Not tested. 76df2a7
2  app/assets/javascripts/application.js
View
@@ -21,4 +21,4 @@
// require rickshaw
// NEXT LINE IS FOR HIGHCHARTS GRAPHING
//= require highcharts
-// require_tree .
+//= require_tree .
0  app/assets/javascripts/growth_chart_morris.js.coffee → ...avascripts/growth_chart_morris.js.coffee.not_used
View
File renamed without changes
7 app/assets/javascripts/ptbase.js
View
@@ -0,0 +1,7 @@
+// ****************** DATEPICKER **************************************
+$(function() {
+ $(".datepicker").live("click", function(){
+ $(this).datepicker();
+ });
+});
+
6 app/controllers/application_controller.rb
View
@@ -1,5 +1,8 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ around_filter :user_time_zone, if: :current_user
+
# Add this when we figure out how to exempt the session#new and session#create actions
# before_filter :authenticate_user!,
@@ -9,5 +12,8 @@ class ApplicationController < ActionController::Base
# config.theme = :gold
end
+ def user_time_zone(&block)
+ Time.use_zone(current_user.time_zone, &block)
+ end
end
2  app/controllers/patients_controller.rb
View
@@ -1,4 +1,4 @@
-require 'std_to_activescaffold_adapter'
+#require 'std_to_activescaffold_adapter'
require 'growth_chart'
class PatientsController < ApplicationController
4 app/controllers/users_controller.rb
View
@@ -0,0 +1,4 @@
+class UsersController < ApplicationController
+ active_scaffold :user do |conf|
+ end
+end
3  app/helpers/patients_helper.rb
View
@@ -4,4 +4,7 @@ def birth_date_column(record, column)
record.birth_date.to_s(:default)
end
+ def birth_date2(record)
+ record.birth_date.to_date
+ end
end
29 app/models/patient.rb
View
@@ -33,8 +33,12 @@
class Patient < ActiveRecord::Base
include DateValidators
include NamesHelper
+
+ attr_accessor :birth_date, :birth_time
+
attr_accessible :first_name, :ident, :last_name, :other_names, :residence, :phone, :caregiver, :birth_date,
- :death_date, :birth_date_exact
+ :death_date, :birth_date_exact,
+ :allergies, :hemoglobin_type, :hiv_status, :maternal_hiv_status
has_many :visits
has_many :lab_requests
@@ -53,6 +57,9 @@ class Patient < ActiveRecord::Base
validates_presence_of :last_name, :ident, :birth_date
validates_uniqueness_of :ident
validate :valid_birth_date
+ after_find :parse_birth_date_time
+ before_save :combine_birth_date_time
+
############ NAME METHODS
def to_s
@@ -204,5 +211,25 @@ def recent_drugs(since=3)
RxDrugList.new.add_prescriptions(recent_prescriptions)
end
+ def parse_birth_date_time
+ @birth_date = birth_datetime.to_date
+ @birth_time = birth_datetime.strftime("%H:%M")
+ end
+
+ def combine_birth_date_time
+ if time_valid? @birth_time
+ self.birth_datetime = DateTime.parse(@birth_date.strftime("%d %B %Y ") + @birth_time)
+ else
+ self.birth_datetime = @birth_date
+ end
+ end
+ def time_valid?(str)
+ return false unless str =~ /\A\s*([0-9]{1,2}):([0-9]{2,2})(\s+|\Z)(am|pm)?/i
+ hour, minute, am_pm = $1, $2, $4
+ hour = hour.to_i
+ minute = minute.to_i
+ return false unless (0..59).include? minute
+ return am_pm ? (1..12).include?(hour) : (0..23).include?(hour)
+ end
end
3  app/models/user.rb
View
@@ -28,7 +28,8 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :full_name, :name
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :full_name, :name,
+ :time_zone
# attr_accessible :title, :body
validates_presence_of :username
end
68 app/views/patients/_form.html.haml
View
@@ -2,32 +2,48 @@
-#= "Record = #{@record.attributes}"
= simple_fields_for(@patient, :html => {:class => 'form-horizontal' }) do |form|
= form.error_notification
- .row-fluid
- .span2
- = form.input :last_name, :input_html => {class: :span12 }
- .span2
- = form.input :first_name, :input_html => {class: :span12 }
- .span2
- = form.input :other_names, :input_html => {class: :span12 }
- .span2
- = form.input :sex, as: :radio_buttons, collection: [['Male', 'M'],['Female', 'F']], label_html: {class: :inline}
- .row-fluid
- .span2
- = form.input :ident, :input_html => {class: :span12 }
- .row-fluid
- .span2
- = form.input :birth_date, as: :string, :input_html => {class: :span12 }
- .span2
- = form.input :birth_date_exact, label: "Exact birth date?"
- .span2
- = form.input :death_date, as: :string, :input_html => {class: :span12 }
- .row-fluid
- .span4
- = form.input :residence, as: :string , :input_html => {class: :span12 }
- .span2
- = form.input :phone, as: :tel, :input_html => {class: :span12 }
- .span2
- = form.input :caregiver, :input_html => {class: :span12 }
+ %fieldset
+ %legend Basic information
+ .row-fluid
+ .span2
+ = form.input :last_name, :input_html => {class: :span12 }
+ .span2
+ = form.input :first_name, :input_html => {class: :span12 }
+ .span2
+ = form.input :other_names, :input_html => {class: :span12 }
+ .span2
+ = form.input :sex, as: :radio_buttons, collection: [['Male', 'M'],['Female', 'F']], label_html: {class: :inline}
+ .row-fluid
+ .span2
+ = form.input :ident, :input_html => {class: :span12 }
+ .row-fluid
+ .span2
+ = form.input :birth_date2, as: :string, :input_html => {class: "span12 datepicker" }
+ .span2
+ = form.input :birth_date_exact, label: "Exact birth date?"
+ .span2
+ = form.input :death_date, as: :string, :input_html => {class: "span12 datepicker" }
+ .row-fluid
+ .span4
+ = form.input :residence, as: :string , :input_html => {class: :span12 }
+ .span2
+ = form.input :phone, as: :tel, :input_html => {class: :span12 }
+ .span2
+ = form.input :caregiver, :input_html => {class: :span12 }
+ %fieldset
+ %legend Health Information
+ .row-fluid
+ .span2
+ = form.input :allergies, :input_html => {class: :span12 }
+ .span2
+ = form.input :hemoglobin_type, :input_html => {class: :span10 }
+ #hiv_info
+ .span2
+ = form.input :hiv_status, :input_html => {class: :span10 },
+ :collection => ['pos', 'neg', '?']
+ .span2
+ = form.input :maternal_hiv_status, :input_html => {class: :span10 },
+ :collection => ['pos', 'neg', '?']
= form.error :base
5 app/views/users/_form.html.haml
View
@@ -0,0 +1,5 @@
+= simple_fields_for @record do |f|
+ = f.input :username
+ = f.input :full_name
+ = f.input :email
+ = f.input :time_zone, priority: [ActiveSupport::TimeZone['West Central Africa']]
2  config/application.rb
View
@@ -33,7 +33,7 @@ class Application < Rails::Application
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
+ config.time_zone = 'West Central Africa'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
2  config/routes.rb
View
@@ -19,6 +19,8 @@
resources :providers do as_routes end
+ resources :users do as_routes end
+
resources :photos do as_routes end
resources :labs do as_routes end
5 db/schema.rb
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130117141312) do
+ActiveRecord::Schema.define(:version => 20130118073230) do
create_table "admissions", :force => true do |t|
t.integer "patient_id"
@@ -196,7 +196,7 @@
t.string "first_name"
t.string "last_name"
t.string "other_names"
- t.datetime "birth_date"
+ t.datetime "birth_datetime"
t.date "death_date"
t.boolean "birth_date_exact"
t.string "ident"
@@ -297,6 +297,7 @@
t.string "username"
t.string "name"
t.string "full_name"
+ t.string "time_zone"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
21 spec/controllers/patients_controller_spec.rb
View
@@ -31,4 +31,25 @@
end
end
+ describe 'updates patient' do
+ let(:patient) { FactoryGirl.create(:patient, birth_date: DateTime.new(2010,6,15,16,30,0))}
+ before(:each) do
+ controller_sign_in
+ end
+
+ it 'updates a new patient' do
+ patient.allergies = 'none'
+ put :update, {:patient => {allergies: 'none'}, id: patient.id}
+ response.status.should == 302 # Redirects to show page for the patient
+ patient.reload.allergies.should eq 'none'
+ end
+
+ #it 'splits date and time for form' do
+ # get :edit, { id: patient.id}
+ # birth_date = (assigns(:patient) || assigns(:record))[:birth_date]
+ # puts birth_date
+ # birth_date.class.should eq Date
+ #end
+ end
+
end

No commit comments for this range

Something went wrong with that request. Please try again.