Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/nppes_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions lib/nppes_api/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
21 changes: 16 additions & 5 deletions lib/nppes_api/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -24,3 +33,5 @@ def initialize(data)
end
end
end


2 changes: 1 addition & 1 deletion lib/nppes_api/search_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/nppes_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NPPESApi
VERSION = '0.1.1'.freeze
VERSION = '1.0.1'.freeze
end
6 changes: 6 additions & 0 deletions spec/nppes_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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