Class: Renalware::Clinics::TotalBodyWater

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/clinics/total_body_water.rb

Constant Summary collapse

NOTHING =
nil
SEX_PROC_MAP =
{
  M: ->(age:, height:, weight:) { 2.447 - 0.09156 * age + 0.1074 * height + 0.3362 * weight },
  F: ->(height:, weight:, **) { -2.097 + 0.1069 * height + 0.2466 * weight }
}.freeze
NOOP =
->(**) { NullObject.instance }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.calculate(dp: 2, **args) ⇒ Object



29
30
31
# File 'app/models/renalware/clinics/total_body_water.rb', line 29

def self.calculate(dp: 2, **args)
  new(**args).calculate(dp: dp)
end

Instance Method Details

#calculate(dp: 2) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/renalware/clinics/total_body_water.rb', line 33

def calculate(dp: 2)
  return NOTHING if height_cm.zero?
  return NOTHING if weight_kg.zero?
  return NOTHING if age.to_i.zero?

  proc_for_sex = SEX_PROC_MAP.fetch(sex_sym, NOOP)

  proc_for_sex.call(
    age: age,
    height: height_cm,
    weight: weight_kg
  ).round(dp)
end