Sha256: ddd0791002537bade568798d40b21b9b4d2be12c246150844a0eca2296a64a98

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

require_dependency "renalware/dashboard"
require_dependency "collection_presenter"

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

      attr_reader :user

      def title
        I18n.t("renalware.dashboard.dashboards.title", name: @user.username&.capitalize)
      end

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

      def letters_in_progress
        @letters_in_progress ||= begin
          present_letters(
            Letters.cast_author(user).letters.in_progress.reverse
          )
        end
      end

      def unread_messages_receipts
        @unread_messages_receipts ||= begin
          receipts = Messaging::Internal.cast_recipient(user).receipts.unread
          CollectionPresenter.new(receipts, Messaging::Internal::ReceiptPresenter)
        end
      end

      def unread_electronic_ccs
        @unread_electronic_ccs ||= begin
          receipts = Letters::ElectronicReceipt.unread.for_recipient(user.id).ordered
          CollectionPresenter.new(receipts, Letters::ElectronicReceiptPresenter)
        end
      end

      private

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc1 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.0.pre.beta12 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.0.pre.beta11 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.0.pre.beta10 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.0.pre.beta9 app/presenters/renalware/dashboard/dashboard_presenter.rb
renalware-core-2.0.0.pre.beta8 app/presenters/renalware/dashboard/dashboard_presenter.rb