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
- #prescription_administrations ⇒ Object
- #profile ⇒ Object
- #sessions ⇒ Object
Constructor Details
#initialize(patient, view_context, current_user) ⇒ DashboardPresenter
Returns a new instance of DashboardPresenter.
12 13 14 15 16 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 12 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
42 43 44 45 46 47 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 42 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.
87 88 89 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 87 def can_add_access_profile? access.nil? && policy_for(Renalware::Accesses::Profile).new? end |
#can_add_dna_session? ⇒ Boolean
95 96 97 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 95 def can_add_dna_session? policy_for(Renalware::HD::Session::DNA).new? && has_ever_been_on_hd? end |
#can_add_hd_profile? ⇒ Boolean
78 79 80 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 78 def can_add_hd_profile? profile.new_record? && policy_for(profile).edit? && has_ever_been_on_hd? end |
#can_add_preference_set? ⇒ Boolean
82 83 84 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 82 def can_add_preference_set? preference_set.new_record? && policy_for(preference_set).new? && has_ever_been_on_hd? end |
#can_add_session? ⇒ Boolean
91 92 93 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 91 def can_add_session? policy_for(Renalware::HD::Session::Open).new? && has_ever_been_on_hd? end |
#historical_profile_count ⇒ Object
38 39 40 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 38 def historical_profile_count @historical_profile_count ||= Profile.deleted.for_patient(patient).count end |
#historical_profiles ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 28 def historical_profiles @historical_profiles ||= begin Profile .deleted .ordered .limit(3) .for_patient(patient).map { |prof| ProfilePresenter.new(prof) } end end |
#preference_set ⇒ Object
18 19 20 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 18 def preference_set @preference_set ||= PreferenceSet.for_patient(patient).first_or_initialize end |
#prescription_administrations ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 64 def prescription_administrations patient .prescription_administrations .includes( [ :administered_by, :witnessed_by, :reason, prescription: [:medication_route, :drug] ] ) .limit(10).ordered end |
#profile ⇒ Object
22 23 24 25 26 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 22 def profile @profile ||= begin ProfilePresenter.new(Profile.for_patient(patient).first_or_initialize) end end |
#sessions ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/presenters/renalware/hd/dashboard_presenter.rb', line 49 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 |