Sha256: ef478ffa6a674d90288facf28f6c65664dc8cfacb37203c73e61084e7d44873e

Contents?: true

Size: 914 Bytes

Versions: 64

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/hospitals"

module Renalware
  module Hospitals
    class Centre < ApplicationRecord
      has_many(
        :units,
        class_name: "Hospitals::Unit",
        foreign_key: :hospital_centre_id,
        dependent: :restrict_with_exception
      )

      scope :ordered, -> { order(:name) }
      scope :active, -> { where(active: true) }
      scope :performing_transplant, -> { active.where(is_transplant_site: true) }
      scope :with_hd_sites, -> { where(id: Unit.hd_sites.pluck(:hospital_centre_id)) }

      validates :code, presence: true
      validates :name, presence: true

      def hd_sites
        units.hd_sites.ordered
      end

      def self.policy_class
        BasePolicy
      end

      def to_s
        if location.present?
          "#{name} (#{location})"
        else
          name
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

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