bloom_api 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/Gemfile.lock +1 -1
- data/lib/bloom_api.rb +25 -4
- data/lib/bloom_api/version.rb +1 -1
- data/spec/bloom_api/api_spec.rb +2 -2
- data/spec/bloom_api_spec.rb +96 -30
- metadata +2 -4
- data/spec/bloom_api/provider_lookup_spec.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88cb09f4c7f006ec69a48ebaaa50d50ea57b486b
|
|
4
|
+
data.tar.gz: 2fe80966cb4bccfcfaf00c38bcb1c7e45504f4ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae1ed22386bdad4933d0a20992091cca438e936d27e8abc2b1e4039021c5b9cc45c676bd263f3e11d9c028564f4f1f043b9f26992b4c3d211fac865f0dfbce2b
|
|
7
|
+
data.tar.gz: 8ec9e8b8567a14a1d1c866fd5bb8a980a89c60c9cc0bce796a6e913491a60c27553ffc400fe8de4b215a5cf5cc00c3caee6daebc21284d7b49fe3d1845d24f01
|
data/.gitignore
CHANGED
|
@@ -27,8 +27,8 @@ build/
|
|
|
27
27
|
# for a library or gem, you might want to ignore these files since the code is
|
|
28
28
|
# intended to run in multiple environments; otherwise, check them in:
|
|
29
29
|
# Gemfile.lock
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
.ruby-version
|
|
31
|
+
.ruby-gemset
|
|
32
32
|
|
|
33
33
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
34
34
|
.rvmrc
|
data/Gemfile.lock
CHANGED
data/lib/bloom_api.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "bloom_api/version"
|
|
2
|
+
require "uri/http"
|
|
2
3
|
|
|
3
4
|
# A module which contains all code necessary for
|
|
4
5
|
# looking up health care providers via the Bloom API.
|
|
@@ -21,6 +22,22 @@ module BloomApi
|
|
|
21
22
|
|
|
22
23
|
# The base url for the bloom api.
|
|
23
24
|
BASE_URL = "www.bloomapi.com"
|
|
25
|
+
NPI_SEARCH_PATH = "/api/search/npi"
|
|
26
|
+
|
|
27
|
+
# Look up a health care provider or organization by the provided criteria
|
|
28
|
+
#
|
|
29
|
+
# @params criteria [Hash] criteria to query against
|
|
30
|
+
# @params limit [Integer] optional, sets the maximum number of records to return. Default is 20 and maximum is 100
|
|
31
|
+
# @params offset [Integer] optional, sets a number of records to skip before returning. Default is 0
|
|
32
|
+
# @return results [Array] Array of providers and/or organizations that match the criteria
|
|
33
|
+
def self.find_by(options, limit=20, offset=0)
|
|
34
|
+
criteria = options.each_with_index.map {|x,i| "key#{i+1}=#{URI::escape(x[0].to_s)}&op#{i+1}=eq&value#{i+1}=#{URI::escape(x[1])}"} || []
|
|
35
|
+
criteria << "limit=#{limit}&offset=#{offset}"
|
|
36
|
+
uri = URI::HTTP.build(host: BASE_URL, path: NPI_SEARCH_PATH, query: criteria.join('&'))
|
|
37
|
+
response = Net::HTTP.get_response(uri)
|
|
38
|
+
|
|
39
|
+
build_provider(JSON.parse(response.body)['result']) if response && response.code == "200"
|
|
40
|
+
end
|
|
24
41
|
|
|
25
42
|
# Look up a health care provider by their national provider identifier
|
|
26
43
|
#
|
|
@@ -32,15 +49,19 @@ module BloomApi
|
|
|
32
49
|
def self.find_by_npi(npi)
|
|
33
50
|
response = Net::HTTP.get_response(BASE_URL, "/api/npis/#{npi}")
|
|
34
51
|
|
|
35
|
-
build_provider(JSON.parse(response.body)['result']) if response.code == "200"
|
|
52
|
+
build_provider(JSON.parse(response.body)['result']) if response && response.code == "200"
|
|
36
53
|
end
|
|
37
54
|
|
|
38
55
|
private
|
|
39
56
|
|
|
40
57
|
def self.build_provider(response)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
if response.is_a?(Array)
|
|
59
|
+
response.map { |r| build_provider(r) }
|
|
60
|
+
else
|
|
61
|
+
return Individual.new(response) if response['type'] == 'individual'
|
|
62
|
+
return Organization.new(response) if response['type'] == 'organization'
|
|
63
|
+
Provider.new(response)
|
|
64
|
+
end
|
|
44
65
|
end
|
|
45
66
|
|
|
46
67
|
end
|
data/lib/bloom_api/version.rb
CHANGED
data/spec/bloom_api/api_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require_relative '../spec_helper'
|
|
2
2
|
|
|
3
|
-
describe BloomApi
|
|
3
|
+
describe BloomApi do
|
|
4
4
|
|
|
5
5
|
describe '#find_by_npi' do
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ describe BloomApi::Api do
|
|
|
8
8
|
allow(Net::HTTP).to receive(:get_response).with("www.bloomapi.com/api/npis/#{npi}").and_return(json_response)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
subject { BloomApi
|
|
11
|
+
subject { BloomApi.find_by_npi(npi) }
|
|
12
12
|
|
|
13
13
|
context 'when given a valid npi' do
|
|
14
14
|
let(:npi) { '1003002809' }
|
data/spec/bloom_api_spec.rb
CHANGED
|
@@ -3,48 +3,114 @@ require 'JSON'
|
|
|
3
3
|
|
|
4
4
|
describe BloomApi do
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
describe '#find_by_npi' do
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
subject { BloomApi.find_by_npi(npi) }
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
context 'when given a valid npi' do
|
|
12
|
+
context 'for an individual' do
|
|
13
|
+
let(:npi) { '1003002809' }
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
it { expect(subject).to be_a BloomApi::Individual }
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
it 'returns the right provider' do
|
|
18
|
+
provider = subject
|
|
19
|
+
expect(provider.npi).to eq '1003002809'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
context 'for an organization' do
|
|
24
|
+
let(:npi) { '1013191311' }
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
it { expect(subject).to be_a BloomApi::Organization }
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
it 'returns the right provider' do
|
|
29
|
+
expect(subject.npi).to eq '1013191311'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
context 'when type is not present' do
|
|
34
|
+
let(:npi) { '1003998626' }
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
it { expect(subject).to be_a BloomApi::Provider }
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
context 'when given an invalid npi' do
|
|
42
|
+
let(:npi) { 'bogus_npi' }
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
it 'returns nil' do
|
|
45
|
+
expect(subject).to be_nil
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#find_by' do
|
|
52
|
+
|
|
53
|
+
subject { BloomApi.find_by(criteria) }
|
|
54
|
+
|
|
55
|
+
context 'when given valid criteria' do
|
|
56
|
+
context 'for an individual' do
|
|
57
|
+
let(:criteria) { {'npi' => '1003002809'} }
|
|
58
|
+
|
|
59
|
+
it { expect(subject).to be_a Array }
|
|
60
|
+
it { expect(subject.size).to eq 1 }
|
|
61
|
+
it { expect(subject.first).to be_a BloomApi::Individual }
|
|
62
|
+
|
|
63
|
+
it 'returns the right provider' do
|
|
64
|
+
expect(subject.first.npi).to eq '1003002809'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'for an organization' do
|
|
69
|
+
let(:criteria) { {'business_name' => 'WILBUR AVENUE', 'practice_address.zip' => '088653453'} }
|
|
70
|
+
|
|
71
|
+
it { expect(subject).to be_a Array }
|
|
72
|
+
it { expect(subject.size).to eq 1 }
|
|
73
|
+
it { expect(subject.first).to be_a BloomApi::Organization }
|
|
74
|
+
|
|
75
|
+
it 'returns the right organization' do
|
|
76
|
+
expect(subject.first.npi).to eq '1013191311'
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context 'for mixed results' do
|
|
81
|
+
let(:criteria) { {'practice_address.zip' => '088653453'} }
|
|
82
|
+
|
|
83
|
+
it { expect(subject).to be_a Array }
|
|
84
|
+
it { expect(subject.size).to eq 4 }
|
|
85
|
+
it { expect(subject.map(&:class).uniq).to contain_exactly BloomApi::Organization, BloomApi::Individual }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context 'no matches' do
|
|
89
|
+
let(:criteria) { {'business_name' => 'bogus_value'} }
|
|
90
|
+
|
|
91
|
+
it { expect(subject).to be_a Array }
|
|
92
|
+
it { expect(subject.empty?).to be_truthy }
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
context 'when given invalid criteria' do
|
|
97
|
+
let(:criteria) { {'bogus_field' => 'bogus_value'} }
|
|
98
|
+
|
|
99
|
+
it { expect(subject).to be_a Array }
|
|
100
|
+
it { expect(subject.empty?).to be_truthy }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context 'when passing symbols' do
|
|
104
|
+
let(:criteria) { {npi: '1003002809'} }
|
|
105
|
+
|
|
106
|
+
it { expect(subject).to be_a Array }
|
|
107
|
+
it { expect(subject.size).to eq 1 }
|
|
108
|
+
it { expect(subject.first).to be_a BloomApi::Individual }
|
|
109
|
+
|
|
110
|
+
it 'returns the right provider' do
|
|
111
|
+
expect(subject.first.npi).to eq '1003002809'
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
50
116
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bloom_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Carpenter
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -83,7 +83,6 @@ files:
|
|
|
83
83
|
- spec/bloom_api/individual_spec.rb
|
|
84
84
|
- spec/bloom_api/organization_official_spec.rb
|
|
85
85
|
- spec/bloom_api/organization_spec.rb
|
|
86
|
-
- spec/bloom_api/provider_lookup_spec.rb
|
|
87
86
|
- spec/bloom_api/provider_spec.rb
|
|
88
87
|
- spec/bloom_api/specialty_spec.rb
|
|
89
88
|
- spec/bloom_api_spec.rb
|
|
@@ -119,7 +118,6 @@ test_files:
|
|
|
119
118
|
- spec/bloom_api/individual_spec.rb
|
|
120
119
|
- spec/bloom_api/organization_official_spec.rb
|
|
121
120
|
- spec/bloom_api/organization_spec.rb
|
|
122
|
-
- spec/bloom_api/provider_lookup_spec.rb
|
|
123
121
|
- spec/bloom_api/provider_spec.rb
|
|
124
122
|
- spec/bloom_api/specialty_spec.rb
|
|
125
123
|
- spec/bloom_api_spec.rb
|