Class: Renalware::Pathology::ObservationsDiff

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/renalware/pathology/observations_diff.rb

Defined Under Namespace

Classes: Observation

Instance Method Summary collapse

Instance Method Details

#changes?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/presenters/renalware/pathology/observations_diff.rb', line 18

def changes?
  @changes
end

#to_hObject

Given two hashes like this

HGB: { result: 2.1, observed_at: "2017-12-12 00:01:01",
CRE: { result: 9, observed_at: "2017-12-12 00:01:01"}

} {

HGB: { result: 1.0, observed_at: "2018-12-12 00:01:01"}, # changed
CRE: { result: 1.1, observed_at: "2017-12-11 00:01:01"}, # no change!
PTH: { result: 1.1, observed_at: "2017-12-11 00:01:01"}  # new!

} Return a hash that looks like this {

 HGB: [
   { result: 2.1, observed_at: "2017-12-12 00:01:01"}, # original
   { result: 1.0, observed_at: "2018-12-12 00:01:01"}, # changed
   -1.1 # digg
 ],
 CRE: [
   { result: 9, observed_at: "2017-12-12 00:01:01"},
   nil, # no new value
   nil # no change
 ],
 PTH: [
   nil, # no original
   { result: 1.1, observed_at: "2017-12-11 00:01:01"}  # new!
   1.1
]

} rubocop:disable Metrics/AbcSize,Metrics/MethodLength



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/presenters/renalware/pathology/observations_diff.rb', line 80

def to_h
  return {} if observation_set_a.blank? && observation_set_a.blank?

  filter_observations

  description_codes.each_with_object({}) do |code, hash|
    obs_a = Observation.new(observation_set_a.fetch(code, {}))
    obs_b = Observation.new(observation_set_b.fetch(code, {}))

    arr = Array.new(3)
    arr[0] = obs_a if obs_a.any?

    if obs_b.supercedes?(obs_a)
      arr[1] = obs_b
      arr[2] = obs_b.result.to_f - obs_a.result.to_f
    end

    hash[code] = arr
  end
end

#to_htmlObject



22
23
24
# File 'app/presenters/renalware/pathology/observations_diff.rb', line 22

def to_html
  render
end