Sha256: d45d56a2fcc9a6de213c807d949f5704ced04d51ec4601d49945e783813a98c4

Contents?: true

Size: 997 Bytes

Versions: 5

Compression:

Stored size: 997 Bytes

Contents

# frozen_string_literal: true

require 'active_support/all'

module Quby
  module Answers
    module Entities
      class Patient
        attr_accessor :gender, :birthyear

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

        # 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.
        def age_at(observation_time)
          return nil unless birthdate && observation_time
          ((observation_time - birthdate) / 1.year).floor
        end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
quby-5.6.5 lib/quby/answers/entities/patient.rb
quby-5.6.3 lib/quby/answers/entities/patient.rb
quby-5.6.2 lib/quby/answers/entities/patient.rb
quby-5.6.1 lib/quby/answers/entities/patient.rb
quby-5.6.0 lib/quby/answers/entities/patient.rb