kimaya 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 989ead6774c2f01563f22f603827b94874812ddc
4
+ data.tar.gz: 241e000085d2c3ba3df6bdb36cdd280e3e06d16f
5
+ SHA512:
6
+ metadata.gz: d442a1a49b7b98c34a9331a1ac6a2d0011fe64c672ed4d6adf713a727a8306ed3451bca1efb4d356ec08d91332376b7eda0111c3c07f73535e8f32041dbe4440
7
+ data.tar.gz: 4f8cf8ed8f07c8a3506a5829bb7b50119a3b682cfe9f255d8c506962fa4de8209ea4d670c712e7a457c7bb775dd4bb37b81677a080479fb83f6f8fccf8b9e3e3
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kimaya (0.0.6)
5
+ activemodel
6
+ activesupport
7
+ i18n
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activemodel (4.0.4)
13
+ activesupport (= 4.0.4)
14
+ builder (~> 3.1.0)
15
+ activesupport (4.0.4)
16
+ i18n (~> 0.6, >= 0.6.9)
17
+ minitest (~> 4.2)
18
+ multi_json (~> 1.3)
19
+ thread_safe (~> 0.1)
20
+ tzinfo (~> 0.3.37)
21
+ builder (3.1.4)
22
+ columnize (0.3.6)
23
+ debugger (1.6.5)
24
+ columnize (>= 0.3.1)
25
+ debugger-linecache (~> 1.2.0)
26
+ debugger-ruby_core_source (~> 1.3.1)
27
+ debugger-linecache (1.2.0)
28
+ debugger-ruby_core_source (1.3.1)
29
+ diff-lcs (1.1.3)
30
+ i18n (0.6.9)
31
+ minitest (4.7.5)
32
+ multi_json (1.9.2)
33
+ rspec (2.11.0)
34
+ rspec-core (~> 2.11.0)
35
+ rspec-expectations (~> 2.11.0)
36
+ rspec-mocks (~> 2.11.0)
37
+ rspec-core (2.11.1)
38
+ rspec-expectations (2.11.3)
39
+ diff-lcs (~> 1.1.3)
40
+ rspec-mocks (2.11.3)
41
+ thread_safe (0.3.3)
42
+ tzinfo (0.3.39)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ debugger
49
+ kimaya!
50
+ rspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kimaya/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "kimaya"
7
+ s.version = Kimaya::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Shailesh Patil"]
10
+ s.email = ["shailesh@joshsoftware.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Core calculations for TPN}
13
+ s.description = %q{Core calculations for TPN}
14
+
15
+ s.rubyforge_project = "kimaya"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "activesupport"
23
+ s.add_dependency "activemodel"
24
+ s.add_dependency "i18n"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "debugger"
27
+ end
@@ -0,0 +1,2 @@
1
+ Kimaya initializer to copy some configuration values, just do:
2
+ rails generate kimaya:install
@@ -0,0 +1,12 @@
1
+ module Kimaya
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Copy Kimaya default files"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_config
8
+ directory 'config/locales'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,195 @@
1
+ en:
2
+ activemodel:
3
+ errors:
4
+ models:
5
+ kimaya:
6
+ tpn_calc:
7
+ attributes:
8
+ day_of_tpn:
9
+ day_of_tpn_blank: "You have entered an invalid value for Day of TPN, please enter the correct value."
10
+ current_weight:
11
+ blank: "You have entered an invalid value for Current Weight, please enter the correct value."
12
+ messages:
13
+ dextrose_conc:
14
+ message: "You have entered an invalid value for Dextrose Concentration, please enter the correct value."
15
+ comment: "invalidPercentDextroseConcentration"
16
+ "1003":
17
+ message: "You have entered an invalid value for Current Weight, please enter the correct value."
18
+ comment: "invalidCurrentWeight"
19
+ "1004":
20
+ message: "You have entered an invalid value for Fluid Intake.The Recommended range is between 40 to 250 ml/kg/day."
21
+ comment: "invalidTotalFluidIntake"
22
+ "1005":
23
+ message: "You have entered an invalid value for Fluid Intake / Current Weight, please enter the correct value(s)."
24
+ comment: "invalidTotalFluidIntakeVolume"
25
+ "1006":
26
+ message: "You have entered an invalid value for Feed Volume, please enter the correct value."
27
+ comment: "invalidFeedVolume"
28
+ "1007":
29
+ message: "You have entered an invalid value for Losses, please enter the correct value."
30
+ comment: "invalidLosses"
31
+ "1008":
32
+ message: "You have entered an invalid value for Fluid Intake / Current Weight / Feed Volume / Losses, please enter the correct value(s)."
33
+ comment: "invalidTPNVolume"
34
+ "1009":
35
+ message: "You have entered an invalid value for FAT Volume Intake, please enter the correct value."
36
+ comment: "invalidFATVolumeIntake"
37
+ "1010":
38
+ message: "You have not selected a value for Lipid Concentration, please select the value."
39
+ comment: "invalidLipidConcentration"
40
+ "1011":
41
+ message: "You have entered an invalid value for FAT Volume Intake, please enter the correct value."
42
+ comment: "invalidFATVolume"
43
+ "1012":
44
+ message: "You have entered an invalid value for Fluid Intake / Current Weight / Feed Volume / Losses / FAT Volume Intake, please enter the correct value(s)."
45
+ comment: "invalidHAVSolution"
46
+ "1013":
47
+ message: "You have entered an invalid value for Overfill Factor, please enter the correct value."
48
+ comment: "invalidOverfillFactor"
49
+ "1014":
50
+ message: "You have entered an invalid value for Fluid Intake / Current Weight / Feed Volume / Losses / FAT Volume Intake / Overfill Factor, please enter the correct value(s)."
51
+ comment: "invalidPreparedOverfill"
52
+ "1015":
53
+ message: "You have entered an invalid value for Amino Acid, please enter the correct value."
54
+ comment: "invalidAminoAcidIntake"
55
+ "1016":
56
+ message: "You have selected an invalid value for Amino Acid Concentration, please select the correct value."
57
+ comment: "invalidAminoAcidConcentration"
58
+ "1017":
59
+ message: "You have entered an invalid value for Amino Acid / Current Weight / Overfill Factor, please enter the correct value(s)."
60
+ comment: "invalidAminoAcid"
61
+ "1018":
62
+ message: "You have entered an invalid value for Sodium Chloride, please enter the correct value."
63
+ comment: "invalidSodiumChlorideIntake"
64
+ "1019":
65
+ message: "You have selected an invalid value for Sodium Chloride Concentration, please select the correct value."
66
+ comment: "invalidSodiumChlorideConcentration"
67
+ "1020":
68
+ message: "You have entered an invalid value for Sodium Chloride / Current Weight / Overfill Factor, please enter the correct value(s)."
69
+ comment: "invalidSodiumChloride"
70
+ "1021":
71
+ message: "You have entered an invalid value for Potassium Chloride, please enter the correct value."
72
+ comment: "invalidPotassiumChlorideIntake"
73
+ "1022":
74
+ message: "You have selected an invalid value for Potassium Chloride Concentration, please select the correct value."
75
+ comment: "invalidPotassiumChlorideConcentration"
76
+ "1023":
77
+ message: "You have entered an invalid value for Potassium Chloride / Current Weight / Overfill Factor, please enter the correct value(s)."
78
+ comment: "invalidPotassiumChloride"
79
+ "1024":
80
+ message: "You have entered an invalid value for Calcium, please enter the correct value."
81
+ comment: "invalidCalciumIntake"
82
+ "1025":
83
+ message: "You have selected an invalid value for Calcium Concentration, please select the correct value."
84
+ comment: "invalidCalciumConcentration"
85
+ "1026":
86
+ message: "You have entered an invalid value for Calcium / Current Weight / Overfill Factor, please enter the correct value(s)."
87
+ comment: "invalidCalcium"
88
+ "1027":
89
+ message: "You have entered an invalid value for Magnesium, please enter the correct value."
90
+ comment: "invalidMagnesiumIntake"
91
+ "1028":
92
+ message: "You have selected an invalid value for Magnesium Concentration, please select the correct value."
93
+ comment: "invalidMagnesiumConcentration"
94
+ "1029":
95
+ message: "You have entered an invalid value for Magnesium / Current Weight / Overfill Factor, please enter the correct value(s)."
96
+ comment: "invalidMagnesium"
97
+ "1033":
98
+ message: "Fluid Intake is too less (%{fluid_intake}) or Sum of Additives is too high (%{additives} ml)"
99
+ comment:
100
+ "1037":
101
+ message: "CNR is Out of Range.The Recommended value is above 150. Do you want to continue?"
102
+ comment: "invalidCNRRate"
103
+ "1040":
104
+ message: "The Dextrose Infusion Rate should always be less than 12mg/kg/min. Do you want to continue?"
105
+ comment: "invalidDIRRate"
106
+ "1043":
107
+ message: "Patient not selected. Please select a patient from the patients list."
108
+ comment: "patientNotSelected"
109
+ "1501":
110
+ message: "Fluid Intake is Out of Range. The Recommended range is between 100 to 120 ml/kg/day. Do you want to continue?"
111
+ comment: "totalFluidIntakeOutOfRangeLessthan10"
112
+ "1502":
113
+ message: "Fluid Intake is Out of Range. The Recommended range is between 60 to 90 ml/kg/day. Do you want to continue?"
114
+ comment: "totalFluidIntakeOutOfRangeMorethan10"
115
+ "1503":
116
+ message: "Fluid Intake is Out of Range. The Recommended range is between 40 to 90 ml/kg/day. Do you want to continue?"
117
+ comment: "totalFluidIntakeOutOfRangeMorethan30"
118
+ "1504":
119
+ message: "Sum of Additive Nutrients are 0.Do you want to continue?"
120
+ comment: "totalAdditiveNutrients"
121
+ "1505":
122
+ message: "The dextrose concentration is not achievable. Please change the dextrose concentration/DIR and try again."
123
+ comment: "invalidDextroseConcentration"
124
+
125
+ help:
126
+ "101":
127
+ message: "It will display the registration number of the patient which you will select from next drop down list."
128
+ "102":
129
+ message: "A new TPN calculation can be made for the selected patient. The latest TPN values (if available) will be shown for the selected patient."
130
+ "103":
131
+ message: "Click the link to view the selected patient's details."
132
+ "104":
133
+ message: "Enter the day of TPN. The day of initiation of TPN is taken as day 1. Subsequent days are counted from this day onwards."
134
+ "105":
135
+ message: "Enter the current body weight of the infant in kg. If the current weight is less than the birth weight, then the birth weight will be taken for calculation."
136
+ "106":
137
+ message: "Enter the expected dextrose concentration(%). Generally, 10% dextrose solution is prepared for administration. However, individual changes are necessary depending on the patient's tolerance. It is recommended that solutions with a dextrose concentration greater than 12.5% be administered through central line. The normal range for Dextrose Concentration of a solution is 5 - 20 %."
138
+ "107":
139
+ message: "Enter the total fluid intake as per patients age and clinical condition. Fluid intake is the total amount of fluid that a patient should receive throughout the day. It includes enteral as well as parenteral fluid volumes. It is expressed in ml/kg/day. It should be decided as per the patient's age and clinical condition. The range for fluid intake is as follows - "
140
+ "108":
141
+ message: "Enter the enteral feed volume intake. This includes all oral as well as Nasogastric Tube i.e., NGT feed administered to the patient and it is expressed in ml/day."
142
+ "109":
143
+ message: "Enter the surgical losses. These losses include nasogastric aspirates, losses through drains or shunts, etc. and it is expressed in ml/day."
144
+ "110":
145
+ message: "Enter the fat requirement. The broad range of the fat requirement for infants and children is 0 - 4gm/kg/day. Generally fat is initiated at 0.5-1gm/kg/day and it is graded up gradually by 0.5gm/kg/day to a maximum of 3.0-4.0gm/kg/day as per tolerance. In certain clinical conditions, administration of fats may be contraindicated. It is advised that you go through standard medical literature before you prescribe fat to the patient."
146
+ "111":
147
+ message: "Select lipid concentration (%). Lipid concentration indicates the concentration of the fat or lipid emulsion. Fat emulsions are available as 10% and 20%. It is recommended that for VLBW and ELBW infants, the 20% emulsion be used as it has less phospholipid to triglyceride ratio."
148
+ "112":
149
+ message: "Enter the Overfill Factor for the solution. Overfill factor is a factor that accounts for the losses of fluid that occurs due to wastage during administration. This is usually the fluid that is left behind in IV bottles, tubings and extension sets. This volume is generally 20% therefore overfill factor is taken as 1.2. However, it may be modified depending on individual prepared volume (1.3 for smaller volumes and 1.1 for larger volumes) "
150
+ "113":
151
+ message: "The normal range for amino acid intake by infants and children is 0.5 - 3.5gm/kg/day. Amino acids are generally introduced at 0.5 - 1gm/kg/day and it is graded up by 0.5 - 1gm/kg/day as warranted by the clinical condition. Standard medical literature should be referred to before deciding the amino acid requirement of the patient. Providing protein in excess of the need may result in hyperammonemia, metabolic acidosis and elevated BUN concentrations and may increase the risk of cholestasis."
152
+ "114":
153
+ message: "Click to select the Marketing Additive for Amino Acid."
154
+ "115":
155
+ message: "Displays the selected Amino Acid concentration, clik on the button on the left side of this control to select available Amino Acid concentration."
156
+ "116":
157
+ message: "The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion. Click on the button to the right to select one of the available Sodium Chloride solutions. Sodium Chloride must be between"
158
+ "117":
159
+ message: "Click to select Marketing Additive for Sodium Chloride."
160
+ "118":
161
+ message: "Displays the selected Sodium Chloride Marketing Additive constant, clik on the button on the left side of this control to select available Sodium Chloride Marketing Additive constant."
162
+ "119":
163
+ message: "The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion. Click on the button to the right to select one of the available Potassium Chloride solutions. Potassium Chloride must be between "
164
+ "120":
165
+ message: "Click to select required Marketing Additive constant for Potassium Chloride."
166
+ "121":
167
+ message: "Displays the selected Potassium Chloride Marketing Additive constant, clik on the button on the left side of this control to select available Potassium Chloride Marketing Additive constant. The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion."
168
+ "122":
169
+ message: "The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion. Click on the button to the right to select one of the available Calcium solutions. Calcium must be between"
170
+ "123":
171
+ message: "Click to select required Marketing Additive constant for Calcium."
172
+ "124":
173
+ message: "Displays the selected Calcium Marketing Additive constant, clik on the button on the left side of this control to select available Calcium Marketing Additive constant. The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion."
174
+ "125":
175
+ message: "The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion. Click on the button to the right to select one of the available Magnesium solutions. Magnesium must be between"
176
+ "126":
177
+ message: "Click to select required Marketing Additive constant for Magnesium."
178
+ "127":
179
+ message: "Displays the selected Magnesium Marketing Additive constant, clik on the button on the left side of this control to select available Magnesium Marketing Additive constant. The dose should be decided based on daily requirements, serum electrolyte values and clinical discretion."
180
+ "128":
181
+ message: "This is help window which provides the help about the TPN Calculations."
182
+ "129":
183
+ message: "It will generate the TPN Calculation Report."
184
+ "130":
185
+ message: "You will lose all the information entered."
186
+ "131":
187
+ message: "Administration chosen as Peripheral Line."
188
+ "132":
189
+ message: "Administration chosen as Central Line."
190
+ "133":
191
+ message: "Enter the Intake values for the Additives."
192
+ "134":
193
+ message: "To get correct range of CNR decrease the amount of Amino acid given to the patient"
194
+ "135":
195
+ message : "To get correct range of DIR decrease the amount of Fluid Intake."
@@ -0,0 +1,4 @@
1
+ require 'active_support'
2
+ require 'active_model'
3
+ require File.dirname(__FILE__) + '/kimaya/kimaya_core.rb'
4
+ require File.dirname(__FILE__) + '/kimaya/kimaya.rb'
@@ -0,0 +1,176 @@
1
+ module Kimaya
2
+ class TPNCalc
3
+ include KimayaCore
4
+
5
+ MAX_DIR = 12.0
6
+ MIN_CNR = 150.0
7
+
8
+ CONCENTRATIONS = {dextrose_5: 20, dextrose_10: 10, dextrose_25: 4, dextrose_50: 2}
9
+
10
+ def initialize(options= {}, &block)
11
+ yield self if block_given?
12
+
13
+ @day_of_tpn ||= initialize_key(options, :day_of_tpn, 1, 1)
14
+ @current_weight ||= initialize_key(options, :current_weight, 2)
15
+ @percent_dextrose_conc ||= initialize_key(options, :percent_dextrose_conc, 4, 0.1)
16
+ @total_fluid_intake ||= initialize_key(options, :total_fluid_intake, 2, 0)
17
+ @losses ||= initialize_key(options, :losses, 2)
18
+ @fat_intake ||= initialize_key(options, :fat_intake, 2, 0)
19
+ @lipid_conc ||= initialize_key(options, :lipid_conc, 2, 0.1)
20
+ @overfill_factor ||= initialize_key(options, :overfill_factor, 2, 1.0)
21
+ @amino_acid_intake ||= initialize_key(options, :amino_acid_intake, 3)
22
+ @amino_acid_conc ||= initialize_key(options, :amino_acid_conc, 3)
23
+ @sodium_chloride_intake ||= initialize_key(options, :sodium_chloride_intake, 3, 0)
24
+ @sodium_chloride_conc ||= initialize_key(options, :sodium_chloride_conc, 3, 1)
25
+ @potassium_chloride_intake ||= initialize_key(options, :potassium_chloride_intake, 3, 0)
26
+ @potassium_chloride_conc ||= initialize_key(options, :potassium_chloride_conc, 3, 1)
27
+ @magnesium_intake ||= initialize_key(options, :magnesium_intake, 3, 0)
28
+ @magnesium_conc ||= initialize_key(options, :magnesium_conc, 3, 1)
29
+ @calcium_intake ||= initialize_key(options, :calcium_intake, 3, 0)
30
+ @calcium_conc ||= initialize_key(options, :calcium_conc, 3, 1)
31
+ @expected_dir ||= initialize_key(options, :expected_dir, 1, 0.0)
32
+ @other_infusions ||= initialize_key(options, :other_infusions, 2, 0.0)
33
+ @administration ||= options.has_key?(:administration) ? options.fetch(:administration) : "Peripheral Line"
34
+ @available_dextrose_concentrations ||= options.has_key?(:available_dextrose_concentrations) ? options.fetch(:available_dextrose_concentrations) : [:dextrose_50, :dextrose_10]
35
+ @feed_vol = 0
36
+ @losses = 0
37
+ @errors = []
38
+ @warnings = []
39
+ @dextrose_concentrations = {}
40
+ @exceptions = []
41
+ end
42
+
43
+ def calculate_tpn
44
+ calculate_volumes
45
+ calculate_additives
46
+ calculate_dextrose_concentration_achieved
47
+ calculate_calories
48
+ validate_results
49
+ end
50
+
51
+ private
52
+
53
+ def calculate_volumes
54
+ @other_infusions = round(other_infusions * 24, 2)
55
+ @total_fluid_intake_vol = round(total_fluid_intake * current_weight, 2)
56
+ @tpn_vol = round(total_fluid_intake_vol - feed_vol + losses, 2)
57
+ @fat_vol = round(fat_intake * current_weight / lipid_conc, 2)
58
+ @hav_vol = round(tpn_vol - fat_vol - other_infusions, 2)
59
+ @prepared_overfill = round(hav_vol * overfill_factor, 1)
60
+ end
61
+
62
+ def calculate_additives
63
+ @amino_acid_vol = volume(amino_acid_intake, amino_acid_conc)
64
+ @sodium_chloride_vol = volume(sodium_chloride_intake, sodium_chloride_conc)
65
+ @potassium_chloride_vol = volume(potassium_chloride_intake, potassium_chloride_conc)
66
+ @calcium_vol = volume(calcium_intake, calcium_conc)
67
+ @magnesium_vol = volume(magnesium_intake, magnesium_conc)
68
+ @mvi = round(round(1 * current_weight, 2) * overfill_factor, 2)
69
+ @remaining_dextrose_vol = round(prepared_overfill - total_additives, 2)
70
+ end
71
+
72
+ def calculate_calories
73
+ @fat_calories = round(fat_vol * 2, 2)
74
+ #@cho_calories = round(hav_vol * percent_dextrose_conc * 3.4, 2)
75
+ tmp_calories = (@dextrose_concentrations[@available_dextrose_concentrations[0]] / CONCENTRATIONS[@available_dextrose_concentrations[0]]) + (@dextrose_concentrations[@available_dextrose_concentrations[1]] / CONCENTRATIONS[@available_dextrose_concentrations[1]])
76
+ @cho_calories = round(tmp_calories * 3.4, 2)
77
+
78
+ tempAminoAcid = amino_acid_vol / overfill_factor
79
+ @cnr_rate = round((fat_calories + cho_calories) / ((amino_acid_intake * current_weight) / 6.25), 2)
80
+ @calories = round(fat_calories + cho_calories + (tempAminoAcid * amino_acid_conc * 4.0), 2)
81
+ @non_protein = round(calories - (tempAminoAcid * amino_acid_conc * 4.0), 2)
82
+ @total_protein= round(amino_acid_intake * current_weight, 2)
83
+ end
84
+
85
+ def calculate_dextrose_concentration_achieved
86
+ calculate_percent_dextrose_conc
87
+ remain_volume = remaining_dextrose_vol
88
+ overfill = prepared_overfill
89
+ dextrose_concentration = @percent_dextrose_conc
90
+ wanted_dextrose_vol = overfill
91
+ achieved_dextrose_concentration = 0.0
92
+ old_val = 1.0
93
+ old_dextrose_1 = dextrose_1 = 1.0
94
+ @available_dextrose_concentrations = [:dextrose_25, :dextrose_5] if dextrose_concentration < 0.1 && !@available_dextrose_concentrations.include?(:dextrose_5)
95
+
96
+ dextrose_conc_1, dextrose_conc_2 = @available_dextrose_concentrations
97
+ while achieved_dextrose_concentration < dextrose_concentration do
98
+ old_val = achieved_dextrose_concentration
99
+ old_dextrose_1 = dextrose_concentration < 0.05 ? 0 : dextrose_1
100
+ dextrose_2 = remain_volume - dextrose_1
101
+ @errors << "1033" if (dextrose_1 < 0 || dextrose_2 < 0)
102
+ dextrose_1 = dextrose_1 / CONCENTRATIONS[dextrose_conc_1]
103
+ dextrose_2 = dextrose_2 / CONCENTRATIONS[dextrose_conc_2]
104
+ achieved_dextrose_concentration = (dextrose_1 + dextrose_2) * dextrose_concentration / (dextrose_concentration * overfill)
105
+ if achieved_dextrose_concentration > dextrose_concentration
106
+ old_val = achieved_dextrose_concentration
107
+ else
108
+ dextrose_1 = old_dextrose_1 + 1
109
+ end
110
+ end
111
+ @dextrose_concentrations[dextrose_conc_1] = round(old_dextrose_1, 1)
112
+ @dextrose_concentrations[dextrose_conc_2] = round(remain_volume - @dextrose_concentrations[dextrose_conc_1], 1)
113
+ @achieved_dextrose_conc = round(old_val * 100, 1)
114
+ @remaining_dextrose_vol = round(@remaining_dextrose_vol, 2)
115
+ rescue SystemStackError => e
116
+ @exceptions << {message: e.message, backtrace: e.backtrace}
117
+ rescue => e
118
+ @exceptions << {message: e.message, backtrace: e.backtrace}
119
+ end
120
+
121
+ def validate_results
122
+ @errors << "1017" if @amino_acid_vol.nil?
123
+ @warnings << "1037" if @cnr_rate.nil? || @cnr_rate <= MIN_CNR
124
+ @warnings << "1040" if @dir_rate.nil? || @dir_rate > MAX_DIR
125
+ @errors << "1505" if @achieved_dextrose_conc == 0.0
126
+
127
+ self.instance_variables.each do |variable|
128
+ val = self.instance_variable_get(variable)
129
+ variable = variable.to_s.gsub('@', '').to_sym
130
+ @errors << KimayaCore::ERROR_CODES[variable] if (val.is_a?(Fixnum) || val.is_a?(Float)) && val < 0
131
+ end
132
+
133
+ @errors.uniq!
134
+ @errors.empty? || @warnings.empty?
135
+ end
136
+
137
+
138
+ def volume(intake, conc)
139
+ round(intake * @current_weight * @overfill_factor / conc, 2)
140
+ end
141
+
142
+ def total_additives
143
+ @heparin = administration == "Central Line" ? round(prepared_overfill / 1000, 2) : 0
144
+ amino_acid_vol + sodium_chloride_vol + potassium_chloride_vol + calcium_vol + magnesium_vol + mvi + heparin
145
+ end
146
+
147
+ def initialize_key(options, key, scale, default_value = nil)
148
+ options.has_key?(key) ? round(options.fetch(key), scale) : default_value
149
+ end
150
+
151
+ def calculate_percent_dextrose_conc
152
+ @dir_rate = round(((hav_vol * @percent_dextrose_conc) / (24 * 60 * current_weight)) * 1000, 1)
153
+ return if hav_vol == 0
154
+
155
+ operator = :- if @dir_rate < 0
156
+ if @expected_dir > 0.0
157
+ value = ((@dir_rate - @expected_dir).abs > 3) ? 0.01 : 0.001
158
+ if @dir_rate < @expected_dir
159
+ # if dir_rate is less than expected dir then increase percent_dextrose_conc
160
+ recalculate_dir(@percent_dextrose_conc, operator || :+, value)
161
+ elsif @dir_rate > @expected_dir
162
+ # if dir_rate is more than expected dir then decrease percent_dextrose_conc
163
+ recalculate_dir(@percent_dextrose_conc, operator || :-, value)
164
+ end
165
+ end
166
+ end
167
+
168
+ def recalculate_dir(percent_dextrose_conc, operator, value)
169
+ return if @dir_rate == @expected_dir
170
+ @percent_dextrose_conc = round([percent_dextrose_conc, value].reduce(operator),4)
171
+ @dir_rate = round(((hav_vol * @percent_dextrose_conc) / (24 * 60 * current_weight)) * 1000, 1)
172
+ value = ((@dir_rate - @expected_dir).abs > 3) ? 0.01 : 0.001
173
+ recalculate_dir(@percent_dextrose_conc, operator, value)
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,32 @@
1
+ module Kimaya
2
+ module KimayaCore
3
+ attr_accessor :day_of_tpn, :current_weight,
4
+ :percent_dextrose_conc, :total_fluid_intake, :total_fluid_intake_vol, :feed_vol,
5
+ :losses, :tpn_vol, :fat_intake, :fat_vol, :lipid_conc, :hav_vol,
6
+ :overfill_factor, :prepared_overfill,
7
+ :amino_acid_intake, :amino_acid_conc, :amino_acid_vol,
8
+ :sodium_chloride_intake, :sodium_chloride_conc, :sodium_chloride_vol,
9
+ :potassium_chloride_intake, :potassium_chloride_conc, :potassium_chloride_vol,
10
+ :calcium_intake, :calcium_conc, :calcium_vol,
11
+ :magnesium_intake, :magnesium_conc, :magnesium_vol,
12
+ :mvi, :remaining_dextrose_vol, :achieved_dextrose_conc, :fat_calories,
13
+ :cho_calories, :cnr_rate, :calories, :total_protein,:dir_rate, :dextrose_concentrations, :water, :heparin, :administration, :non_protein, :expected_dir, :available_dextrose_concentrations, :other_infusions
14
+
15
+ attr_accessor :errors, :warnings, :exceptions
16
+ def round(value, scale)
17
+ ("%.#{scale}f" % value).to_f
18
+ end
19
+
20
+ ERROR_CODES = {
21
+ percent_dextrose_conc: "1002", current_weight: "1003", total_fluid_intake: "1004", total_fluid_intake_vol: "1005",
22
+ feed_vol: "1006", losses: "1007", tpn_vol: "1008", fat_intake: "1009", fat_vol: "1011", lipid_conc: "1010",
23
+ hav_vol: "1012", overfill_factor: "1013", prepared_overfill: "1014", amino_acid_intake: "1015", amino_acid_conc: "1016",
24
+ amino_acid_vol: "1017", sodium_chloride_intake: "1018", sodium_chloride_conc: "1019", sodium_chloride_vol: "1020",
25
+ potassium_chloride_intake: "1021", potassium_chloride_conc: "1022", potassium_chloride_vol: "1023", calcium_intake: "1024",
26
+ calcium_conc: "1025", calcium_vol: "1026", magnesium_intake: "1027", magnesium_conc: "1028", magnesium_vol: "1029",
27
+ mvi: "1032", remaining_dextrose_vol: "1033", achieved_dextrose_conc: "1034", fat_calories: "1035", cho_calories: "1036",
28
+ cnr_rate: "1037", calories: "1039", dir_rate: "1040", dextrose_10: "1041", dextrose_50: "1042", heparin: "1044"
29
+ }
30
+ end
31
+ end
32
+
@@ -0,0 +1,3 @@
1
+ module Kimaya
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,254 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'spec_helper'
3
+
4
+ module Kimaya
5
+
6
+ describe TPNCalc do
7
+
8
+ describe "Calculate with default values" do
9
+ def build_tpn(params = {})
10
+ @tpn = Kimaya::TPNCalc.new(params)
11
+ end
12
+
13
+ def match_results(results = {})
14
+ results.keys.each do |key|
15
+ @tpn.send(key).should eq(results[key])
16
+ end
17
+ end
18
+
19
+ it "test latest test and test" do
20
+ build_tpn({current_weight: 1.2, percent_dextrose_conc: 0.1, total_fluid_intake: 125, fat_intake: 0.5,
21
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05, other_infusions: 2})
22
+ @tpn.calculate_tpn
23
+
24
+ @tpn.errors.empty?.should == true
25
+ match_results({current_weight: 1.2, percent_dextrose_conc: 0.1, total_fluid_intake: 125, fat_intake: 0.5,
26
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
27
+ total_fluid_intake_vol: 150.0, tpn_vol: 150.0, fat_vol: 6.0, hav_vol: 96.0, prepared_overfill: 115.2,
28
+ amino_acid_vol: 14.4, sodium_chloride_vol: 0.0, potassium_chloride_vol: 0.0, calcium_vol: 0.0, magnesium_vol: 0.0,
29
+ mvi: 0.6, heparin: 0, remaining_dextrose_vol: 100.2, dextrose_concentrations: {dextrose_10: 96.2, dextrose_50: 4.0},
30
+ achieved_dextrose_conc: 9.7, fat_calories: 5.4, cho_calories: 39.51, cnr_rate: 467.81, non_protein: 44.91,
31
+ total_protein: 0.6, dir_rate: 5.6})
32
+ end
33
+
34
+ it "test Zoting preeti santosh" do
35
+ build_tpn({current_weight: 0.82, percent_dextrose_conc: 0.1, total_fluid_intake: 170, overfill_factor: 1.2,
36
+ amino_acid_intake: 1.5, amino_acid_conc: 0.1, sodium_chloride_intake: 5, sodium_chloride_conc: 3.3,
37
+ potassium_chloride_intake: 2, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
38
+ magnesium_intake:0.3, magnesium_conc: 4, administration: "Central Line"})
39
+ @tpn.calculate_tpn
40
+ @tpn.errors.empty?.should == true
41
+ match_results({current_weight: 0.82, percent_dextrose_conc: 0.1, total_fluid_intake: 170, overfill_factor: 1.2,
42
+ amino_acid_intake: 1.5, amino_acid_conc: 0.1, sodium_chloride_intake: 5, sodium_chloride_conc: 3.3,
43
+ potassium_chloride_intake: 2, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
44
+ magnesium_intake:0.3, magnesium_conc: 4, administration: "Central Line",
45
+ total_fluid_intake_vol: 139.4, tpn_vol: 139.4, fat_vol: 0.0, hav_vol: 139.4, prepared_overfill: 167.3,
46
+ amino_acid_vol: 14.76, sodium_chloride_vol: 1.49, potassium_chloride_vol: 0.98, calcium_vol: 4.37, magnesium_vol: 0.07,
47
+ mvi: 0.41, heparin: 0.17, remaining_dextrose_vol: 145.05, dextrose_concentrations: {dextrose_10: 139.1, dextrose_50: 6.0},
48
+ achieved_dextrose_conc: 9.9, fat_calories: 0.0, cho_calories: 57.49, cnr_rate: 292.12, non_protein: 57.49,
49
+ total_protein: 1.23, dir_rate: 11.8})
50
+ end
51
+
52
+ it "test Langole Sunita" do
53
+ build_tpn({current_weight: 1.36, percent_dextrose_conc: 0.1, total_fluid_intake: 150, fat_intake: 2.0, lipid_conc: 0.2,
54
+ overfill_factor: 1.2, amino_acid_intake: 2.7, amino_acid_conc: 0.1, sodium_chloride_intake: 3, sodium_chloride_conc: 3.3,
55
+ potassium_chloride_intake: 2, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
56
+ magnesium_intake:0.3, magnesium_conc: 4, administration: "Central Line"})
57
+ @tpn.calculate_tpn
58
+ @tpn.errors.empty?.should == true
59
+ match_results({current_weight: 1.36, percent_dextrose_conc: 0.1, total_fluid_intake: 150, fat_intake: 2.0, lipid_conc: 0.2,
60
+ overfill_factor: 1.2, amino_acid_intake: 2.7, amino_acid_conc: 0.1, sodium_chloride_intake: 3, sodium_chloride_conc: 3.3,
61
+ potassium_chloride_intake: 2, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
62
+ magnesium_intake:0.3, magnesium_conc: 4, administration: "Central Line",
63
+ total_fluid_intake_vol: 204.0, tpn_vol: 204.0, fat_vol: 13.6, hav_vol: 190.4, prepared_overfill: 228.5,
64
+ amino_acid_vol: 44.06, sodium_chloride_vol: 1.48, potassium_chloride_vol: 1.63, calcium_vol: 7.25, magnesium_vol: 0.12,
65
+ mvi: 0.68, heparin: 0.23, dextrose_concentrations: {dextrose_10: 159.1, dextrose_50: 14.0},
66
+ achieved_dextrose_conc: 9.8, fat_calories: 24.48, cho_calories: 77.89, cnr_rate: 174.26, non_protein: 102.37,
67
+ total_protein: 3.67, dir_rate: 9.7})
68
+ end
69
+
70
+ it "test Bhapkar mangal" do
71
+ build_tpn({current_weight: 1.11, percent_dextrose_conc: 0.1, total_fluid_intake: 80,
72
+ overfill_factor: 1.2, amino_acid_intake: 1, amino_acid_conc: 0.1, sodium_chloride_intake: 3, sodium_chloride_conc: 3.3,
73
+ potassium_chloride_intake: 2, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
74
+ magnesium_intake: 2, magnesium_conc: 4})
75
+ @tpn.calculate_tpn
76
+ @tpn.errors.empty?.should == true
77
+ match_results({current_weight: 1.11, percent_dextrose_conc: 0.1, total_fluid_intake: 80,
78
+ overfill_factor: 1.2, amino_acid_intake: 1, amino_acid_conc: 0.1, sodium_chloride_intake: 3, sodium_chloride_conc: 3.3,
79
+ potassium_chloride_intake: 2, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
80
+ magnesium_intake: 2, magnesium_conc: 4,
81
+ total_fluid_intake_vol: 88.8, tpn_vol: 88.8, hav_vol: 88.8, prepared_overfill: 106.6,
82
+ amino_acid_vol: 13.32, sodium_chloride_vol: 1.21, potassium_chloride_vol: 1.33, calcium_vol: 5.92, magnesium_vol: 0.67,
83
+ mvi: 0.56, dextrose_concentrations: {dextrose_10: 77.6, dextrose_50: 6.0},
84
+ achieved_dextrose_conc: 9.7, fat_calories: 0, cho_calories: 36.58, cnr_rate: 205.97, non_protein: 36.58,
85
+ total_protein: 1.11, dir_rate: 5.6})
86
+ end
87
+
88
+ it "test Shaikh Rauf Kasif" do
89
+ build_tpn({current_weight: 2.6, percent_dextrose_conc: 0.1, total_fluid_intake: 100,
90
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
91
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
92
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line"})
93
+ @tpn.calculate_tpn
94
+ @tpn.errors.empty?.should == true
95
+ match_results({current_weight: 2.6, percent_dextrose_conc: 0.1, total_fluid_intake: 100,
96
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
97
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
98
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line",
99
+ total_fluid_intake_vol: 260.0, tpn_vol: 260.0, hav_vol: 260.0, prepared_overfill: 312.0,
100
+ amino_acid_vol: 40.56, sodium_chloride_vol: 7.56, potassium_chloride_vol: 0.0, calcium_vol: 13.87, magnesium_vol: 0.23,
101
+ mvi: 1.3, dextrose_concentrations: {dextrose_10: 232.2, dextrose_50: 16.0},
102
+ achieved_dextrose_conc: 9.9, fat_calories: 0, cho_calories: 106.15, cnr_rate: 196.28, non_protein: 106.15,
103
+ total_protein: 3.38, dir_rate: 6.9, heparin: 0.31})
104
+ end
105
+
106
+ it "test Shaikh Rauf Kasif less percent_dextrose_conc" do
107
+ build_tpn({current_weight: 2.6, percent_dextrose_conc: 0.088, total_fluid_intake: 100,
108
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
109
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
110
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line"})
111
+ @tpn.calculate_tpn
112
+ @tpn.errors.empty?.should == true
113
+ match_results({current_weight: 2.6, percent_dextrose_conc: 0.088, total_fluid_intake: 100,
114
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
115
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
116
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line",
117
+ total_fluid_intake_vol: 260.0, tpn_vol: 260.0, hav_vol: 260.0, prepared_overfill: 312.0,
118
+ amino_acid_vol: 40.56, sodium_chloride_vol: 7.56, potassium_chloride_vol: 0.0, calcium_vol: 13.87, magnesium_vol: 0.23,
119
+ mvi: 1.3, dextrose_concentrations: {dextrose_5: 172.2, dextrose_25: 76.0},
120
+ achieved_dextrose_conc: 8.8, fat_calories: 0, cho_calories: 93.87, cnr_rate: 173.58, non_protein: 93.87,
121
+ total_protein: 3.38, dir_rate: 6.1, heparin: 0.31})
122
+ end
123
+
124
+ it "test Shaikh Rauf Kasif with fat" do
125
+ build_tpn({current_weight: 2.6, percent_dextrose_conc: 0.1, total_fluid_intake: 100, fat_intake: 1.2,
126
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
127
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
128
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line"})
129
+ @tpn.calculate_tpn
130
+ @tpn.errors.empty?.should == true
131
+ match_results({current_weight: 2.6, percent_dextrose_conc: 0.1, total_fluid_intake: 100,
132
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
133
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
134
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line",
135
+ total_fluid_intake_vol: 260.0, tpn_vol: 260.0, hav_vol: 228.8, prepared_overfill: 274.6,
136
+ amino_acid_vol: 40.56, sodium_chloride_vol: 7.56, potassium_chloride_vol: 0.0, calcium_vol: 13.87, magnesium_vol: 0.23,
137
+ mvi: 1.3, dextrose_concentrations: {dextrose_10: 194.8, dextrose_50: 16.0}, fat_vol: 31.2,
138
+ achieved_dextrose_conc: 9.9, fat_calories: 28.08, cho_calories: 93.43, cnr_rate: 224.69, non_protein: 121.51,
139
+ total_protein: 3.38, dir_rate: 6.1, heparin: 0.27})
140
+ end
141
+
142
+ it "test CNR warning" do
143
+ build_tpn({current_weight: 0.5, percent_dextrose_conc: 0.1, total_fluid_intake: 50,
144
+ overfill_factor: 1.2, amino_acid_intake: 0.9, amino_acid_conc: 0.05})
145
+ @tpn.calculate_tpn
146
+ @tpn.errors.empty?.should == true
147
+ @tpn.warnings.empty?.should_not == true
148
+ @tpn.warnings.include? "1037"
149
+ end
150
+
151
+ it "test DIR warning" do
152
+ build_tpn({current_weight: 1.2, percent_dextrose_conc: 0.1, total_fluid_intake: 180,
153
+ overfill_factor: 1.2, amino_acid_intake: 0.6, amino_acid_conc: 0.05})
154
+ @tpn.calculate_tpn
155
+ @tpn.errors.empty?.should == true
156
+ @tpn.warnings.empty?.should_not == true
157
+ @tpn.warnings.include? "1040"
158
+ end
159
+
160
+ it "test Shaikh Rauf Kasif with DIR input" do
161
+ build_tpn({current_weight: 2.6, expected_dir: 6.9, total_fluid_intake: 100,
162
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
163
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
164
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line"})
165
+ @tpn.calculate_tpn
166
+ @tpn.errors.empty?.should == true
167
+ match_results({current_weight: 2.6, percent_dextrose_conc: 0.1, total_fluid_intake: 100,
168
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8, sodium_chloride_conc: 3.3,
169
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
170
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line",
171
+ total_fluid_intake_vol: 260.0, tpn_vol: 260.0, hav_vol: 260.0, prepared_overfill: 312.0,
172
+ amino_acid_vol: 40.56, sodium_chloride_vol: 7.56, potassium_chloride_vol: 0.0, calcium_vol: 13.87, magnesium_vol: 0.23,
173
+ mvi: 1.3, dextrose_concentrations: {dextrose_10: 232.2, dextrose_50: 16.0},
174
+ achieved_dextrose_conc: 9.9, fat_calories: 0, cho_calories: 106.15, cnr_rate: 196.28, non_protein: 106.15,
175
+ total_protein: 3.38, dir_rate: 6.9, heparin: 0.31})
176
+ end
177
+
178
+ it "test total_fluid_intake as 1 with DIR input" do
179
+ build_tpn({current_weight: 2.6, expected_dir: 7.0, total_fluid_intake: 1,
180
+ overfill_factor: 1.2, amino_acid_intake: 1.3, amino_acid_conc: 0.1, sodium_chloride_intake: 8,sodium_chloride_conc: 3.3,
181
+ potassium_chloride_intake: 0, potassium_chloride_conc: 2, calcium_intake: 2, calcium_conc: 0.45,
182
+ magnesium_intake: 0.3, magnesium_conc: 4, administration: "Central Line"})
183
+ @tpn.calculate_tpn
184
+ expect(@tpn.errors.include? "1033").to be_true
185
+ end
186
+
187
+ it "Expected dir is less than actual" do
188
+ build_tpn({current_weight: 1.2, expected_dir: 7.3, total_fluid_intake: 125, fat_intake: 0.5,
189
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05})
190
+ @tpn.calculate_tpn
191
+ @tpn.errors.empty?.should == true
192
+ match_results({current_weight: 1.2, percent_dextrose_conc: 0.088, total_fluid_intake: 125, fat_intake: 0.5,
193
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
194
+ total_fluid_intake_vol: 150.0, tpn_vol: 150.0, fat_vol: 6.0, hav_vol: 144.0, prepared_overfill: 172.8,
195
+ amino_acid_vol: 14.4, sodium_chloride_vol: 0.0, potassium_chloride_vol: 0.0, calcium_vol: 0.0, magnesium_vol: 0.0,
196
+ mvi: 0.6, heparin: 0, remaining_dextrose_vol: 157.8, dextrose_concentrations: {dextrose_25: 37.0, dextrose_5: 120.8},
197
+ achieved_dextrose_conc: 8.7, fat_calories: 5.4, cho_calories: 51.99, cnr_rate: 597.81, non_protein: 57.39,
198
+ total_protein: 0.6, dir_rate: 7.3})
199
+ end
200
+
201
+ it "Expected dir is more than actual" do
202
+ build_tpn({current_weight: 1.2, expected_dir: 11.3, total_fluid_intake: 125, fat_intake: 0.5,
203
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05})
204
+ @tpn.calculate_tpn
205
+ @tpn.errors.empty?.should == true
206
+ match_results({current_weight: 1.2, percent_dextrose_conc: 0.135, total_fluid_intake: 125, fat_intake: 0.5,
207
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
208
+ total_fluid_intake_vol: 150.0, tpn_vol: 150.0, fat_vol: 6.0, hav_vol: 144.0, prepared_overfill: 172.8,
209
+ amino_acid_vol: 14.4, sodium_chloride_vol: 0.0, potassium_chloride_vol: 0.0, calcium_vol: 0.0, magnesium_vol: 0.0,
210
+ mvi: 0.6, heparin: 0, remaining_dextrose_vol: 157.8, dextrose_concentrations: {dextrose_10: 138.8, dextrose_50: 19.0},
211
+ achieved_dextrose_conc: 13.3, fat_calories: 5.4, cho_calories: 79.49, cnr_rate: 884.27, non_protein: 84.89,
212
+ total_protein: 0.6, dir_rate: 11.3})
213
+ end
214
+
215
+
216
+ it "should calculate from given dextrose50 & dextrose5" do
217
+ build_tpn({current_weight: 1.2, expected_dir: 11.3, total_fluid_intake: 125, fat_intake: 0.5,
218
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
219
+ available_dextrose_concentrations: [:dextrose_50, :dextrose_5]})
220
+ @tpn.calculate_tpn
221
+ @tpn.errors.empty?.should == true
222
+ match_results({achieved_dextrose_conc: 13.4, dextrose_concentrations: {dextrose_50: 35.0, dextrose_5: 122.8}})
223
+ end
224
+
225
+ it "should calculate with defaults dextrose concentration if its not achivable with given dextrose concs" do
226
+ build_tpn({current_weight: 1.2, expected_dir: 6.0, total_fluid_intake: 125, fat_intake: 0.5,
227
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
228
+ available_dextrose_concentrations: [:dextrose_50, :dextrose_25]})
229
+ @tpn.calculate_tpn
230
+ @tpn.errors.empty?.should == true
231
+ match_results({achieved_dextrose_conc: 7.1, dextrose_concentrations: {dextrose_25: 23.0, dextrose_5: 134.8}})
232
+ end
233
+
234
+ it "should throw an error if dextrose concentration can not be achieved with given concentrations" do
235
+ build_tpn({current_weight: 1.2, expected_dir: 11.3, total_fluid_intake: 125, fat_intake: 0.5,
236
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
237
+ available_dextrose_concentrations: [:dextrose_50, :dextrose_25]})
238
+ @tpn.calculate_tpn
239
+ @tpn.errors.include?("1505")
240
+ end
241
+
242
+ it "should throw an error if dextrose concentration can not be achieved with given concentrations" do
243
+ build_tpn({current_weight: 1.2, expected_dir: 11.3, total_fluid_intake: 125, fat_intake: 0.5,
244
+ lipid_conc: 0.1, overfill_factor: 1.2, amino_acid_intake: 0.5, amino_acid_conc: 0.05,
245
+ available_dextrose_concentrations: [:dextrose_50, :dextrose_5]})
246
+
247
+ @tpn.calculate_tpn
248
+ @tpn.errors.empty?.should == true
249
+ match_results({achieved_dextrose_conc: 13.4, dextrose_concentrations: {dextrose_50: 35.0, dextrose_5: 122.8}})
250
+ end
251
+
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $:.unshift(File.dirname(__FILE__) + '/../lib/')
5
+
6
+ require 'kimaya'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kimaya
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Shailesh Patil
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Core calculations for TPN
84
+ email:
85
+ - shailesh@joshsoftware.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - Rakefile
94
+ - kimaya.gemspec
95
+ - lib/generators/kimaya/USAGE
96
+ - lib/generators/kimaya/install_generator.rb
97
+ - lib/generators/kimaya/templates/config/locales/kimaya.en.yml
98
+ - lib/kimaya.rb
99
+ - lib/kimaya/kimaya.rb
100
+ - lib/kimaya/kimaya_core.rb
101
+ - lib/kimaya/version.rb
102
+ - spec/kimaya_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project: kimaya
123
+ rubygems_version: 2.4.8
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Core calculations for TPN
127
+ test_files:
128
+ - spec/kimaya_spec.rb
129
+ - spec/spec_helper.rb