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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79978a9d395de7d6641f7d7e7c701303fe64a2f8
4
- data.tar.gz: 471a65706596e3e316327446a825558383cac87d
3
+ metadata.gz: 88cb09f4c7f006ec69a48ebaaa50d50ea57b486b
4
+ data.tar.gz: 2fe80966cb4bccfcfaf00c38bcb1c7e45504f4ef
5
5
  SHA512:
6
- metadata.gz: 68cd0f7cfae9037ffe1bae9b85d14f944c49966883ba8531ba0a6fb90b21f93ceeaa888cbd5c6d944c97434c6b9fee51d6df257ab94edb953d098c36b9b4b78b
7
- data.tar.gz: 82ef03b48b114787326117066163cea9c0a243859aac751e45cd495913e6ae4ed266aaea4a9f5a46360bfe37c1d0f2550a2a4bce5c2591208d3a09d6b157d6b0
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
- # .ruby-version
31
- # .ruby-gemset
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bloom_api (0.0.1)
4
+ bloom_api (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- return Individual.new(response) if response['type'] == 'individual'
42
- return Organization.new(response) if response['type'] == 'organization'
43
- Provider.new(response)
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
@@ -1,4 +1,4 @@
1
1
  module BloomApi
2
2
  # the gem's version
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
@@ -1,6 +1,6 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
- describe BloomApi::Api do
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::Api.find_by_npi(npi) }
11
+ subject { BloomApi.find_by_npi(npi) }
12
12
 
13
13
  context 'when given a valid npi' do
14
14
  let(:npi) { '1003002809' }
@@ -3,48 +3,114 @@ require 'JSON'
3
3
 
4
4
  describe BloomApi do
5
5
 
6
- describe '#find_by_npi' do
6
+ describe '#find_by_npi' do
7
7
 
8
- subject { BloomApi.find_by_npi(npi) }
8
+ subject { BloomApi.find_by_npi(npi) }
9
9
 
10
10
 
11
- context 'when given a valid npi' do
12
- context 'for an individual' do
13
- let(:npi) { '1003002809' }
11
+ context 'when given a valid npi' do
12
+ context 'for an individual' do
13
+ let(:npi) { '1003002809' }
14
14
 
15
- it { expect(subject).to be_a BloomApi::Individual }
15
+ it { expect(subject).to be_a BloomApi::Individual }
16
16
 
17
- it 'returns the right provider' do
18
- provider = subject
19
- expect(provider.npi).to eq '1003002809'
20
- end
21
- end
17
+ it 'returns the right provider' do
18
+ provider = subject
19
+ expect(provider.npi).to eq '1003002809'
20
+ end
21
+ end
22
22
 
23
- context 'for an organization' do
24
- let(:npi) { '1013191311' }
23
+ context 'for an organization' do
24
+ let(:npi) { '1013191311' }
25
25
 
26
- it { expect(subject).to be_a BloomApi::Organization }
26
+ it { expect(subject).to be_a BloomApi::Organization }
27
27
 
28
- it 'returns the right provider' do
29
- expect(subject.npi).to eq '1013191311'
30
- end
31
- end
28
+ it 'returns the right provider' do
29
+ expect(subject.npi).to eq '1013191311'
30
+ end
31
+ end
32
32
 
33
- context 'when type is not present' do
34
- let(:npi) { '1003998626' }
33
+ context 'when type is not present' do
34
+ let(:npi) { '1003998626' }
35
35
 
36
- it { expect(subject).to be_a BloomApi::Provider }
36
+ it { expect(subject).to be_a BloomApi::Provider }
37
37
 
38
- end
39
- end
38
+ end
39
+ end
40
40
 
41
- context 'when given an invalid npi' do
42
- let(:npi) { 'bogus_npi' }
41
+ context 'when given an invalid npi' do
42
+ let(:npi) { 'bogus_npi' }
43
43
 
44
- it 'returns nil' do
45
- expect(subject).to be_nil
46
- end
47
- end
44
+ it 'returns nil' do
45
+ expect(subject).to be_nil
46
+ end
47
+ end
48
48
 
49
- end
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.2
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: 2014-12-14 00:00:00.000000000 Z
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
@@ -1,7 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe BloomApi::ProviderLookup do
4
-
5
-
6
-
7
- end