Sha256: b981b0259d6f155397a07dc6c3cd82cefa44d612a7e840a72f343e06e8719e70

Contents?: true

Size: 1.17 KB

Versions: 104

Compression:

Stored size: 1.17 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

104 entries across 104 versions & 1 rubygems

Version Path
renalware-core-2.0.159 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.158 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.157 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.156 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.155 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.153 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.152 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.151 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.149 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.148 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.147 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.146 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.145 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.144 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.143 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.142 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.141 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.140 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.139 app/models/renalware/pd/apd/regime_calculations.rb
renalware-core-2.0.138 app/models/renalware/pd/apd/regime_calculations.rb