Sha256: 885e0cb9952d2a4d3eeddbc73d8d9bb74bb17d704236d3515463fe6b797731e6

Contents?: true

Size: 1.2 KB

Versions: 114

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

114 entries across 114 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.1.0 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.167 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.166 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.165 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.164 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.163 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.162 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.161 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.160 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.159 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.158 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.157 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.156 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.155 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.153 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.152 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.151 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.149 app/models/renalware/hd/patient_statistics.rb
renalware-core-2.0.148 app/models/renalware/hd/patient_statistics.rb