Permalink
Browse files

in progress

  • Loading branch information...
1 parent 5f874ac commit 05cca475f81fd9fa4e95824261dd7ebc44abedbe @MikeBlyth committed Jan 18, 2013
View
0 ...ts/growth_chart_morris.js.coffee.not_used → app/archived/growth_chart_morris.js.coffee
File renamed without changes.
View
4 app/controllers/patients_controller.rb
@@ -25,6 +25,7 @@ def do_show
def create
@record = patient = Patient.new(params[:patient])
+ # binding.pry
if patient.save
flash[:notice] = "Created new patient #{patient}"
render :show
@@ -39,7 +40,8 @@ def update
flash[:notice] = 'Patient updated'
redirect_to patient_path(patient.id)
else
- render :edit
+
+ render :update
end
end
View
32 app/models/patient.rb
@@ -35,9 +35,11 @@ class Patient < ActiveRecord::Base
include NamesHelper
attr_accessible :first_name, :ident, :last_name, :other_names, :sex, :residence, :phone, :caregiver, :birth_date,
- :death_date, :birth_date, :birth_date_exact,:death_date,
+ :death_date, :birth_date_text, :birth_date_exact,:death_date,
:allergies, :hemoglobin_type, :hiv_status, :maternal_hiv_status
+ attr_writer :birth_date_text
+
has_many :visits
has_many :lab_requests
has_many :lab_results, through: :lab_requests
@@ -51,9 +53,11 @@ class Patient < ActiveRecord::Base
validates_presence_of :last_name, :ident, :birth_date
validates_uniqueness_of :ident
+ before_validation :save_birth_date_text
validate :valid_birth_date
+
############ NAME METHODS
def to_s
name_id
@@ -167,6 +171,15 @@ def next_appt
############### OTHER METHODS
+ def birth_date_text
+ @birth_date_text || birth_date.to_s(:day_mon_year)
+ end
+
+ def save_birth_date_text
+ self.birth_date = validate_birth_date_text unless @birth_date_text.blank?
+ #binding.pry
+ end
+
def date
birth_date
end
@@ -204,6 +217,23 @@ def recent_drugs(since=3)
RxDrugList.new.add_prescriptions(recent_prescriptions)
end
+ def validate_birth_date_text
+ if @birth_date_text.blank?
+ errors.add :birth_date_text, "cannot be blank"
+ return nil
+ end
+ parsed = Time.zone.parse(@birth_date_text)
+ if parsed
+ return parsed
+ else
+ errors.add :birth_date_text, "cannot be parsed"
+ return nil
+ end
+ rescue ArgumentError
+ errors.add :birth_date_text, "is out of range"
+ return nil
+ 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
View
2 app/views/patients/_form.html.haml
@@ -18,7 +18,7 @@
= form.input :ident, :input_html => {class: :span12 }
.row-fluid
.span2
- = form.input :birth_date, as: :string, :input_html => {class: "span12 datepicker" }
+ = form.input :birth_date_text, as: :string, :input_html => {class: "span12" }
.span2
= form.input :birth_date_exact, label: "Exact birth date?"
.span2
View
1 config/initializers/date_formats.rb
@@ -13,6 +13,7 @@
# TIME::DATE_FORMATS for formatting .to_s.
Time::DATE_FORMATS[:date_long] = "%-1e %B %Y"
+Time::DATE_FORMATS[:day_mon_year] = "%-1e %b %Y"
Time::DATE_FORMATS[:us_date_long] = "%B %-1e, %Y"
Time::DATE_FORMATS[:date] = "%-1e %B"
Time::DATE_FORMATS[:us_date] = "%B %-1e"

0 comments on commit 05cca47

Please sign in to comment.