Class: Quby::Answers::Entities::Patient

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/answers/entities/patient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Patient

Returns a new instance of Patient.



11
12
13
14
15
16
# File 'lib/quby/answers/entities/patient.rb', line 11

def initialize(attributes = {})
  attributes = attributes.with_indifferent_access
  @gender    = attributes[:gender] || :unknown
  @birthyear = attributes[:birthyear]
  @birthdate = attributes[:birthdate]
end

Instance Attribute Details

#birthyearObject

Returns the value of attribute birthyear.



9
10
11
# File 'lib/quby/answers/entities/patient.rb', line 9

def birthyear
  @birthyear
end

#genderObject

Returns the value of attribute gender.



9
10
11
# File 'lib/quby/answers/entities/patient.rb', line 9

def gender
  @gender
end

Instance Method Details

#age_at(observation_time) ⇒ Object

returns the age at the given observation_time, 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.



21
22
23
24
# File 'lib/quby/answers/entities/patient.rb', line 21

def age_at(observation_time)
  return nil unless birthdate && observation_time
  ((observation_time - birthdate) / 1.year).floor
end

#birthdateObject



26
27
28
# File 'lib/quby/answers/entities/patient.rb', line 26

def birthdate
  @birthdate&.in_time_zone || (@birthyear && Time.gm(@birthyear, 1, 1))
end