Class: Renalware::HD::SessionPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/presenters/renalware/hd/session_presenter.rb

Direct Known Subclasses

Protocol::SessionPresenter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, view_context = nil) ⇒ SessionPresenter

Returns a new instance of SessionPresenter.



32
33
34
35
36
# File 'app/presenters/renalware/hd/session_presenter.rb', line 32

def initialize(session, view_context = nil)
  @view_context = view_context
  @session = session
  super(session)
end

Instance Attribute Details

#preference_setObject (readonly)

Returns the value of attribute preference_set.



6
7
8
# File 'app/presenters/renalware/hd/session_presenter.rb', line 6

def preference_set
  @preference_set
end

Instance Method Details

#access_usedObject



85
86
87
# File 'app/presenters/renalware/hd/session_presenter.rb', line 85

def access_used
  Renalware::HD::SessionAccessPresenter.new(self).to_s
end

#after_measurement_for(measurement) ⇒ Object



64
65
66
# File 'app/presenters/renalware/hd/session_presenter.rb', line 64

def after_measurement_for(measurement)
  observations_after.try!(measurement.to_sym)
end

#before_measurement_for(measurement) ⇒ Object



60
61
62
# File 'app/presenters/renalware/hd/session_presenter.rb', line 60

def before_measurement_for(measurement)
  observations_before.try(measurement.to_sym)
end

#change_in(measurement) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/presenters/renalware/hd/session_presenter.rb', line 68

def change_in(measurement)
  pre = before_measurement_for(measurement)
  post = after_measurement_for(measurement)
  return if pre.blank? || post.blank?

  case pre
  when ::Float then (post - pre).round(1)
  when ::Integer then (post - pre)
  end
rescue StandardError => exception
  nil
end

#durationObject



56
57
58
# File 'app/presenters/renalware/hd/session_presenter.rb', line 56

def duration
  super && ::Renalware::Duration.from_minutes(super)
end

#edit_or_view_urlObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/presenters/renalware/hd/session_presenter.rb', line 95

def edit_or_view_url
  i18n_scope = "renalware.hd.sessions.#{session.state}"
  if immutable?
    view_context.link_to(I18n.t(".view", scope: i18n_scope),
                         view_context.patient_hd_session_path(patient, self),
                         class: "nowrap")
  else
    view_context.link_to(I18n.t(".edit", scope: i18n_scope),
                         view_context.edit_patient_hd_session_path(patient, self),
                         class: "nowrap")
  end
end

#end_timeObject



52
53
54
# File 'app/presenters/renalware/hd/session_presenter.rb', line 52

def end_time
  ::I18n.l(super, format: :time)
end

#performed_onObject



42
43
44
45
46
# File 'app/presenters/renalware/hd/session_presenter.rb', line 42

def performed_on
  url = view_context.patient_hd_session_path(session.patient, session)
  text = ::I18n.l(super)
  view_context.link_to(text, url)
end

#start_timeObject



48
49
50
# File 'app/presenters/renalware/hd/session_presenter.rb', line 48

def start_time
  ::I18n.l(super, format: :time)
end

#stateObject



38
39
40
# File 'app/presenters/renalware/hd/session_presenter.rb', line 38

def state
  self.class.to_s.demodulize.downcase
end

#summarised_access_usedObject



81
82
83
# File 'app/presenters/renalware/hd/session_presenter.rb', line 81

def summarised_access_used
  Renalware::HD::SessionAccessPresenter.new(self).to_html
end

#truncated_notesObject



89
90
91
92
93
# File 'app/presenters/renalware/hd/session_presenter.rb', line 89

def truncated_notes
  return unless notes

  notes.truncate(100, omission: "…").html_safe
end