hippocratic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +9 -0
- data/hippocratic.gemspec +27 -0
- data/lib/hippocratic/version.rb +3 -0
- data/lib/hippocratic.rb +59 -0
- data/spec/hippocratic_spec.rb +160 -0
- data/spec/spec_helper.rb +2 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a89ab114ad43c1a76725e64d2c5196a20dd258d
|
4
|
+
data.tar.gz: 14719d98888218d0f56e5ccd33fad7c7f52fb5d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bc8508c8bad00131f782d72ce3d6b68f50d4723dc1a3dbb2d767541b4ccd938575c485d1f84ebc8dbb69be3b230dadc687c87107a09d3e844643a20364ea798
|
7
|
+
data.tar.gz: 05fce638b55be0b6daa98f5abb34f0dc264a7bee63821ebd51e2771d736e3ae3d670a9dd620624ba2b71023f208e209fdc883041bb72e8d662c489034c4b0d1d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Shelby Switzer
|
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,53 @@
|
|
1
|
+
# Hippocratic
|
2
|
+
|
3
|
+
Hippocratic is a simple wrapper for the Physicans Desk Reference. Since the PDR doesn't have an API and I needed a simple way
|
4
|
+
to get information about drugs, I wrote Hippocratic, which basically uses Nokogiri to search and parse pdrhealth.com. It essentially creates
|
5
|
+
an object based on the PDR page for the drug you specify, with basic methods available to get the info you need.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'hippocratic'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hippocratic
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
To find info about a drug, simply instantiate a new Drug Reference object with the name of the drug:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
reference = Hippocratic::DrugReference.new("Sudafed")
|
29
|
+
|
30
|
+
reference.valid?
|
31
|
+
=> true
|
32
|
+
|
33
|
+
reference.description
|
34
|
+
=> "What is this medication?Sudafed contains a nasal decongestant. It is intended to temporarily relieve sinus congestion and pressure. It is also intended to temporarily relieve nasal congestion due to the the common cold, hay fever, and other upper respiratory allergies. Sudafed 24 Hour is also intended to reduce the swelling of nasal passages."
|
35
|
+
|
36
|
+
reference.side_effects
|
37
|
+
=> "What are the possible side effects of Sudafed?If you are taking Sudafed 24 Hour, tablets of this kind may cause a bowel obstruction, usually in people with a severe narrowing of the bowel (esophagus, stomach, or intestine). Side effects cannot always be anticipated. If any develop or change in intensity, tell your doctor as soon as possible. Only your doctor can determine if it is safe for you to continue taking this drug."
|
38
|
+
|
39
|
+
reference.storage
|
40
|
+
=> "How should I store Sudafed?Store Sudafed Congestion at room temperature. Store Sudafed 12 Hour and Sudafed 24 Hour at room temperature in a dry place. Protect Sudafed 12 Hour from light."
|
41
|
+
|
42
|
+
reference.dosage
|
43
|
+
=> "What is the usual dosage of Sudafed?Sudafed Congestion: Adults and children ≥12 years: Take two 30-milligram (mg) tablets every 4 to 6 hours. Do not take more than 8 tablets in 24 hours. Children 6-11: Take1 tablet every 4 to 6 hours. Do not take more than 4 tablets in 24 hours. Children Do not use. Sudafed 12 Hour: Adults and children ≥12 years: Take one 120-mg tablet every 12 hours. Do not take more than 2 tablets in 24 hours. Children Do not use. Sudafed 24 Hour: Adults and children ≥12 years: Swallow one whole 240-mg tablet with water every 24 hours. Do not exceed one tablet in 24 hours. Do not divide, crush, chew, or dissolve the tablet. Children Do not use."
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it ( https://github.com/[my-github-username]/hippocratic/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/hippocratic.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hippocratic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hippocratic"
|
8
|
+
spec.version = Hippocratic::VERSION
|
9
|
+
spec.authors = ["Shelby Switzer"]
|
10
|
+
spec.email = ["shelbyswitzer@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for the online Physician's Desk Reference}
|
12
|
+
spec.description =
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_runtime_dependency "nokogiri", "~>1.6"
|
24
|
+
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
27
|
+
end
|
data/lib/hippocratic.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "nokogiri"
|
3
|
+
require "hippocratic/version"
|
4
|
+
|
5
|
+
module Hippocratic
|
6
|
+
|
7
|
+
class DrugReference
|
8
|
+
|
9
|
+
attr_accessor :description, :dosage, :other_names, :side_effects, :storage
|
10
|
+
|
11
|
+
REFERENCE_HASH = {
|
12
|
+
description: "What is",
|
13
|
+
dosage: "What is the usual dosage",
|
14
|
+
other_names: "Other names",
|
15
|
+
side_effects: "What are the possible side effects",
|
16
|
+
storage: "How should I store"
|
17
|
+
}
|
18
|
+
|
19
|
+
# assign instance variables for attributes (description, dosage, other names, side effects, storage)
|
20
|
+
# that are contained within a question node on page
|
21
|
+
# TODO rescue from 404 / include as part of validation
|
22
|
+
def initialize(drug_name)
|
23
|
+
@drug_name = drug_name
|
24
|
+
modified_name = format_name
|
25
|
+
@document = Nokogiri::HTML(open(Hippocratic.base_uri + modified_name))
|
26
|
+
@article = @document.css("article")
|
27
|
+
for key in REFERENCE_HASH.keys do
|
28
|
+
send "#{key}=", find_node(key)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
header = @document.css("h1").first
|
34
|
+
header.text == @drug_name
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def find_node(key)
|
40
|
+
term = REFERENCE_HASH[key]
|
41
|
+
header_node = @article.search("[text()*='#{term}']").first
|
42
|
+
return nil unless header_node
|
43
|
+
header_node.parent.text
|
44
|
+
end
|
45
|
+
|
46
|
+
def format_name
|
47
|
+
name = @drug_name.gsub(" ", "-")
|
48
|
+
name = name.gsub("'", "")
|
49
|
+
name.gsub("/", "-")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
# not actually the pdr but same publishers. need To index pdr drugs before we can use that
|
56
|
+
def self.base_uri
|
57
|
+
"http://www.pdrhealth.com/drugs/"
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hippocratic do
|
4
|
+
|
5
|
+
describe Hippocratic::DrugReference do
|
6
|
+
|
7
|
+
context "Normal one-word drug name, with other names" do
|
8
|
+
subject { Hippocratic::DrugReference.new("Sudafed") }
|
9
|
+
|
10
|
+
it 'has Sudafed description' do
|
11
|
+
expect(
|
12
|
+
subject.description
|
13
|
+
).to include("contains a nasal decongestant")
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has Sudafed dosage' do
|
17
|
+
expect(subject.dosage.downcase).to include("adults")
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has Sudafed other names' do
|
21
|
+
expect(subject.other_names).to include("Sudafed Congestion")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has Sudafed side effects' do
|
25
|
+
expect(subject.side_effects).to include("bowel obstruction")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has Sudafed storage info' do
|
29
|
+
expect(subject.storage).to include("room temperature")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "drug name with dash" do
|
34
|
+
subject { Hippocratic::DrugReference.new("Toprol-XL") }
|
35
|
+
|
36
|
+
it 'has Toprol-XL description' do
|
37
|
+
expect(
|
38
|
+
subject.description
|
39
|
+
).to include("beta-blocker")
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'has Toprol-XL dosage' do
|
43
|
+
expect(subject.dosage.downcase).to include("adults")
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has Toprol-XL other names' do
|
47
|
+
expect(subject.other_names).to eq(nil)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'has Toprol-XL side effects' do
|
51
|
+
expect(subject.side_effects).to include("diarrhea")
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has Toprol-XL storage info' do
|
55
|
+
expect(subject.storage).to include("room temperature")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "drug name with slash" do
|
60
|
+
subject { Hippocratic::DrugReference.new("Derma-Smoothe/FS Scalp Oil") }
|
61
|
+
|
62
|
+
it 'has Toprol-XL description' do
|
63
|
+
expect(subject.description).to include("topical medicine")
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'has Toprol-XL dosage' do
|
67
|
+
expect(subject.dosage.downcase).to include("adults")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'has Toprol-XL other names' do
|
71
|
+
expect(subject.other_names).to eq(nil)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'has Toprol-XL side effects' do
|
75
|
+
expect(subject.side_effects).to include("acne")
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'has Toprol-XL storage info' do
|
79
|
+
expect(subject.storage).to include("room temperature")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "drug name with spaces" do
|
84
|
+
subject { Hippocratic::DrugReference.new("Advil Cold and Sinus") }
|
85
|
+
|
86
|
+
it 'has advil description' do
|
87
|
+
expect(subject.description).to include("nasal decongestant")
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'has advil dosage' do
|
91
|
+
expect(subject.dosage.downcase).to include("adults")
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'has advil other names' do
|
95
|
+
expect(subject.other_names).to include("Advil Cold and Sinus Caplets")
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'has advil side effects' do
|
99
|
+
expect(subject.side_effects).to include("allergic reaction")
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'has advil storage info' do
|
103
|
+
expect(subject.storage).to include("room temperature")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "drug name with apostrophe" do
|
108
|
+
subject { Hippocratic::DrugReference.new("Children's Tylenol") }
|
109
|
+
|
110
|
+
it 'has advil description' do
|
111
|
+
expect(subject.description).to include("pain reliever/fever reducer")
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'has advil dosage' do
|
115
|
+
expect(subject.dosage.downcase).to include("children")
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'has advil other names' do
|
119
|
+
expect(subject.other_names).to include("Children's Tylenol Suspension Liquid Grape")
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'has advil side effects' do
|
123
|
+
expect(subject.side_effects).to include("Severe liver damage")
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'has advil storage info' do
|
127
|
+
expect(subject.storage).to include("room temperature")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "normal drug name with no other names" do
|
132
|
+
subject { Hippocratic::DrugReference.new("Ambien") }
|
133
|
+
|
134
|
+
it 'has ambien description' do
|
135
|
+
expect(
|
136
|
+
subject.description
|
137
|
+
).to include("insomnia")
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'has ambien dosage' do
|
141
|
+
expect(subject.dosage.downcase).to include("adults")
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns nil for other names' do
|
145
|
+
expect(subject.other_names).to eq(nil)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'has ambien side effects' do
|
149
|
+
expect(subject.side_effects).to include("diarrhea")
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'has ambien storage info' do
|
153
|
+
expect(subject.storage).to include("room temperature")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hippocratic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shelby Switzer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- shelbyswitzer@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- hippocratic.gemspec
|
96
|
+
- lib/hippocratic.rb
|
97
|
+
- lib/hippocratic/version.rb
|
98
|
+
- spec/hippocratic_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: ''
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Ruby wrapper for the online Physician's Desk Reference
|
124
|
+
test_files:
|
125
|
+
- spec/hippocratic_spec.rb
|
126
|
+
- spec/spec_helper.rb
|