Sha256: 3b8d6b460d75153fc0e04037cf3b48ca5825b87714f3412ae5ac9fd0bb2bbb6c

Contents?: true

Size: 1.32 KB

Versions: 36

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/admissions"

module Renalware
  module Admissions
    class Consult < ApplicationRecord
      include Accountable
      extend Enumerize
      include PatientsRansackHelper
      PRIORITY_VALUES = (1..20).freeze
      validates :patient_id, presence: true
      validates :started_on, presence: true
      validates :description, presence: true
      validates :priority,
                numericality: {
                  only_integer: true,
                  less_than_or_equal_to: PRIORITY_VALUES.last,
                  allow_blank: true
                }

      validates :other_site_or_ward, presence: {
        if: ->(consult) { consult.consult_site_id.blank? && consult.hospital_ward_id.blank? }
      }

      belongs_to :patient, touch: true
      belongs_to :consult_site, class_name: "Admissions::ConsultSite"
      belongs_to :hospital_ward, class_name: "Hospitals::Ward"
      belongs_to :specialty, class_name: "Admissions::Specialty"
      belongs_to :seen_by, class_name: "User"

      enumerize :transfer_priority, in: %i(unknown necessary desirable potential unnecessary)
      enumerize :aki_risk, in: %i(yes no unknown)

      scope :active, -> { where(ended_on: nil) }

      ransacker :priority do
        Arel.sql("coalesce(priority, -1)")
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

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