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)


66
67
68
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 66

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

#can_add_dna_session?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 74

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)


57
58
59
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 57

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)


61
62
63
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 61

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)


70
71
72
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 70

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

#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
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 48

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