Permalink
Browse files

Added some time zone stuff. Not tested.

  • Loading branch information...
1 parent a8bfddc commit 76df2a75469122b8f96ef8622e94aacc95a9b5e7 @MikeBlyth committed Jan 18, 2013
@@ -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
@@ -0,0 +1,4 @@
+class UsersController < ApplicationController
+ active_scaffold :user do |conf|
+ end
+end
View
@@ -33,6 +33,9 @@
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,
:allergies, :hemoglobin_type, :hiv_status, :maternal_hiv_status
@@ -54,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
@@ -205,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
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
@@ -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']]
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]
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
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

0 comments on commit 76df2a7

Please sign in to comment.