Sha256: a2d680916a0bf915df35754a89d237dc21add1d7c31fbe4efcd851120a444e4d

Contents?: true

Size: 1.88 KB

Versions: 114

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/dashboard"
require_dependency "collection_presenter"

module Renalware
  module Dashboard
    class DashboardPresenter
      def initialize(user)
        @user = user
      end

      attr_reader :user

      def bookmarks
        @bookmarks ||= begin
          Patients.cast_user(user)
                  .bookmarks
                  .ordered
                  .includes(patient: [current_modality: :description])
        end
      end

      # Note we want oldest letters ordered first on the dashboard - elsewhere letters
      # are newest first
      def letters_in_progress
        @letters_in_progress ||= begin
          present_letters(
            Letters::Letter
              .reversed
              .where("author_id = ? or created_by_id = ?", user.id, user.id)
              .in_progress
              .includes(:author, :patient, :letterhead)
          )
          # Renalware::Letters.cast_author(user)
        end
      end

      def unread_messages_receipts
        @unread_messages_receipts ||= begin
          receipts = Messaging::Internal.cast_recipient(user)
            .receipts
            .includes(message: [:author, :patient])
            .order("messaging_messages.sent_at asc")
            .unread
          CollectionPresenter.new(receipts, Messaging::Internal::ReceiptPresenter)
        end
      end

      def unread_electronic_ccs
        @unread_electronic_ccs ||= begin
          receipts = Letters::ElectronicReceipt
            .includes(letter: [:patient, :author, :letterhead])
            .unread
            .for_recipient(user.id)
            .order(created_at: :asc)
          CollectionPresenter.new(receipts, Letters::ElectronicReceiptPresenter)
        end
      end

      private

      def present_letters(letters)
        CollectionPresenter.new(letters, Letters::LetterPresenterFactory)
      end
    end
  end
end

Version data entries

114 entries across 114 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.1.0 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.167 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.166 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.165 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.164 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.163 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.162 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.161 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.160 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.159 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.158 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.157 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.156 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.155 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.153 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.152 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.151 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.149 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.148 app/presenters/renalware/dashboard/dashboard_presenter.rb