pueri 0.7.0 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Sat Oct 19 21:50:31 2019 by
103
+ Generated on Mon Oct 28 17:34:32 2019 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.20 (ruby-2.5.5).
106
106
  </div>
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pueri/age'
4
+ require 'pueri/dosecalc'
5
+ require 'pueri/dosecheck'
4
6
  require 'pueri/neuro'
5
7
  require 'pueri/vax'
6
8
  require 'pueri/version'
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pueri
4
+ # Calculates the prescription of a given medication given the weight of the
5
+ # pacient, the dose-per-weight-day, the concentration of the medication's
6
+ # presentation and the periodicity of takes in hours.
7
+ class DoseCalc
8
+ attr_reader :weight, :dose, :time, :days, :concentration, :result, :name
9
+ attr_accessor :dose_unit, :conc_unit
10
+
11
+ # Calculate the dosage for each taking of a given medicine.
12
+ #
13
+ # @param params [Hash] A Hash of elements, all of which are required to
14
+ # properly calculate and output the final dosage-per-taking:
15
+ # [+:weight+] The weight of the pacient, in _kilograms_.
16
+ # [+:dose+] The dose for the pacient, in _unit/kg/day_.
17
+ # [+:time+] The time between takings, in hours.
18
+ # [+:days+] The number of days to take the medication.
19
+ # [+:concentration+] The posologic concentration, number only.
20
+ # [+:dose_unit+] The unit of dosage for the pacient (_e.g._ mg/kg/d).
21
+ # [+:conc_unit+] The unit of concentration (_e.g._ mg/mL, mcg/pill).
22
+ # [+:name+] The name of the medication.
23
+ def initialize(params)
24
+ init_vars(params)
25
+ @result = ((@weight * @dose * @time) / (24.0 * @concentration)).round(3)
26
+ end
27
+
28
+ # Outputs the calculated dosage into a prescription string.
29
+ #
30
+ # @return [String] The prescription string.
31
+ def to_s
32
+ [
33
+ "- #{@name} #{@concentration.to_i}#{@conc_unit.join '/'}",
34
+ "Tomar #{@result}#{@conc_unit[1]} #{time_to_s} #{days_to_s}."
35
+ ].join "\n"
36
+ end
37
+
38
+ # Outputs the calculated dosage for each taking. _E.g._ +3.7+, as in _use
39
+ # 3.7 units of medication each time_.
40
+ #
41
+ # @return [Float] The dosage to be used each time one takes the medication.
42
+ def to_f
43
+ @result
44
+ end
45
+
46
+ private
47
+
48
+ def time_to_s
49
+ if @time == 24.0
50
+ 'uma vez por dia'
51
+ else
52
+ time = @time.to_i.to_s.rjust(2, '0')
53
+ hour = 'hora'
54
+ hour += 's' if @time > 1.0
55
+ "de #{time}/#{time} #{hour}"
56
+ end
57
+ end
58
+
59
+ def days_to_s
60
+ if @days == 1.0
61
+ str = 'por um dia'
62
+ str = 'em dose única' if @time == 24.0
63
+ str
64
+ else
65
+ days = @days.to_i.to_s.rjust(2, '0')
66
+ str = 'dia'
67
+ str += 's' if @days > 1.0
68
+ "por #{days} #{str}"
69
+ end
70
+ end
71
+
72
+ def init_vars(params)
73
+ check_vars(params)
74
+ init_calc_vars(params)
75
+ init_str_vars(params)
76
+ end
77
+
78
+ def check_vars(params)
79
+ params.each do |key, value|
80
+ if value.is_a? String
81
+ check_str_var(key, value)
82
+ elsif value.zero?
83
+ raise ArgumentError, "#{key} must not be zero"
84
+ end
85
+ end
86
+ end
87
+
88
+ def check_str_var(key, value)
89
+ raise ArgumentError, "#{key} must not be zero" if value.empty?
90
+
91
+ if key == :dose_unit
92
+ msg = "#{key} must follow unit/kg/d format"
93
+ raise ArgumentError, msg unless value.match? %r{^[A-Za-z]+\/kg\/d$}
94
+ elsif key == :conc_unit
95
+ msg = "#{key} must follow unit/presentation format"
96
+ raise ArgumentError, msg unless value.match? %r{^[A-Za-z]+\/[A-Za-z]+$}
97
+ end
98
+ end
99
+
100
+ def init_calc_vars(params)
101
+ @weight = params[:weight].to_f
102
+ @dose = params[:dose].to_f
103
+ @time = params[:time].to_f
104
+ @days = params[:days].to_i
105
+ @concentration = params[:concentration].to_f
106
+ end
107
+
108
+ def init_str_vars(params)
109
+ @dose_unit = params[:dose_unit].split '/'
110
+ @conc_unit = params[:conc_unit].split '/'
111
+ @name = params[:name].strip
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pueri
4
+ # Checks the prescription of a given medication given the weight of the
5
+ # pacient, the dose-per-take, the concentration of the medication's
6
+ # presentation and the periodicity of takes in hours.
7
+ class DoseCheck
8
+ attr_reader :weight, :dose, :time, :concentration, :result, :name
9
+ attr_accessor :dose_unit, :conc_unit, :way
10
+
11
+ # Calculate the dosage-per-weight-day for the prescribed medicine.
12
+ #
13
+ # @param params [Hash] A Hash of elements, all of which are required to
14
+ # properly calculate and output the final dosage-per-weight-day:
15
+ # [+:weight+] The weight of the pacient, in _kilograms_.
16
+ # [+:dose+] The dose for the pacient, in any given _unit_.
17
+ # [+:time+] The time between takings, in hours.
18
+ # [+:concentration+] The posologic concentration, number only.
19
+ # [+:dose_unit+] The unit of medication for each taking (_e.g._ mL).
20
+ # [+:conc_unit+] The unit of concentration (_e.g._ mg/mL, mcg/pill).
21
+ # [+:way+] The way of admnistration (_e.g._ IV, SC).
22
+ # [+:name+] The name of the medication.
23
+ def initialize(params)
24
+ init_vars(params)
25
+ @result = ((@dose * @concentration * 24.0) / (@time * @weight)).round(3)
26
+ end
27
+
28
+ # Outputs the calculated dosage as a string.
29
+ #
30
+ # @return [String] The dosage-per-weight-day string.
31
+ def to_s
32
+ [
33
+ "#{@name} #{@concentration.to_i}#{@conc_unit.join '/'} (#{usage})",
34
+ "-> Dose de #{@result}#{@conc_unit[0]}/kg/d."
35
+ ].join "\n"
36
+ end
37
+
38
+ # Outputs the calculated dosage-per-weight-day as a float.
39
+ #
40
+ # @return [Float] The dosage prescribe as a float, without units.
41
+ def to_f
42
+ @result
43
+ end
44
+
45
+ private
46
+
47
+ def usage
48
+ time = @time.to_i
49
+ "#{@dose}#{@dose_unit} #{@way} #{time}/#{time}h por #{@days.to_i}d"
50
+ end
51
+
52
+ def init_vars(params)
53
+ check_vars(params)
54
+ init_calc_vars(params)
55
+ init_str_vars(params)
56
+ end
57
+
58
+ def check_vars(params)
59
+ params.each do |key, value|
60
+ if value.is_a? String
61
+ check_str_var(key, value)
62
+ elsif value.zero?
63
+ raise ArgumentError, "#{key} must not be zero"
64
+ end
65
+ end
66
+ end
67
+
68
+ def check_str_var(key, value)
69
+ raise ArgumentError, "#{key} must not be zero" if value.empty?
70
+
71
+ if key == :dose_unit
72
+ msg = "#{key} must follow 'unit' format"
73
+ raise ArgumentError, msg unless value.match?(/^[A-Za-z]+$/)
74
+ elsif key == :conc_unit
75
+ msg = "#{key} must follow unit/presentation format"
76
+ raise ArgumentError, msg unless value.match? %r{^[A-Za-z]+\/[A-Za-z]+$}
77
+ end
78
+ end
79
+
80
+ def init_calc_vars(params)
81
+ @weight = params[:weight].to_f
82
+ @dose = params[:dose].to_f
83
+ @time = params[:time].to_f
84
+ @days = params[:days].to_i
85
+ @concentration = params[:concentration].to_f
86
+ end
87
+
88
+ def init_str_vars(params)
89
+ @dose_unit = params[:dose_unit].strip
90
+ @conc_unit = params[:conc_unit].split '/'
91
+ @name = params[:name].strip
92
+ @way = params[:way].strip
93
+ end
94
+ end
95
+ end
@@ -6,7 +6,7 @@
6
6
  # of Immunization (PNI), using the 2019 uptade.
7
7
  module Pueri
8
8
  # Sets the current version of the gem
9
- @version = '0.7.0'
9
+ @version = '0.11.2'
10
10
 
11
11
  # Returns the Gem's current version.
12
12
  #
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "Pueri",
3
3
  "description": "Um script em Ruby para ajudar o dia-a-dia de médicos e enfermeiros de Atenção Básica.",
4
- "version": "0.7.0",
4
+ "version": "0.11.2",
5
5
  "maintainers": [
6
6
  {
7
7
  "name": "Igor Padoim",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pueri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Padoim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-20 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,10 +93,12 @@ files:
93
93
  - ".github/ISSUE_TEMPLATE/user_question.md"
94
94
  - ".github/PULL_REQUEST_TEMPLATE.md"
95
95
  - ".github/config.yml"
96
+ - ".github/workflows/ruby.yml"
96
97
  - ".gitignore"
97
98
  - ".rspec"
98
99
  - ".rubocop.yml"
99
100
  - ".travis.yml"
101
+ - ABOUT.md
100
102
  - CHANGELOG.md
101
103
  - CODE-OF-CONDUCT.md
102
104
  - CONTRIBUTING.md
@@ -109,6 +111,8 @@ files:
109
111
  - bin/setup
110
112
  - docs/Pueri.html
111
113
  - docs/Pueri/Age.html
114
+ - docs/Pueri/DoseCalc.html
115
+ - docs/Pueri/DoseCheck.html
112
116
  - docs/Pueri/Neuro.html
113
117
  - docs/Pueri/Vax.html
114
118
  - docs/_index.html
@@ -127,6 +131,8 @@ files:
127
131
  - docs/top-level-namespace.html
128
132
  - lib/pueri.rb
129
133
  - lib/pueri/age.rb
134
+ - lib/pueri/dosecalc.rb
135
+ - lib/pueri/dosecheck.rb
130
136
  - lib/pueri/neuro.rb
131
137
  - lib/pueri/vax.rb
132
138
  - lib/pueri/version.rb