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.



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

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



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

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



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

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



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

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

#access_usedObject



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

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

#after_measurement_for(measurement) ⇒ Object



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

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

#before_measurement_for(measurement) ⇒ Object



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

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

#change_in(measurement) ⇒ Object



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

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”



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

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

#duration_in_minutesObject

Returns duration as e.g. 121 (minutes)



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

def duration_in_minutes
  __getobj__.duration
end

#edit_or_view_urlObject



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

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



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

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

#had_intradialytic_hypotension?Boolean

Returns:

  • (Boolean)


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

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

#performed_onObject



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

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



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

def performed_on_date
  __getobj__.performed_on
end

#start_timeObject



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

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

#stateObject



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

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

#summarised_access_usedObject



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

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

#truncated_notesObject



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

def truncated_notes
  return if notes.blank?

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