Class: Renalware::Letters::LetterPathology::FilteredObservationSet

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/renalware/letters/letter_pathology.rb

Overview

Filters a set of observations using a specific set of OBX codes

Instance Method Summary collapse

Constructor Details

#initialize(observation_set:, codes: nil) ⇒ FilteredObservationSet

Returns a new instance of FilteredObservationSet.



12
13
14
15
# File 'app/models/concerns/renalware/letters/letter_pathology.rb', line 12

def initialize(observation_set:, codes: nil)
  @codes = codes || RelevantObservationDescription.all.map(&:code)
  @observation_set = observation_set
end

Instance Method Details

#to_hObject

Returns a hash of the filtered observations e.g.

"NA"=>{"result"=>"139", "observed_at"=>"2016-03-15T03:28:00",
"ALB"=>"observed_at"=>"2016-03-15T03:28:00",
...

}



23
24
25
26
27
28
# File 'app/models/concerns/renalware/letters/letter_pathology.rb', line 23

def to_h
  return if observation_set.blank?

  hash = observation_set.values.select { |code, _| codes.include?(code.to_s) }
  hash.empty? ? nil : hash
end