Class: Renalware::HD::DashboardPresenter
- Inherits:
-
Object
- Object
- Renalware::HD::DashboardPresenter
- Defined in:
- app/presenters/renalware/hd/dashboard_presenter.rb
Instance Attribute Summary collapse
-
#patient ⇒ Object
Returns the value of attribute patient.
Instance Method Summary collapse
- #access ⇒ Object
-
#can_add_access_profile? ⇒ Boolean
Its possible to add an Access Profile even if the patient does not have the HD modality.
- #can_add_dna_session? ⇒ Boolean
- #can_add_hd_profile? ⇒ Boolean
- #can_add_preference_set? ⇒ Boolean
- #can_add_session? ⇒ Boolean
- #historical_profile_count ⇒ Object
- #historical_profiles ⇒ Object
-
#initialize(patient, view_context, current_user) ⇒ DashboardPresenter
constructor
A new instance of DashboardPresenter.
- #preference_set ⇒ Object
- #profile ⇒ Object
- #sessions ⇒ Object
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
#patient ⇒ Object
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
#access ⇒ Object
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.
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
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
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
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
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_count ⇒ Object
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_profiles ⇒ Object
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_set ⇒ Object
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 |
#profile ⇒ Object
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 |
#sessions ⇒ Object
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, :signed_on_by, :signed_off_by) .for_patient(patient) .limit(10).ordered CollectionPresenter.new(hd_sessions, SessionPresenter, view_context) end end |