Sha256: 64afbcf6da66a0237239d5d4db0300784e93a0df25fe236a5f198da53a174519

Contents?: true

Size: 1.42 KB

Versions: 157

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/events"

module Renalware
  module Events
    class SummaryPart < Renalware::SummaryPart
      def recent_events
        @recent_events ||= begin
          Events::Event.includes([:created_by, :event_type])
                       .for_patient(patient)
                       .limit(Renalware.config.clinical_summary_max_events_to_display)
                       .ordered
        end
      end

      def recent_events_count
        title_friendly_collection_count(
          actual: recent_events.size,
          total: patient.summary.events_count
        )
      end

      # AR::Relation#cache_key here will issue:
      #   SELECT COUNT(*) AS "size", MAX("events"."updated_at") AS timestamp
      #   FROM "events" WHERE "events"."patient_id" = 1
      # and use size and timestamp in the cache key.
      # We purposefully don't use the recent_events relation here as it has includes and a limit
      # and apart from being slower, using LIMIT in cache_key sql has been known to produce
      # inconsistent results.
      # We need to include the patient.cache_key otherwise if there are no events, the key will
      # be the same for other patients with no events.
      def cache_key
        [patient.cache_key, Events::Event.for_patient(patient).cache_key].join("~")
      end

      def to_partial_path
        "renalware/events/events/summary_part"
      end
    end
  end
end

Version data entries

157 entries across 157 versions & 1 rubygems

Version Path
renalware-core-2.0.127 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.126 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.125 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.124 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.123 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.121 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.120 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.119 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.118 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.117 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.116 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.115 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.113 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.112 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.111 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.110 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.109 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.108 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.106 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.105 app/presenters/renalware/events/summary_part.rb