Permalink
Browse files

Search by age too!

  • Loading branch information...
brentvatne committed Jan 27, 2013
1 parent 15b6599 commit bb7f993b37c8387e6c098acd2a0d2f688c5cf1a6
Showing with 15 additions and 0 deletions.
  1. +5 −0 app/models/patient_search.rb
  2. +10 −0 test/unit/patient_search_test.rb
@@ -3,6 +3,7 @@ class PatientSearch
attribute :chart_number, Integer
attribute :treatment_area_id, Integer
+ attribute :age, Integer
attribute :name, String
attribute :commit, String
@@ -27,6 +28,10 @@ def execute
)
end
+ if age.present?
+ patients = patients.where("date_part('year', age(date_of_birth)) = ?", age)
+ end
+
patients.order('id')
end
@@ -40,6 +40,16 @@ class PatientSearchTest < ActiveSupport::TestCase
end
test 'search by age' do
+ # We probably want to have options like greater than, less than, equal to,
+ # but leaving this out for now.
+ @jordan_byron.update_attributes(date_of_birth: Date.today - 65.years)
+ @michael_jordan.update_attributes(date_of_birth: Date.today - 23.years)
+
+ @patient_search.age = 65
+ assert_equal [@jordan_byron], @patient_search.execute
+
+ @patient_search.age = 23
+ assert_equal [@michael_jordan], @patient_search.execute
end
test 'search by procedure' do

0 comments on commit bb7f993

Please sign in to comment.