Class: Renalware::HD::ProtocolPresenter
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
|
#codes_to_show ⇒ Object
64
65
66
67
|
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 64
def codes_to_show
code_group_name = "hd_session_form_recent"
@codes_to_show ||= Pathology::CodeGroup.descriptions_for_group(code_group_name).pluck(:code)
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
69
70
71
|
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 69
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
53
54
55
56
|
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 53
def prescriptions
prescriptions = patient.prescriptions.includes(:drug).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
58
59
60
61
62
|
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 58
def recent_pathology
current_observation_set = Pathology.cast_patient(patient).fetch_current_observation_set
current_observation_set ||= Pathology::NullObservationSet.new
current_observation_set.values_for_codes(codes_to_show)
end
|
#sessions ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 44
def sessions
@sessions ||= begin
hd_sessions =
Sessions::ProtocolSessionsQuery.new(patient: patient)
.call.includes(:patient, :signed_on_by, :signed_off_by)
::CollectionPresenter.new(hd_sessions, Protocol::SessionPresenter, view_context)
end
end
|
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'
= render 'my_partial', format: :html
- with_format(:html) do
= render 'my_partial'
See stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-\ different-format-in-rails/3427634#3427634
87
88
89
90
91
92
93
94
95
|
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 87
def with_format(format, &block)
old_formats = formats
begin
self.formats = [format]
block.call
ensure
self.formats = old_formats
end
end
|