framingham 0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *~
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in framingham.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Framingham
2
+
3
+ Ruby gem to implement Framingham Heart Study calculators
4
+ http://www.framinghamheartstudy.org
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'framingham'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install framingham
19
+
20
+ # Module: Framingham::Heartdisease#
21
+         `Defined in: framingham/heartdisease.rb`
22
+
23
+ ## Usage
24
+
25
+ ---
26
+ ### Public Class Methods ###
27
+ ![](http://ruby-doc.org/images/brick.png) ::eval(options) → Float or Error String
28
+
29
+         Evaluates Framingham::Heartdisease score
30
+
31
+ ###   Parameters ###
32
+
33
+ options(<code>Hash&lt;<span style="color:purple">​Symbol</span>, <span style="color:cadetblue">Object</span>&gt;</span></code>) (defaults to: `{}`) — initial context configuration
34
+
35
+ ```ruby
36
+ age: 30..74
37
+ blood_pressure: 90..200
38
+ blood_pressure_treatment: true | false
39
+ body_mass_index: 15..50
40
+ diabetes: true | false
41
+ gender: :male | :female
42
+ smoker: true | false
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,150 @@
1
+ module Framingham::Heartdisease extend Framingham, self
2
+
3
+ def eval options = {}
4
+ begin
5
+ #initialize
6
+ options = NORMAL.merge options
7
+ @age = options[:age]
8
+ @blood_pressure = options[:blood_pressure]
9
+ @blood_pressure_treatment = options[:blood_pressure_treatment] ? :treated : :untreated
10
+ @body_mass_index = options[:body_mass_index]
11
+ @gender = options[:gender]
12
+ @diabetes = to_i options[:diabetes]
13
+ @smoker = to_i options[:smoker]
14
+ rescue => exception
15
+ abort "\033[31merror: " + exception.message + "\033[0m"
16
+ else
17
+ #calculate
18
+ start_beta = BETA_ZERO[@gender] + Math.log(@age) * AGE[@gender]
19
+ risk = 1 - POWER_BASE[@gender] ** Math.exp(
20
+ start_beta +
21
+ Math.log(@blood_pressure) * BLOOD_PRESSURE[@gender][@blood_pressure_treatment] +
22
+ Math.log(@body_mass_index) * BODY_MASS_INDEX[@gender] +
23
+ @diabetes * DIABETES[@gender] +
24
+ @smoker * SMOKER[@gender]
25
+ )
26
+ normal = 1 - POWER_BASE[@gender] ** Math.exp(
27
+ start_beta +
28
+ Math.log(NORMAL[:blood_pressure]) * BLOOD_PRESSURE[@gender][:untreated] +
29
+ Math.log(NORMAL[:body_mass_index]) * BODY_MASS_INDEX[@gender]
30
+ )
31
+ optimal = 1 - POWER_BASE[@gender] ** Math.exp(
32
+ start_beta +
33
+ Math.log(OPTIMAL[:blood_pressure]) * BLOOD_PRESSURE[@gender][:untreated] +
34
+ Math.log(OPTIMAL[:body_mass_index]) * BODY_MASS_INDEX[@gender]
35
+ )
36
+ age_range = 10..86
37
+ age = 0
38
+ heart_age = lambda{
39
+ while (age_range.max - age_range.min) > 0.2 do
40
+ age = (age_range.max + age_range.min) / 2.0
41
+ test_risk = 1 - POWER_BASE[@gender] ** Math.exp(
42
+ BETA_ZERO[@gender] + Math.log(age) * AGE[@gender] +
43
+ Math.log(NORMAL[:blood_pressure]) * BLOOD_PRESSURE[@gender][:untreated] +
44
+ Math.log(NORMAL[:body_mass_index]) * BODY_MASS_INDEX[@gender]
45
+ )
46
+ age_range = test_risk < risk ? age..age_range.max : age_range = age_range.min..age
47
+ end
48
+ age
49
+ }.call
50
+ {
51
+ heart_age: heart_age,
52
+ risk: risk,
53
+ normal: normal,
54
+ optimal: optimal
55
+ }
56
+ end
57
+ end
58
+
59
+ def pretty _
60
+ result = eval _
61
+ puts "Heart Age: " + result[:heart_age].to_i.to_s
62
+ puts "Risk: " + "%4.1f%%" % (result[:risk] * 100)
63
+ puts "Normal: " + "%4.1f%%" % (result[:normal] * 100)
64
+ puts "Optimal: " + "%4.1f%%" % (result[:optimal] * 100)
65
+ end
66
+
67
+ def help
68
+ "Evaluate 10 year heart disease risk"
69
+ end
70
+
71
+ protected
72
+
73
+ $, = ", " #default join
74
+
75
+ NORMAL = { #default options
76
+ age: 30,
77
+ blood_pressure: 125,
78
+ blood_pressure_treatment: false,
79
+ body_mass_index: 22.5,
80
+ diabetes: false,
81
+ gender: :female,
82
+ smoker: false
83
+ } unless defined? NORMAL
84
+
85
+ OPTIMAL = NORMAL.merge({
86
+ blood_pressure: 110,
87
+ body_mass_index: 22
88
+ }) unless defined? OPTIMAL
89
+
90
+ AGE_RANGE = (30..79) unless defined? AGE_RANGE
91
+
92
+ BLOOD_PRESSURE_RANGE = (90..200) unless defined? BLOOD_PRESSURE_RANGE
93
+
94
+ BMI_RANGE = (15..50) unless defined? BMI_RANGE
95
+
96
+ GENDERS = [
97
+ :male,
98
+ :female
99
+ ] unless defined? GENDERS
100
+
101
+ ERRORS = {
102
+ age: "age must be in range: " + AGE_RANGE.to_s,
103
+ blood_pressure: "blood pressure must be in range: " + BLOOD_PRESSURE_RANGE.to_s,
104
+ bmi: "bmi must be in range: " + BMI_RANGE.to_s,
105
+ gender: "invalid gender, options: " + GENDERS.join,
106
+ } unless defined? ERRORS
107
+
108
+ BETA_ZERO = {
109
+ male: -23.9388,
110
+ female: -26.0145
111
+ } unless defined? BETA_ZERO
112
+
113
+ POWER_BASE = {
114
+ male: 0.88431,
115
+ female: 0.94833
116
+ } unless defined? POWER_BASE
117
+
118
+ AGE = {
119
+ male: 3.11296,
120
+ female: 2.72107
121
+ } unless defined? AGE
122
+
123
+ BLOOD_PRESSURE = {
124
+ male:{
125
+ treated: 1.92672,
126
+ untreated: 1.85508
127
+ },
128
+ female:{
129
+ treated: 2.88267,
130
+ untreated: 2.81291
131
+ }
132
+ } unless defined? BLOOD_PRESSURE
133
+
134
+ BODY_MASS_INDEX = {
135
+ male: 0.79277,
136
+ female: 0.51125
137
+ } unless defined? BODY_MASS_INDEX
138
+
139
+ DIABETES = {
140
+ male: 0.5316,
141
+ female: 0.77763
142
+ } unless defined? DIABETES
143
+
144
+ SMOKER = {
145
+ male: 0.70953,
146
+ female: 0.61868
147
+ } unless defined? SMOKER
148
+
149
+ end
150
+
@@ -0,0 +1,3 @@
1
+ module Framingham
2
+ VERSION = "0.0" unless defined? VERSION
3
+ end
@@ -0,0 +1,19 @@
1
+ lib = File.expand_path('./framingham')
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ $LOAD_PATH << lib
4
+
5
+ require 'version'
6
+
7
+ Gem::Specification.new{ |_|
8
+ _.name = "framingham"
9
+ _.version = Framingham::VERSION
10
+ _.author = "3PoundHealth"
11
+ _.summary = "Gem to implement Framingham Heart Study calculators"
12
+ _.license = "MIT"
13
+ _.files = `git ls-files`.split($/)
14
+ _.executables = _.files.grep(%r{^/}) { |f| File.basename(f) }
15
+ _.test_files = _.files.grep(%r{^(test|spec|features)/})
16
+ _.require_path = "."
17
+ _.add_development_dependency "bundler", "~> 1.3"
18
+ _.add_development_dependency "rake"
19
+ }
data/framingham.rb ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby
2
+ load 'framingham/version.rb'
3
+ load 'framingham/heartdisease.rb'
4
+
5
+ module Framingham extend self
6
+
7
+ def help
8
+ "Framingham display help info..."
9
+ end
10
+
11
+ def version
12
+ "version: " + VERSION
13
+ end
14
+
15
+ protected
16
+
17
+ def to_i value
18
+ (value.eql? true or value.to_s == "true" or (
19
+ value.to_f != 0 if value.respond_to? 'to_f'
20
+ )) ? 1 : 0
21
+ end
22
+
23
+ end
24
+
25
+ puts self.eval ARGV[0].to_s if ARGV.length !=0
26
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: framingham
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - 3PoundHealth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email:
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - framingham.gemspec
58
+ - framingham.rb
59
+ - framingham/heartdisease.rb
60
+ - framingham/version.rb
61
+ homepage:
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - .
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Gem to implement Framingham Heart Study calculators
86
+ test_files: []