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.1.1 app/presenters/renalware/events/summary_part.rb
renalware-core-2.1.0 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.167 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.166 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.165 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.164 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.163 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.162 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.161 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.160 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.159 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.158 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.157 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.156 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.155 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.153 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.152 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.151 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.149 app/presenters/renalware/events/summary_part.rb
renalware-core-2.0.148 app/presenters/renalware/events/summary_part.rb