Class: Renalware::Patients::CalculateAge
- Inherits:
-
Object
- Object
- Renalware::Patients::CalculateAge
- Defined in:
- app/models/renalware/patients/calculate_age.rb
Overview
Calculates a patients age. Takes into account:
-
if they have a died_on date, in which case their age never changes
-
which side of ‘today’ their birthday (e.g. May 11) falls, to make sure their age is for example only 99 and not 100 when their birthday is 100 years ago tomorrow, and 100 when its is 100 years ago today or yesterday.
Example usage:
CalculateAge.for(patient) #=> 99
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.for(patient) ⇒ Object
22 23 24 |
# File 'app/models/renalware/patients/calculate_age.rb', line 22 def self.for(patient) new(patient).call end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/models/renalware/patients/calculate_age.rb', line 26 def call return if born_on.blank? age = relative_date.year - born_on.year age -= 1 if relative_date < (born_on + age.years) # for days before birthday age end |