Class: Renalware::Dashboard::DashboardPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/renalware/dashboard/dashboard_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ DashboardPresenter

Returns a new instance of DashboardPresenter.



9
10
11
# File 'app/presenters/renalware/dashboard/dashboard_presenter.rb', line 9

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



13
14
15
# File 'app/presenters/renalware/dashboard/dashboard_presenter.rb', line 13

def user
  @user
end

Instance Method Details

#bookmarksObject



15
16
17
18
19
20
21
22
# File 'app/presenters/renalware/dashboard/dashboard_presenter.rb', line 15

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

#letters_in_progressObject

Note we want oldest letters ordered first on the dashboard - elsewhere letters are newest first



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/presenters/renalware/dashboard/dashboard_presenter.rb', line 26

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

#unread_electronic_ccsObject



50
51
52
53
54
55
56
57
58
59
# File 'app/presenters/renalware/dashboard/dashboard_presenter.rb', line 50

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

#unread_messages_receiptsObject



39
40
41
42
43
44
45
46
47
48
# File 'app/presenters/renalware/dashboard/dashboard_presenter.rb', line 39

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