Sha256: bfaa0b540f54330d67c8bff9892e877c9014e5e2c987f9c9a7fe353f7bb33448

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 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
      # Currently #consult_type is a string and we are not sure what should be in there
      # Migrated consults may not have a type so only enforce it creation of new ones.
      validates :consult_type, presence: true, on: :create
      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 :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

21 entries across 21 versions & 1 rubygems

Version Path
renalware-core-2.0.131 app/models/renalware/admissions/consult.rb
renalware-core-2.0.130 app/models/renalware/admissions/consult.rb
renalware-core-2.0.129 app/models/renalware/admissions/consult.rb
renalware-core-2.0.128 app/models/renalware/admissions/consult.rb
renalware-core-2.0.127 app/models/renalware/admissions/consult.rb
renalware-core-2.0.126 app/models/renalware/admissions/consult.rb
renalware-core-2.0.125 app/models/renalware/admissions/consult.rb
renalware-core-2.0.124 app/models/renalware/admissions/consult.rb
renalware-core-2.0.123 app/models/renalware/admissions/consult.rb
renalware-core-2.0.121 app/models/renalware/admissions/consult.rb
renalware-core-2.0.120 app/models/renalware/admissions/consult.rb
renalware-core-2.0.119 app/models/renalware/admissions/consult.rb
renalware-core-2.0.118 app/models/renalware/admissions/consult.rb
renalware-core-2.0.117 app/models/renalware/admissions/consult.rb
renalware-core-2.0.116 app/models/renalware/admissions/consult.rb
renalware-core-2.0.115 app/models/renalware/admissions/consult.rb
renalware-core-2.0.113 app/models/renalware/admissions/consult.rb
renalware-core-2.0.112 app/models/renalware/admissions/consult.rb
renalware-core-2.0.111 app/models/renalware/admissions/consult.rb
renalware-core-2.0.110 app/models/renalware/admissions/consult.rb