Sha256: 99822803216a1e96b30a48b4142e5f3fc97a3f8a8fdd124b0f3a215a92731be4

Contents?: true

Size: 1.86 KB

Versions: 11

Compression:

Stored size: 1.86 KB

Contents

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

11 entries across 11 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/events/event.rb
renalware-core-2.0.7 app/models/renalware/events/event.rb
renalware-core-2.0.5 app/models/renalware/events/event.rb
renalware-core-2.0.4 app/models/renalware/events/event.rb
renalware-core-2.0.3 app/models/renalware/events/event.rb
renalware-core-2.0.2 app/models/renalware/events/event.rb
renalware-core-2.0.1 app/models/renalware/events/event.rb
renalware-core-2.0.0 app/models/renalware/events/event.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/events/event.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/events/event.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/events/event.rb