Class: Pueri::DoseCalc

Inherits:
Object
  • Object
show all
Defined in:
lib/pueri/dosecalc.rb

Overview

Calculates the prescription of a given medication given the weight of the pacient, the dose-per-weight-day, the concentration of the medication's presentation and the periodicity of takes in hours.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ DoseCalc

Calculate the dosage for each taking of a given medicine.

Parameters:

  • params (Hash)

    A Hash of elements, all of which are required to properly calculate and output the final dosage-per-taking:

    :weight

    The weight of the pacient, in kilograms.

    :dose

    The dose for the pacient, in unit/kg/day.

    :time

    The time between takings, in hours.

    :days

    The number of days to take the medication.

    :concentration

    The posologic concentration, number only.

    :dose_unit

    The unit of dosage for the pacient (e.g. mg/kg/d).

    :conc_unit

    The unit of concentration (e.g. mg/mL, mcg/pill).

    :name

    The name of the medication.



23
24
25
26
# File 'lib/pueri/dosecalc.rb', line 23

def initialize(params)
  init_vars(params)
  @result = ((@weight * @dose * @time) / (24.0 * @concentration)).round(3)
end

Instance Attribute Details

#conc_unitObject

Returns the value of attribute conc_unit



9
10
11
# File 'lib/pueri/dosecalc.rb', line 9

def conc_unit
  @conc_unit
end

#concentrationObject (readonly)

Returns the value of attribute concentration



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def concentration
  @concentration
end

#daysObject (readonly)

Returns the value of attribute days



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def days
  @days
end

#doseObject (readonly)

Returns the value of attribute dose



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def dose
  @dose
end

#dose_unitObject

Returns the value of attribute dose_unit



9
10
11
# File 'lib/pueri/dosecalc.rb', line 9

def dose_unit
  @dose_unit
end

#nameObject (readonly)

Returns the value of attribute name



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def result
  @result
end

#timeObject (readonly)

Returns the value of attribute time



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def time
  @time
end

#weightObject (readonly)

Returns the value of attribute weight



8
9
10
# File 'lib/pueri/dosecalc.rb', line 8

def weight
  @weight
end

Instance Method Details

#to_fFloat

Outputs the calculated dosage for each taking. E.g. 3.7, as in _use 3.7 units of medication each time_.

Returns:

  • (Float)

    The dosage to be used each time one takes the medication.



48
49
50
# File 'lib/pueri/dosecalc.rb', line 48

def to_f
  @result
end

#to_s(pretty = false) ⇒ String

Outputs the calculated dosage into a prescription string.

Parameters:

  • pretty (Boolean) (defaults to: false)

    Whether to output a colored result or not.

Returns:

  • (String)

    The prescription string.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pueri/dosecalc.rb', line 32

def to_s(pretty = false)
  if pretty
    pretty_to_s
  else
    [
      '',
      "- #{@name} #{@concentration.to_i}#{@conc_unit.join '/'}",
      "Tomar #{@result}#{@conc_unit[1]} #{time_to_s} #{days_to_s}."
    ].join "\n"
  end
end