Sha256: 1643c65641e3989b9e5c079dc7c2aefe34b8e04022ed6ee945c46f189883a96a

Contents?: true

Size: 1.89 KB

Versions: 118

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/events"

module Renalware
  module Events
    class Event < ApplicationRecord
      include Accountable
      include PatientScope

      # Virtual attribute helps us persist in the UI (across posts) whether or not the
      # event_type can be changed. If we target e.g.
      #   patient_new_specific_event(slug: 'something')
      # it can be assumed we are creating an event of a certain type (event_type.slug ==
      # 'something') and therefore changing that type in the new event form should be disallowed
      attr_accessor :disable_selection_of_event_type

      belongs_to :patient, touch: true
      belongs_to :event_type, class_name: "Type"

      validates :patient, presence: true
      validates :date_time, presence: true
      validates :event_type_id, presence: true
      validates :date_time, timeliness: { type: :datetime }

      scope :ordered, -> { order(date_time: :desc, updated_at: :desc) }

      # By default an event has no embedded document but a subclass may
      # implement one using has_document
      def document
        NullObject.instance
      end

      def to_s
        description
      end

      # As Events are a cross domain model, a subclass can choose to override to_partial_path etc
      # in order to use events from another namespace for instance.
      def to_partial_path
        partial_for "inputs"
      end
      alias :to_input_partial_path :to_partial_path

      def to_cell_partial_path
        partial_for "cell"
      end

      def to_toggled_cell_partial_path
        partial_for "toggled_cell"
      end

      def partial_for(partial_type)
        File.join(
          "renalware/events/events",
          partial_type,
          self.class.name.demodulize.underscore
        )
      end

      private

      def our_class_name
        self.class.name.demodulize.underscore
      end
    end
  end
end

Version data entries

118 entries across 118 versions & 1 rubygems

Version Path
renalware-core-2.0.136 app/models/renalware/events/event.rb
renalware-core-2.0.135 app/models/renalware/events/event.rb
renalware-core-2.0.134 app/models/renalware/events/event.rb
renalware-core-2.0.133 app/models/renalware/events/event.rb
renalware-core-2.0.132 app/models/renalware/events/event.rb
renalware-core-2.0.131 app/models/renalware/events/event.rb
renalware-core-2.0.130 app/models/renalware/events/event.rb
renalware-core-2.0.129 app/models/renalware/events/event.rb
renalware-core-2.0.128 app/models/renalware/events/event.rb
renalware-core-2.0.127 app/models/renalware/events/event.rb
renalware-core-2.0.126 app/models/renalware/events/event.rb
renalware-core-2.0.125 app/models/renalware/events/event.rb
renalware-core-2.0.124 app/models/renalware/events/event.rb
renalware-core-2.0.123 app/models/renalware/events/event.rb
renalware-core-2.0.121 app/models/renalware/events/event.rb
renalware-core-2.0.120 app/models/renalware/events/event.rb
renalware-core-2.0.119 app/models/renalware/events/event.rb
renalware-core-2.0.118 app/models/renalware/events/event.rb
renalware-core-2.0.117 app/models/renalware/events/event.rb
renalware-core-2.0.116 app/models/renalware/events/event.rb