Sha256: 72d3b109d0832f5661f6c1a369501b877bbd492ad658fe4b97034716dff820a0

Contents?: true

Size: 1.44 KB

Versions: 31

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology/requests"

module Renalware
  module Pathology
    module Requests
      class Request < ApplicationRecord
        include Accountable

        TEMPLATES = %w(crs manual).freeze

        belongs_to :patient, class_name: "::Renalware::Pathology::Patient", touch: true
        belongs_to :clinic, class_name: "::Renalware::Clinics::Clinic"
        belongs_to :consultant, class_name: "::Renalware::Pathology::Consultant"
        has_and_belongs_to_many :request_descriptions,
                                class_name: "::Renalware::Pathology::RequestDescription"
        has_and_belongs_to_many :patient_rules,
                                class_name: "::Renalware::Pathology::Requests::PatientRule"

        validates :patient, presence: true
        validates :clinic, presence: true
        validates :consultant, presence: true
        validates :template, presence: true
        validates :template, inclusion: { in: TEMPLATES, allow_nil: false }

        def print_form
          save
        end

        def has_global_requests?
          request_descriptions.any?
        end

        def has_patient_requests?
          patient_rules.any?
        end

        def has_tests_required?
          has_global_requests? || has_patient_requests?
        end

        def requested_on
          created_at.to_date
        end
        alias_method :printed_on, :requested_on
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
renalware-core-2.0.109 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.108 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.106 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.105 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.104 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.103 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.102 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.101 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.100 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.99 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.98 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.97 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.96 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.95 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.94 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.93 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.92 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.91 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.90 app/models/renalware/pathology/requests/request.rb
renalware-core-2.0.89 app/models/renalware/pathology/requests/request.rb