Sha256: 4ab2b0df243459f5136ee6ff0f5a74a3642f648432f3addef93425a5f8d68a08

Contents?: true

Size: 1.09 KB

Versions: 134

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

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

134 entries across 134 versions & 1 rubygems

Version Path
renalware-core-2.0.153 app/models/renalware/accesses/plan.rb
renalware-core-2.0.152 app/models/renalware/accesses/plan.rb
renalware-core-2.0.151 app/models/renalware/accesses/plan.rb
renalware-core-2.0.149 app/models/renalware/accesses/plan.rb
renalware-core-2.0.148 app/models/renalware/accesses/plan.rb
renalware-core-2.0.147 app/models/renalware/accesses/plan.rb
renalware-core-2.0.146 app/models/renalware/accesses/plan.rb
renalware-core-2.0.145 app/models/renalware/accesses/plan.rb
renalware-core-2.0.144 app/models/renalware/accesses/plan.rb
renalware-core-2.0.143 app/models/renalware/accesses/plan.rb
renalware-core-2.0.142 app/models/renalware/accesses/plan.rb
renalware-core-2.0.141 app/models/renalware/accesses/plan.rb
renalware-core-2.0.140 app/models/renalware/accesses/plan.rb
renalware-core-2.0.139 app/models/renalware/accesses/plan.rb
renalware-core-2.0.138 app/models/renalware/accesses/plan.rb
renalware-core-2.0.137 app/models/renalware/accesses/plan.rb
renalware-core-2.0.136 app/models/renalware/accesses/plan.rb
renalware-core-2.0.135 app/models/renalware/accesses/plan.rb
renalware-core-2.0.134 app/models/renalware/accesses/plan.rb
renalware-core-2.0.133 app/models/renalware/accesses/plan.rb