Class: Renalware::HD::ProtocolPresenter

Inherits:
DumbDelegator show all
Defined in:
app/presenters/renalware/hd/protocol_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#patientObject

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

#accessObject



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_weightObject



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_titleObject



63
64
65
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 63

def patient_title
  patient.to_s(:long)
end

#preference_setObject

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

#prescriptionsObject



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

#profileObject



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_pathologyObject



58
59
60
61
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 58

def recent_pathology
  current_observation_set = Pathology.cast_patient(patient).current_observation_set
  current_observation_set&.values || Pathology::CurrentObservationSet.null_values_hash
end

#sessionsObject



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

#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



81
82
83
84
85
86
87
88
89
# File 'app/presenters/renalware/hd/protocol_presenter.rb', line 81

def with_format(format, &block)
  old_formats = formats
  begin
    self.formats = [format]
    block.call
  ensure
    self.formats = old_formats
  end
end