Sha256: 3bc96b302017c1086fb1dc18b122cdde9ca2f105d1b0122f6f4f8b69fb64f587

Contents?: true

Size: 1.13 KB

Versions: 28

Compression:

Stored size: 1.13 KB

Contents

require_dependency "renalware/pd"
require_relative "./glucose_calculator"

module Renalware
  module PD
    module APD
      class RegimeCalculations < SimpleDelegator
        INCALCULABLE = nil

        def calculated_overnight_volume
          raise NotImplementedAError
        end

        #  The total volume of all bags for a day when they have PD.
        def calculated_daily_volume
          vol = [
            calculated_overnight_volume,
            effective_last_fill_volume,
            effective_additional_manual_exchange_volume
          ].compact.inject(0, :+)
          vol == 0 ? nil : vol
        end

        def volume_of_glucose_at_strength(strength)
          raise "Overnight volume must be calculated first" if overnight_volume.blank?
          GlucoseCalculator.new(regime: self, strength: strength).glucose_content
        end

        private

        def effective_last_fill_volume
          has_last_fill_bag? ? last_fill_volume : 0
        end

        def effective_additional_manual_exchange_volume
          has_additional_manual_exchange_bag? ? additional_manual_exchange_volume : 0
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.7 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.5 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.4 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.3 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.2 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.1 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/pd/apd/regime_calculations.rb