Sha256: a72be76c8e304b0fe45413f79fcbf64ac45fef8524058b8fdda1b8e0a1edee52

Contents?: true

Size: 1.59 KB

Versions: 33

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/problems"

module Renalware
  module Problems
    class Problem < ApplicationRecord
      include PatientScope
      include Accountable

      acts_as_paranoid
      has_paper_trail class_name: "Renalware::Problems::Version", on: [:create, :update, :destroy]

      belongs_to :patient, touch: true
      has_many :notes, -> { ordered }, dependent: :destroy

      scope :ordered, -> { order(position: :asc) }
      scope :with_notes, -> { eager_load(:notes).merge(Renalware::Problems::Note.ordered) }
      scope :with_patient, -> { includes(:patient) }
      scope :with_versions, -> { includes(versions: :item) }

      # This scope is called by CoreExtensions::ActiveRecord::Sort
      scope :position_sorting_scope, ->(problem) { where(patient_id: problem.patient.id) }

      validates :patient, presence: true
      validates :description, presence: true

      def self.with_archived
        with_deleted
      end

      def self.current
        all.with_notes
      end

      def self.archived
        only_deleted.with_notes
      end

      def archived?
        deleted?
      end

      def archived_at
        deleted_at
      end

      def archived_on
        deleted_at.to_date
      end

      def created_on
        created_at.to_date
      end

      def updated_on
        updated_at.to_date
      end

      def self.reject_if_proc
        proc { |attrs| attrs[:description].blank? }
      end

      def full_description
        description
      end

      def formatted
        "#{full_description}, #{date}"
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
renalware-core-2.0.148 app/models/renalware/problems/problem.rb
renalware-core-2.0.147 app/models/renalware/problems/problem.rb
renalware-core-2.0.146 app/models/renalware/problems/problem.rb
renalware-core-2.0.145 app/models/renalware/problems/problem.rb
renalware-core-2.0.144 app/models/renalware/problems/problem.rb
renalware-core-2.0.143 app/models/renalware/problems/problem.rb
renalware-core-2.0.142 app/models/renalware/problems/problem.rb
renalware-core-2.0.141 app/models/renalware/problems/problem.rb
renalware-core-2.0.140 app/models/renalware/problems/problem.rb
renalware-core-2.0.139 app/models/renalware/problems/problem.rb
renalware-core-2.0.138 app/models/renalware/problems/problem.rb
renalware-core-2.0.137 app/models/renalware/problems/problem.rb
renalware-core-2.0.136 app/models/renalware/problems/problem.rb
renalware-core-2.0.135 app/models/renalware/problems/problem.rb
renalware-core-2.0.134 app/models/renalware/problems/problem.rb
renalware-core-2.0.133 app/models/renalware/problems/problem.rb
renalware-core-2.0.132 app/models/renalware/problems/problem.rb
renalware-core-2.0.131 app/models/renalware/problems/problem.rb
renalware-core-2.0.130 app/models/renalware/problems/problem.rb
renalware-core-2.0.129 app/models/renalware/problems/problem.rb