Sha256: 62f83e3f4a74d178e4bc0559871bae3382b87bf8861568a6f9854796f672f0b9

Contents?: true

Size: 838 Bytes

Versions: 4

Compression:

Stored size: 838 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]
        end

        # returns the age at the given completed_at, 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(completed_at)
          return nil unless @birthyear and completed_at
          ((completed_at - Time.gm(@birthyear, 1, 1)) / 1.year).floor
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
quby-5.4.0 lib/quby/answers/entities/patient.rb
quby-5.3.1 lib/quby/answers/entities/patient.rb
quby-5.3.0 lib/quby/answers/entities/patient.rb
quby-5.2.0 lib/quby/answers/entities/patient.rb