Sha256: e7c095949bc784e461e18e16d4d871bcf2889ad6fdae21c88062d9c7db21ffb9

Contents?: true

Size: 1.2 KB

Versions: 35

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

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

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.45 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.44 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.43 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.42 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.41 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.40 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.39 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.38 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.37 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.36 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.35 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.34 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.33 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.32 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.31 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.30 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.28 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.27 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.26 app/models/renalware/hd/patient_statistics.rb