Class: Renalware::HD::ProtocolPresenter
- Inherits:
-
DumbDelegator
- Object
- DumbDelegator
- Renalware::HD::ProtocolPresenter
- Defined in:
- app/presenters/renalware/hd/protocol_presenter.rb
Instance Attribute Summary collapse
-
#patient ⇒ Object
Returns the value of attribute patient.
Instance Method Summary collapse
- #access ⇒ Object
-
#initialize(patient, view_context) ⇒ ProtocolPresenter
constructor
We must delegate unknown method calls to view_context in order to handle e.g.
- #latest_dry_weight ⇒ Object
- #patient_title ⇒ Object
-
#preference_set ⇒ Object
TODO: some emerging duplication with HD::DashboardPresenter and forthcoming MDMPresenter? Could have a base HD presenter or mixin required elements e.g.
- #prescriptions ⇒ Object
- #profile ⇒ Object
- #recent_pathology ⇒ Object
- #sessions ⇒ Object
-
#with_format(format, &block) ⇒ Object
In order for pdf rendering to easily re-use html partials (despite a mime type of :pdf), pass partial rendering code as a block to ‘with_format`.
Methods inherited from DumbDelegator
#inspect, #public_send, #send, #try, #try!
Constructor Details
#initialize(patient, view_context) ⇒ ProtocolPresenter
We must delegate unknown method calls to view_context in order to handle e.g. .formats (required by our #with_format method) and to avoid errors if any link_to etc helpers are called.
13 14 15 16 17 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 13 def initialize(patient, view_context) @patient = patient @view_context = view_context super(view_context) end |
Instance Attribute Details
#patient ⇒ Object
Returns the value of attribute patient.
8 9 10 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 8 def patient @patient end |
Instance Method Details
#access ⇒ Object
37 38 39 40 41 42 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 37 def access @access ||= begin access_profile = Renalware::Accesses.cast_patient(patient).current_profile Accesses::ProfilePresenter.new(access_profile) end end |
#latest_dry_weight ⇒ Object
19 20 21 22 23 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 19 def latest_dry_weight @latest_dry_weight ||= begin Clinical::DryWeight.for_patient(patient).order(assessed_on: :desc).first end end |
#patient_title ⇒ Object
61 62 63 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 61 def patient_title patient.to_s(:long) end |
#preference_set ⇒ Object
TODO: some emerging duplication with HD::DashboardPresenter and forthcoming MDMPresenter?
Could have a base HD presenter or mixin required elements e.g. from concerns
27 28 29 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 27 def preference_set @preference_set ||= PreferenceSet.for_patient(patient).first_or_initialize end |
#prescriptions ⇒ Object
51 52 53 54 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 51 def prescriptions prescriptions = patient.prescriptions.to_be_administered_on_hd ::CollectionPresenter.new(prescriptions, ::Renalware::Medications::PrescriptionPresenter) end |
#profile ⇒ Object
31 32 33 34 35 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 31 def profile @profile ||= begin ProfilePresenter.new(Profile.for_patient(patient).first_or_initialize) end end |
#recent_pathology ⇒ Object
56 57 58 59 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 56 def recent_pathology current_observation_set = Pathology.cast_patient(patient).current_observation_set current_observation_set&.values || Pathology::CurrentObservationSet.null_values_hash end |
#sessions ⇒ Object
44 45 46 47 48 49 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 44 def sessions @sessions ||= begin hd_sessions = Sessions::ProtocolSessionsQuery.new(patient: patient).call ::CollectionPresenter.new(hd_sessions, Protocol::SessionPresenter, view_context) end end |
#with_format(format, &block) ⇒ Object
In order for pdf rendering to easily re-use html partials (despite a mime type of :pdf), pass partial rendering code as a block to ‘with_format`.
Example issues and usage trying to render my_partial.html.slim from my_template.pdf.slim:
= render 'my_partial' # cannot resolve the html partial
= render 'my_partial', format: :html # resolves partial but i18n requires an `html:` key
- with_format(:html) do
= render 'my_partial' # resolves the html partial and existing i18n keys are used.
See stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-\ different-format-in-rails/3427634#3427634
79 80 81 82 83 84 85 86 87 |
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 79 def with_format(format, &block) old_formats = formats begin self.formats = [format] return block.call ensure self.formats = old_formats end end |