class Quby::Answers::Entities::Patient

Attributes

birthyear[RW]
gender[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/quby/answers/entities/patient.rb, line 11
def initialize(attributes = {})
  attributes = attributes.with_indifferent_access
  @gender    = attributes[:gender] || :unknown
  @birthyear = attributes[:birthyear]
end

Public Instance Methods

age_at(timestamp) click to toggle source

returns the age at the given timestamp, as an integer NB: if you make this a float, this breaks various questionnaire score calculations that do the following: `if (8..12).cover?(age) … elsif (13..15).cover?(age)` etc.

# File lib/quby/answers/entities/patient.rb, line 20
def age_at(timestamp)
  return nil unless @birthyear and timestamp
  ((timestamp - Time.gm(@birthyear, 1, 1)) / 1.year).floor
end