Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Search by age too!

  • Loading branch information...
commit bb7f993b37c8387e6c098acd2a0d2f688c5cf1a6 1 parent 15b6599
@brentvatne brentvatne authored
Showing with 15 additions and 0 deletions.
  1. +5 −0 app/models/patient_search.rb
  2. +10 −0 test/unit/patient_search_test.rb
View
5 app/models/patient_search.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
View
10 test/unit/patient_search_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.