Sha256: 3191a6e51f262bef1c32d3fe09a39ed1f26e176291f547eb8cf05e6070d0988f

Contents?: true

Size: 1.16 KB

Versions: 35

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.45 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.44 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.43 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.42 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.41 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.40 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.39 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.38 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.37 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.36 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.35 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.34 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.33 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.32 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.31 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.30 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.28 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.27 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.26 app/models/renalware/pd/apd/regime_calculations.rb