Class: Renalware::HD::DashboardPresenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patient, view_context, current_user) ⇒ DashboardPresenter

Returns a new instance of DashboardPresenter.



11
12
13
14
15
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 11

def initialize(patient, view_context, current_user)
  @patient = patient
  @view_context = view_context
  @current_user = current_user
end

Instance Attribute Details

#patientObject

Returns the value of attribute patient.



8
9
10
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 8

def patient
  @patient
end

Instance Method Details

#accessObject



41
42
43
44
45
46
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 41

def access
  @access ||= begin
    access_profile = Renalware::Accesses.cast_patient(patient).current_profile
    Accesses::ProfilePresenter.new(access_profile)
  end
end

#can_add_access_profile?Boolean

Its possible to add an Access Profile even if the patient does not have the HD modality.

Returns:

  • (Boolean)


86
87
88
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 86

def can_add_access_profile?
  access.nil? && policy_for(Renalware::Accesses::Profile).new?
end

#can_add_dna_session?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 94

def can_add_dna_session?
  policy_for(Renalware::HD::Session::DNA).new? && has_ever_been_on_hd?
end

#can_add_hd_profile?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 77

def can_add_hd_profile?
  profile.new_record? && policy_for(profile).edit? && has_ever_been_on_hd?
end

#can_add_preference_set?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 81

def can_add_preference_set?
  preference_set.new_record? && policy_for(preference_set).new? && has_ever_been_on_hd?
end

#can_add_session?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 90

def can_add_session?
  policy_for(Renalware::HD::Session::Open).new? && has_ever_been_on_hd?
end

#historical_profile_countObject



37
38
39
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 37

def historical_profile_count
  @historical_profile_count ||= Profile.deleted.for_patient(patient).count
end

#historical_profilesObject



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

def historical_profiles
  @historical_profiles ||= begin
    Profile
      .deleted
      .ordered
      .limit(3)
      .for_patient(patient).map { |prof| ProfilePresenter.new(prof) }
  end
end

#preference_setObject



17
18
19
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 17

def preference_set
  @preference_set ||= PreferenceSet.for_patient(patient).first_or_initialize
end

#prescription_administrationsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 63

def prescription_administrations
  patient
    .prescription_administrations
    .includes(
      [
        :administered_by,
        :witnessed_by,
        :reason,
        prescription: [:medication_route, :drug]
      ]
    )
    .limit(10).ordered
end

#profileObject



21
22
23
24
25
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 21

def profile
  @profile ||= begin
    ProfilePresenter.new(Profile.for_patient(patient).first_or_initialize)
  end
end

#sessionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 48

def sessions
  @sessions ||= begin
    hd_sessions = Session
      .eager_load(
        :hospital_unit,
        :patient,
        :signed_on_by,
        :signed_off_by
      )
      .for_patient(patient)
      .limit(10).ordered
    CollectionPresenter.new(hd_sessions, SessionPresenter, view_context)
  end
end