medlineplus_ruby 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74298631315bcea88050379dcaa144ca9f74d341
4
+ data.tar.gz: 1dc8518d0f3cf74e25db5ec63d4e379614e8cfa3
5
+ SHA512:
6
+ metadata.gz: dff400e496b590ee21d9b58f4076d27b36d431f676ebad948e99f6a8688f09ceb53a78a4cc3e602e4d4cde4c090a441ed926373b3bfdd0f719c0f9d26d0febda
7
+ data.tar.gz: 83520bd0432eda769e7e81cc2c5124d1743ab5d0be7f6360bf49bdd5820e17ddf29530a6df652ce750be967c67e9f4f0e3b95aca38884ad7f5a47d49473e497e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in medlineplus_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 stratigos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # medlineplus_ruby
2
+
3
+ :construction: *Under Construction*
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library
6
+ into a gem. Put your Ruby code in the file `lib/medlineplus/ruby`. To experiment with that code, run `bin/console` for
7
+ an interactive prompt.
8
+
9
+ TODO: Delete this and the text above, and describe your gem
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'medlineplus_ruby'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install medlineplus_ruby
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here :construction_worker:
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
34
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
37
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
38
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and PRs from forks are welcome on GitHub at https://github.com/stratigos/medlineplus_ruby.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'medlineplus_ruby'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
11
+
12
+ # Alternatively, switch to IRB for console environment.
13
+ # require "irb"
14
+ # IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require 'medlineplus_ruby/version'
2
+ require 'medlineplus_ruby/client'
3
+
4
+ module MedlineplusRuby
5
+ end
@@ -0,0 +1,22 @@
1
+ require 'medlineplus_ruby/api/code_system'
2
+ require 'medlineplus_ruby/api/request_format'
3
+ require 'medlineplus_ruby/api/request'
4
+
5
+ module MedlineplusRuby
6
+ module API
7
+
8
+ # Creates a Hash intended for use as a HTTP GET query, in which keys
9
+ # represent both API endpoints and request parameters for the NLM
10
+ # Medlineplus Connect API request.
11
+ def description_data_for_code(diagnosis_code, options = {})
12
+ code_description_params = {
13
+ 'mainSearchCriteria.v.c' => diagnosis_code,
14
+ 'mainSearchCriteria.v.cs' => (options[:code_system] || MedlineplusRuby::API::CodeSystem::SYSTEM_ICD10),
15
+ 'knowledgeResponseType' => (options[:response_type] || MedlineplusRuby::API::RequestFormat::RESPONSE_JSON)
16
+ }
17
+
18
+ MedlineplusRuby::API::Request.build.get_request code_description_params
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module MedlineplusRuby
2
+ module API
3
+ module CodeSystem
4
+ # Medical diagnosis coding system identifiers, as understood by National
5
+ # Library of Medicine's Medlineplus Connect API internals.
6
+ SYSTEM_ICD10 = '2.16.840.1.113883.6.90'.freeze
7
+ SYSTEM_ICD9 = '2.16.840.1.113883.6.103'.freeze
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ require 'medlineplus_ruby/error'
2
+ require 'medlineplus_ruby/api/response_payload'
3
+ require 'medlineplus_ruby/api/response_message'
4
+ require 'rest-client'
5
+
6
+ module MedlineplusRuby
7
+ module API
8
+ # MedlinePlus Connect is rate limited to 100 req/minute. Once this limit is
9
+ # reached, service will not be restored for 300 seconds, or whenever the
10
+ # request rate falls below 100/min, whichever is longer.
11
+ class Request
12
+
13
+ # Base location from which to make API requests.
14
+ API_URI = 'https://apps.nlm.nih.gov/medlineplus/services/mpconnect_service.cfm'.freeze
15
+
16
+ # Object to handle resulting response body.
17
+ attr_reader :response_payload
18
+
19
+ def self.build
20
+ new ResponsePayload.new
21
+ end
22
+
23
+ def initialize(response_payload_handler)
24
+ @response_payload = response_payload_handler
25
+ end
26
+
27
+ def get_request(req_params = {})
28
+
29
+ response = RestClient.get API_URI, { params: req_params }
30
+
31
+ # TODO: Check for failures and/or rate limitations, and return an
32
+ # appropriate response. Provide an error message, or extract something
33
+ # meaningful from the response if provided. Note: it appears as though
34
+ # the National Library of Medicine has no such rate limitation at this
35
+ # time.
36
+ raise MedlineplusRuby::Error,
37
+ MedlineplusRuby::API::ResponseMessage::ERROR_NO_RESPONSE if response.nil? || response.empty?
38
+
39
+ @response_payload.respond response.body
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ module MedlineplusRuby
2
+ module API
3
+ module RequestFormat
4
+ # Acceptable MedlinePlus Connect API response types.
5
+ RESPONSE_JSON = 'application/json'.freeze
6
+ RESPONSE_XML = 'text/xml'.freeze
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module MedlineplusRuby
2
+ module API
3
+ module ResponseMessage
4
+ ERROR_NO_RESPONSE = 'No response from National Library of Medicine API.'.freeze
5
+ ERROR_NO_PARSE = 'Unable to parse response from National Library of Medicine API.'.freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'medlineplus_ruby/api/response_message'
2
+ require 'json'
3
+
4
+ module MedlineplusRuby
5
+ module API
6
+ class ResponsePayload
7
+
8
+ def initialize
9
+ end
10
+
11
+ # Currently only supports 'application/json' responses.
12
+ def respond(api_response_body)
13
+ formatted_response = {
14
+ success: false,
15
+ errors: [],
16
+ data_requested: nil,
17
+ data: [],
18
+ response_raw: api_response_body
19
+ }
20
+
21
+ begin
22
+ parsed_body = JSON.parse api_response_body, symbolize_names: true
23
+ rescue JSON::ParserError => e
24
+ formatted_response[:errors] << MedlineplusRuby::API::ResponseMessage::ERROR_NO_PARSE
25
+ end
26
+
27
+ formatted_response.tap do |h|
28
+ h[:success] = true
29
+ h[:data_requested] = parsed_body.dig :feed, :subtitle, :_value
30
+
31
+ parsed_body[:feed][:entry].each do |entry|
32
+ h[:data] << {
33
+ title: entry[:title][:_value],
34
+ link: entry[:link].first[:href],
35
+ description: entry[:summary][:_value]
36
+ }
37
+ end if !!parsed_body[:feed][:entry]
38
+ end if !!parsed_body
39
+
40
+ formatted_response
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require 'medlineplus_ruby/api/api'
2
+
3
+ module MedlineplusRuby
4
+ class Client
5
+ include MedlineplusRuby::API
6
+
7
+ def initialize(options = {})
8
+ options.each do |key, value|
9
+ instance_variable_set "@#{key}", value
10
+ end
11
+ yield(self) if block_given?
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # Descriptive error object for client/service errors.
2
+ module MedlineplusRuby
3
+ class Error < StandardError; end;
4
+ end
@@ -0,0 +1,3 @@
1
+ module MedlineplusRuby
2
+ VERSION = '0.1.1'.freeze
3
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'medlineplus_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'medlineplus_ruby'
8
+ spec.version = MedlineplusRuby::VERSION
9
+ spec.authors = ['Todd Morningstar']
10
+ spec.email = ['techarchist@gmail.com']
11
+ spec.homepage = 'https://github.com/stratigos/medlineplus_ruby'
12
+ spec.license = 'MIT'
13
+ spec.summary = 'Modernize access to the Medlineplus Connect API.'
14
+ spec.description = 'The National Library of Medicine API, "Medlineplus Connect", can be somewhat cantankerous to ' \
15
+ 'work with. Query params are non sensical to end users, query format is from a bygone era, and the resulting ' \
16
+ 'responses often contain large amounts of superficial information. The response structures are somewhat ' \
17
+ 'inconsistant, and are always non intuitive. This gem simplifies querying the NLM API, and parses the responses '\
18
+ 'into something more sane and structured for the average Ruby dev to use. Note that at this time, the only ' \
19
+ 'feature available through this gem is querying descriptions for ICD-10 codes, more API interfaces TBD.'
20
+ spec.post_install_message = 'Thanks for trying medlineplus_ruby!'
21
+
22
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
23
+ # 'allowed_push_host' to allow pushing to a single host or delete this
24
+ # section to allow pushing to any host.
25
+ # if spec.respond_to?(:metadata)
26
+ # spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
27
+ # else
28
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
29
+ # 'public gem pushes.'
30
+ # end
31
+
32
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
33
+ f.match(%r{^(test|spec|features)/})
34
+ end
35
+
36
+ # spec.bindir = 'exe'
37
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ['lib']
39
+ spec.required_ruby_version = '>= 2.4.1'
40
+
41
+ spec.add_development_dependency 'bundler', '~> 1.14'
42
+ spec.add_development_dependency 'pry'
43
+ spec.add_development_dependency 'rake', '~> 10.0'
44
+ spec.add_development_dependency 'rspec', '~> 3.6'
45
+ spec.add_development_dependency 'webmock', '~> 3.0.1'
46
+
47
+ spec.add_runtime_dependency 'json', '~> 2.1.0'
48
+ spec.add_runtime_dependency 'rest-client', '~> 2.0.2'
49
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: medlineplus_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Todd Morningstar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-17 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.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: '3.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rest-client
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.2
111
+ description: The National Library of Medicine API, "Medlineplus Connect", can be somewhat
112
+ cantankerous to work with. Query params are non sensical to end users, query format
113
+ is from a bygone era, and the resulting responses often contain large amounts of
114
+ superficial information. The response structures are somewhat inconsistant, and
115
+ are always non intuitive. This gem simplifies querying the NLM API, and parses the
116
+ responses into something more sane and structured for the average Ruby dev to use.
117
+ Note that at this time, the only feature available through this gem is querying
118
+ descriptions for ICD-10 codes, more API interfaces TBD.
119
+ email:
120
+ - techarchist@gmail.com
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - ".gitignore"
126
+ - ".rspec"
127
+ - ".travis.yml"
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - bin/console
133
+ - bin/setup
134
+ - lib/medlineplus_ruby.rb
135
+ - lib/medlineplus_ruby/api/api.rb
136
+ - lib/medlineplus_ruby/api/code_system.rb
137
+ - lib/medlineplus_ruby/api/request.rb
138
+ - lib/medlineplus_ruby/api/request_format.rb
139
+ - lib/medlineplus_ruby/api/response_message.rb
140
+ - lib/medlineplus_ruby/api/response_payload.rb
141
+ - lib/medlineplus_ruby/client.rb
142
+ - lib/medlineplus_ruby/error.rb
143
+ - lib/medlineplus_ruby/version.rb
144
+ - medlineplus_ruby.gemspec
145
+ homepage: https://github.com/stratigos/medlineplus_ruby
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message: Thanks for trying medlineplus_ruby!
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: 2.4.1
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.6.11
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Modernize access to the Medlineplus Connect API.
169
+ test_files: []