Sha256: bc8ef054b43ff813a86b7dd0c315076a92a7a67b62daec90c25061e87cb16c14

Contents?: true

Size: 1.17 KB

Versions: 28

Compression:

Stored size: 1.17 KB

Contents

require_dependency "renalware/hd"

module Renalware
  module HD
    class PatientStatistics < ApplicationRecord
      include PatientScope

      belongs_to :patient
      belongs_to :hospital_unit, class_name: "Hospitals::Unit"

      validates :hospital_unit, presence: true
      validates :patient,
                presence: true,
                uniqueness: { scope: [:month, :year] }

      validates :month,
                numericality: true,
                inclusion: 1..12,
                allow_nil: true

      validates :month, presence: true, unless: :rolling?
      validates :year, presence: true, unless: :rolling?

      validates :year,
                numericality: true,
                inclusion: 1970..2100,
                allow_nil: true

      validates :rolling,
                inclusion: { in: [true, nil] }

      validates :session_count, presence: true, numericality: true

      scope :ordered, lambda {
        order(:rolling, year: :desc, month: :desc)
      }

      def to_s
        return "Last #{session_count} sessions" if rolling?
        if year > 0 && month > 0
          Date.new(year, month).strftime("%b %Y")
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.7 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.5 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.4 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.3 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.2 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.1 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/hd/patient_statistics.rb