Class: Pueri::DoseCheck

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

Overview

Checks the prescription of a given medication given the weight of the pacient, the dose-per-take, 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) ⇒ DoseCheck

Calculate the dosage-per-weight-day for the prescribed medicine.

Parameters:

  • params (Hash)

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

    :weight

    The weight of the pacient, in kilograms.

    :dose

    The dose for the pacient, in any given unit.

    :time

    The time between takings, in hours.

    :concentration

    The posologic concentration, number only.

    :dose_unit

    The unit of medication for each taking (e.g. mL).

    :conc_unit

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

    :way

    The way of admnistration (e.g. IV, SC).

    :name

    The name of the medication.



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

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

Instance Attribute Details

#conc_unitObject

Returns the value of attribute conc_unit.



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

def conc_unit
  @conc_unit
end

#concentrationObject (readonly)

Returns the value of attribute concentration.



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

def concentration
  @concentration
end

#doseObject (readonly)

Returns the value of attribute dose.



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

def dose
  @dose
end

#dose_unitObject

Returns the value of attribute dose_unit.



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

def dose_unit
  @dose_unit
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end

#wayObject

Returns the value of attribute way.



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

def way
  @way
end

#weightObject (readonly)

Returns the value of attribute weight.



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

def weight
  @weight
end

Instance Method Details

#to_fFloat

Outputs the calculated dosage-per-weight-day as a float.

Returns:

  • (Float)

    The dosage prescribe as a float, without units.



47
48
49
# File 'lib/pueri/dosecheck.rb', line 47

def to_f
  @result
end

#to_s(pretty = false) ⇒ String

Outputs the calculated dosage as a string.

Parameters:

  • pretty (Boolean) (defaults to: false)

    Whether to output a colored result or not.

Returns:

  • (String)

    The dosage-per-weight-day string.



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

def to_s(pretty = false)
  if pretty
    pretty_to_s
  else
    [
      '',
      "#{@name} #{@concentration.to_i}#{@conc_unit.join '/'} (#{usage})",
      " - Dose de #{@result}#{@conc_unit[0]}/kg/d."
    ].join "\n"
  end
end