Class: Renalware::HD::SessionPresenter

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

Direct Known Subclasses

Protocol::SessionPresenter

Constant Summary collapse

RR40_ACCESS_SIDE_MAP =
{
  "left" => "L",
  "right" => "R",
  "unknown" => "U"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, view_context = nil) ⇒ SessionPresenter

Returns a new instance of SessionPresenter.



45
46
47
48
49
# File 'app/presenters/renalware/hd/session_presenter.rb', line 45

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.



12
13
14
# File 'app/presenters/renalware/hd/session_presenter.rb', line 12

def preference_set
  @preference_set
end

Instance Method Details

#access_rr02_codeObject

We only store the abbreviated access (rr02 + “ ” + rr41) so just take the first word which will be the rr02 code



141
142
143
144
145
# File 'app/presenters/renalware/hd/session_presenter.rb', line 141

def access_rr02_code
  return if access_type_abbreviation.blank?

  access_type_abbreviation.split(" ").first
end

#access_rr41_codeObject

We only store the abbreviated access (rr02 + “ ” + rr41) so to resolve rr41, take the last word if there are >1 words in the abbreviation



149
150
151
152
153
154
# File 'app/presenters/renalware/hd/session_presenter.rb', line 149

def access_rr41_code
  return if access_type_abbreviation.blank?

  parts = access_type_abbreviation.split(" ")
  return parts.last if parts.length > 1
end

#access_side_rr40_codeObject



135
136
137
# File 'app/presenters/renalware/hd/session_presenter.rb', line 135

def access_side_rr40_code
  RR40_ACCESS_SIDE_MAP[access_side] || RR40_ACCESS_SIDE_MAP["unknown"]
end

#access_usedObject



112
113
114
# File 'app/presenters/renalware/hd/session_presenter.rb', line 112

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

#after_measurement_for(measurement) ⇒ Object



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

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

#before_measurement_for(measurement) ⇒ Object



87
88
89
# File 'app/presenters/renalware/hd/session_presenter.rb', line 87

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

#change_in(measurement) ⇒ Object



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

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
  nil
end

#durationObject

Returns duration as e.g. “02:01”



78
79
80
# File 'app/presenters/renalware/hd/session_presenter.rb', line 78

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

#duration_in_minutesObject

Returns duration as e.g. 121 (minutes)



83
84
85
# File 'app/presenters/renalware/hd/session_presenter.rb', line 83

def duration_in_minutes
  __getobj__.duration
end

#edit_or_view_urlObject



122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/presenters/renalware/hd/session_presenter.rb', line 122

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



73
74
75
# File 'app/presenters/renalware/hd/session_presenter.rb', line 73

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

#had_intradialytic_hypotension?Boolean

Returns:

  • (Boolean)


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

def had_intradialytic_hypotension?
  had_intradialytic_hypotension&.yes? ? "Y" : "N"
end

#performed_onObject



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

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

#performed_on_dateObject



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

def performed_on_date
  __getobj__.performed_on
end

#start_timeObject



69
70
71
# File 'app/presenters/renalware/hd/session_presenter.rb', line 69

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

#stateObject



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

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

#summarised_access_usedObject



108
109
110
# File 'app/presenters/renalware/hd/session_presenter.rb', line 108

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

#truncated_notesObject



116
117
118
119
120
# File 'app/presenters/renalware/hd/session_presenter.rb', line 116

def truncated_notes
  return if notes.blank?

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