Sha256: f668dcd2df9d8164a45bd41096193fbfdbdbf86b508de885033ffaeb441fe8d6

Contents?: true

Size: 826 Bytes

Versions: 23

Compression:

Stored size: 826 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 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.
        def age_at(timestamp)
          return nil unless @birthyear and timestamp
          ((timestamp - Time.gm(@birthyear, 1, 1)) / 1.year).floor
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
quby-5.1.3 lib/quby/answers/entities/patient.rb
quby-5.1.2 lib/quby/answers/entities/patient.rb
quby-5.1.1 lib/quby/answers/entities/patient.rb
quby-5.1.0 lib/quby/answers/entities/patient.rb
quby-5.0.5 lib/quby/answers/entities/patient.rb
quby-5.0.4 lib/quby/answers/entities/patient.rb
quby-5.0.3 lib/quby/answers/entities/patient.rb
quby-5.0.2 lib/quby/answers/entities/patient.rb
quby-5.0.1 lib/quby/answers/entities/patient.rb
quby-5.0.0 lib/quby/answers/entities/patient.rb
quby-4.0.4 lib/quby/answers/entities/patient.rb
quby-5.0.0.pre4 lib/quby/answers/entities/patient.rb
quby-5.0.0.pre3 lib/quby/answers/entities/patient.rb
quby-5.0.0.pre2 lib/quby/answers/entities/patient.rb
quby-5.0.0.pre1 lib/quby/answers/entities/patient.rb
quby-4.0.3 lib/quby/answers/entities/patient.rb
quby-4.0.2 lib/quby/answers/entities/patient.rb
quby-4.0.1 lib/quby/answers/entities/patient.rb
quby-4.0.0 lib/quby/answers/entities/patient.rb
quby-3.2.2 lib/quby/answers/entities/patient.rb