diff --git a/README.md b/README.md index fa5bf53..841fdd7 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,58 @@ Or install it yourself as: $ gem install nppes_api ## Usage - -The entrypoint for searches is at NPPESApi.search. See the code in lib/nppes_api.rb for information on the options that you can pass, -which are the same as the ones [described by NPPES](https://npiregistry.cms.hhs.gov/api/demo). A successful search will return an -NPPESApi::SearchResults object, from which you can call methods to retrieve data or call the raw_data method to get the original JSON. +The entrypoint for searches is at NPPESApi.search. See the code in `lib/nppes_api.rb` for information on the options that you can pass, which are the same as the ones [described by NPPES](https://npiregistry.cms.hhs.gov/api-page). A successful search will return an +`NPPESApi::SearchResults` object, from which you can call methods to retrieve data or call the `raw_data` method to get the original JSON. Here is an example query: ``` NPPESApi.search(number: 1932494937).results.first.taxonomies.first.state #=> 'NC' ``` +## Search Results Methods and Objects +A successful `NPPESApi.search()` call will return an `NPPESApi::SearchResults` object, which contains the following objects/methods: + +- `raw_data`: The raw JSON returned by the NPPES API, as a Hash +- `result_count`: The number of results returned by the search +- `results`: An array of `NPPESApi::Provider` objects, which have the following objects/methods: + - `created_epoch` + - `enumeration_type` + - `last_updated_epoch` + - `number` + - `other_names` + - `identifiers` + - `basic`: an `NPPESApi::Basic` object, which has the following objects/methods: + - `first_name` + - `last_name` + - `middle_name` + - `credential` + - `sole_proprietor` + - `gender` + - `enumeration_date` + - `last_updated` + - `status` + - `name_prefix` + - `name_suffix` + - `addresses`: An array of `NPPESApi::Address` objects, which have the following objects/methods: + - `country_code` + - `country_name` + - `address_purpose` + - `address_type` + - `address_1` + - `address_2` + - `city` + - `state` + - `postal_code` + - `telephone_number` + - `fax_number` + - `taxonomies`: An array of `NPPESApi::Taxonomy` objects, which have the following objects/methods: + - `state` + - `code` + - `primary` + - `license` + - `des` + + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/lib/nppes_api.rb b/lib/nppes_api.rb index 340b42e..3997fa8 100644 --- a/lib/nppes_api.rb +++ b/lib/nppes_api.rb @@ -38,6 +38,10 @@ module NPPESApi # @param limit [Integer] Limit results, default = 10, max = 200 # @param skip [Integer] Skip first N results, max = 1000 def self.search(options = {}) + # Append the API version number to the options hash. + # Note that as of November 2022, the latest API version is 2.1, according to + # https://npiregistry.cms.hhs.gov/api-page + options[:version] = '2.1' # this version flag is required as of version 2.1 SearchResults.new(RestClient.get('https://npiregistry.cms.hhs.gov/api', params: options).body) end end diff --git a/lib/nppes_api/address.rb b/lib/nppes_api/address.rb index d29016a..a94e1fe 100644 --- a/lib/nppes_api/address.rb +++ b/lib/nppes_api/address.rb @@ -5,16 +5,17 @@ def initialize(data) end methods = [ + :country_code, + :country_name, + :address_purpose, + :address_type, :address_1, :address_2, :city, :state, :postal_code, :telephone_number, - :country_code, - :country_name, - :address_type, - :address_purpose + :fax_number ] methods.each do |meth| diff --git a/lib/nppes_api/basic.rb b/lib/nppes_api/basic.rb index e0b4f22..6c3ec0b 100644 --- a/lib/nppes_api/basic.rb +++ b/lib/nppes_api/basic.rb @@ -5,16 +5,25 @@ def initialize(data) end methods = [ - :status, - :credential, :first_name, :last_name, :middle_name, - :name, - :gender, + :credential, :sole_proprietor, + :gender, + :enumeration_date, :last_updated, - :enumeration_date + :status, + :name_prefix, + :name_suffix, + :authorized_official_first_name, + :authorized_official_last_name, + :authorized_official_middle_name, + :authorized_official_title_or_position, + :authorized_official_telephone_number, + :authorized_official_name_prefix, + :authorized_official_name_suffix, + :authorized_official_credential ] methods.each do |meth| @@ -24,3 +33,5 @@ def initialize(data) end end end + + diff --git a/lib/nppes_api/search_results.rb b/lib/nppes_api/search_results.rb index 560f714..43510aa 100644 --- a/lib/nppes_api/search_results.rb +++ b/lib/nppes_api/search_results.rb @@ -15,7 +15,7 @@ def result_count end def results - @results ||= @data['results'].map { |i| Provider.new(i) } + @results ||= @data['results']&.map { |i| Provider.new(i) } end end end diff --git a/lib/nppes_api/version.rb b/lib/nppes_api/version.rb index caace6d..12af762 100644 --- a/lib/nppes_api/version.rb +++ b/lib/nppes_api/version.rb @@ -1,3 +1,3 @@ module NPPESApi - VERSION = '0.1.1'.freeze + VERSION = '1.0.1'.freeze end diff --git a/spec/nppes_api_spec.rb b/spec/nppes_api_spec.rb index be8f66b..bf2b7c7 100644 --- a/spec/nppes_api_spec.rb +++ b/spec/nppes_api_spec.rb @@ -4,4 +4,10 @@ it 'has a version number' do expect(NPPESApi::VERSION).not_to be nil end + it 'successfully searches for a provider' do + expect(NPPESApi.search(number: 1932494937).results.first.taxonomies.first.state).to eq('NC') + end + it 'gracefully handles a nil search' do + expect(NPPESApi.search(number: 00000000).results).to be_nil + end end