Sha256: 3aca96967cfe8fda0a2806588a32d4147a009f3c8b9db7d542ac03a897e5a97b

Contents?: true

Size: 955 Bytes

Versions: 18

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/clinics"

# The body surface area (BSA) of a patient calculated using DuBois/DuBois
# BSA = 0.007184 * Height^0.725 * Weight^0.425
# Resources:
# - Calculators
#   - https://www.msdmanuals.com/en-gb/medical-calculators/BodySurfaceArea.htm
#   - http://www.medcalc.com/body.html
module Renalware
  module Clinics
    class BodySurfaceArea
      pattr_initialize [:weight!, :height!]

      def self.calculate(weight:, height:, dp: 2)
        new(weight: weight, height: height).calculate(dp: dp)
      end

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

        # NB ** is ruby syntax for power of (^)
        result = 0.007184 * (weight_kg**0.425) * (height_cm**0.725)
        result.round(dp)
      end

      private

      def height_cm
        height.to_f * 100
      end

      def weight_kg
        weight.to_f
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.1.0 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.167 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.166 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.165 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.164 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.163 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.162 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.161 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.160 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.159 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.158 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.157 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.156 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.155 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.153 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.152 app/models/renalware/clinics/body_surface_area.rb
renalware-core-2.0.151 app/models/renalware/clinics/body_surface_area.rb