From 108b36c6e36bf10837bd27090b79bc1a7882c021 Mon Sep 17 00:00:00 2001 From: Greg Matthew Crossley Date: Thu, 10 Nov 2022 10:29:57 -0500 Subject: [PATCH 1/4] Update API call to include now-required version number Also update README with object and method names, add test --- README.md | 48 ++++++++++++++++++++++++++++++++++++---- lib/nppes_api.rb | 4 ++++ lib/nppes_api/version.rb | 2 +- spec/nppes_api_spec.rb | 3 +++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fa5bf53..ae917b8 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,56 @@ 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: + - `status` + - `credential` + - `first_name` + - `last_name` + - `middle_name` + - `name` + - `gender` + - `sole_proprietor` + - `last_updated` + - `enumeration_date` + - `addresses`: An array of `NPPESApi::Address` objects, which have the following objects/methods: + - `address_1` + - `address_2` + - `city` + - `state` + - `postal_code` + - `telephone_number` + - `country_code` + - `country_name` + - `address_type` + - `address_purpose` + - `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/version.rb b/lib/nppes_api/version.rb index caace6d..ca4e967 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.0'.freeze end diff --git a/spec/nppes_api_spec.rb b/spec/nppes_api_spec.rb index be8f66b..9e5f7c1 100644 --- a/spec/nppes_api_spec.rb +++ b/spec/nppes_api_spec.rb @@ -4,4 +4,7 @@ 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 end From b2471d6cf1b87938c9f920e08e4f4931cac74bab Mon Sep 17 00:00:00 2001 From: Greg Matthew Crossley Date: Thu, 10 Nov 2022 11:12:08 -0500 Subject: [PATCH 2/4] Added some new / missing attributes to the basic and address objects --- README.md | 22 ++++++++++++---------- lib/nppes_api/address.rb | 9 +++++---- lib/nppes_api/basic.rb | 13 ++++++++----- lib/nppes_api/version.rb | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ae917b8..841fdd7 100644 --- a/README.md +++ b/README.md @@ -40,28 +40,30 @@ A successful `NPPESApi.search()` call will return an `NPPESApi::SearchResults` o - `number` - `other_names` - `identifiers` - - `basic`: an `NPPESApi::Basic` object, which has the following objects/methods: - - `status` - - `credential` + - `basic`: an `NPPESApi::Basic` object, which has the following objects/methods: - `first_name` - `last_name` - `middle_name` - - `name` - - `gender` + - `credential` - `sole_proprietor` - - `last_updated` + - `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` - - `country_code` - - `country_name` - - `address_type` - - `address_purpose` + - `fax_number` - `taxonomies`: An array of `NPPESApi::Taxonomy` objects, which have the following objects/methods: - `state` - `code` 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..2e07016 100644 --- a/lib/nppes_api/basic.rb +++ b/lib/nppes_api/basic.rb @@ -5,16 +5,17 @@ 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 ] methods.each do |meth| @@ -24,3 +25,5 @@ def initialize(data) end end end + + diff --git a/lib/nppes_api/version.rb b/lib/nppes_api/version.rb index ca4e967..12af762 100644 --- a/lib/nppes_api/version.rb +++ b/lib/nppes_api/version.rb @@ -1,3 +1,3 @@ module NPPESApi - VERSION = '1.0.0'.freeze + VERSION = '1.0.1'.freeze end From 1c81188154982e3172d8aa398ddbfa2a0776b7b7 Mon Sep 17 00:00:00 2001 From: Greg Matthew Crossley Date: Thu, 10 Nov 2022 12:44:51 -0500 Subject: [PATCH 3/4] Better handle a nil search --- lib/nppes_api/search_results.rb | 2 +- spec/nppes_api_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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/spec/nppes_api_spec.rb b/spec/nppes_api_spec.rb index 9e5f7c1..bf2b7c7 100644 --- a/spec/nppes_api_spec.rb +++ b/spec/nppes_api_spec.rb @@ -7,4 +7,7 @@ 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 From ed585072997561c7687b2d89f6ebe747a03afb72 Mon Sep 17 00:00:00 2001 From: Jordan Owens Date: Wed, 25 Jan 2023 17:22:57 -0500 Subject: [PATCH 4/4] Add authorized official fields to basic data --- lib/nppes_api/basic.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/nppes_api/basic.rb b/lib/nppes_api/basic.rb index 2e07016..6c3ec0b 100644 --- a/lib/nppes_api/basic.rb +++ b/lib/nppes_api/basic.rb @@ -15,7 +15,15 @@ def initialize(data) :last_updated, :status, :name_prefix, - :name_suffix + :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|