Sha256: 71485805d563cf05107fa4d99a5b81447f19b98ab638d1fac09f3929447e19ef

Contents?: true

Size: 1.06 KB

Versions: 28

Compression:

Stored size: 1.06 KB

Contents

require_dependency "renalware/accesses"

module Renalware
  module Accesses
    class Plan < ApplicationRecord
      include Accountable

      belongs_to :patient, touch: true
      belongs_to :plan_type
      belongs_to :decided_by, class_name: "User", foreign_key: "decided_by_id"

      validates :plan_type, presence: true
      validates :decided_by, presence: true

      scope :ordered, -> { order(created_at: :desc) }
      scope :current, -> { where(terminated_at: nil) }
      scope :historical, -> { where.not(terminated_at: nil) }

      def self.policy_class
        BasePolicy
      end

      def self.attributes_to_ignore_when_comparing
        [:id, :created_at, :updated_at, :created_by_id, :updated_by_id]
      end

      def identical_to?(other)
        attrs_to_ignore = self.class.attributes_to_ignore_when_comparing.map(&:to_s)
        attributes.except(*attrs_to_ignore) == other.attributes.except(*attrs_to_ignore)
      end

      def terminate_by(user)
        self.terminated_at = Time.zone.now
        self.by = user
        save!
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/accesses/plan.rb
renalware-core-2.0.7 app/models/renalware/accesses/plan.rb
renalware-core-2.0.5 app/models/renalware/accesses/plan.rb
renalware-core-2.0.4 app/models/renalware/accesses/plan.rb
renalware-core-2.0.3 app/models/renalware/accesses/plan.rb
renalware-core-2.0.2 app/models/renalware/accesses/plan.rb
renalware-core-2.0.1 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/accesses/plan.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/accesses/plan.rb