Introduction to npi

library(npi)

This vignette provides an brief introduction to the npi package.

npi is an R package that allows R users to access the U.S. National Provider Identifier (NPI) Registry API by the Center for Medicare and Medicaid Services (CMS).

The package makes it easy to obtain administrative data linked to a specific individual or organizational healthcare provider. Additionally, users can perform advanced searches based on provider name, location, type of service, credentials, and many other attributes.

Search registry

To explore organizational providers with primary locations in New York City, we could use the city argument in the npi_search(). The nyc dataset here finds 10 organizational providers with primary locations in New York City, since 10 is the default number of records that are returned in npi_search(). The response is a tibble that has high-cardinality data organized into list columns.

nyc <- npi_search(city = "New York City")
#> 10 records requested
#> Requesting records 0-10...
nyc
#> # A tibble: 10 × 11
#>    npi    enumeration_type basic    other_names identifiers taxonomies addresses
#>  * <chr>  <chr>            <list>   <list>      <list>      <list>     <list>   
#>  1 12658… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  2 16796… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  3 19822… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  4 14873… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  5 15889… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  6 17309… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  7 16297… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  8 16391… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  9 14579… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> 10 11842… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> # ℹ 4 more variables: practice_locations <list>, endpoints <list>,
#> #   created_date <dttm>, last_updated_date <dttm>

Other search arguments for the function include number, enumeration_type, taxonomy_description, first_name, last_name, use_first_name_alias, organization_name, address_purpose, state, postal_code, country_code, and limit.

Additionally, more than one search argument can be used at once.

nyc_multi <- npi_search(city = "New York City", state = "NY", enumeration_type = "org")
#> 10 records requested
#> Requesting records 0-10...
nyc_multi
#> # A tibble: 10 × 11
#>    npi    enumeration_type basic    other_names identifiers taxonomies addresses
#>  * <chr>  <chr>            <list>   <list>      <list>      <list>     <list>   
#>  1 16398… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  2 19520… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  3 10034… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  4 13465… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  5 19728… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  6 12251… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  7 16292… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  8 17302… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  9 11849… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> 10 17601… Organization     <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> # ℹ 4 more variables: practice_locations <list>, endpoints <list>,
#> #   created_date <dttm>, last_updated_date <dttm>

Visit the function’s help page via ?npi_search after installing and loading the package for more details.

Increasing number of records returned

The limit argument of npi_search() lets you set the maximum records to return from 1 to 1200 inclusive, defaulting to 10 records if no value is specified.

nyc_25 <- npi_search(city = "New York City", limit = 25)
#> 25 records requested
#> Requesting records 0-25...
nyc_25
#> # A tibble: 25 × 11
#>    npi    enumeration_type basic    other_names identifiers taxonomies addresses
#>  * <chr>  <chr>            <list>   <list>      <list>      <list>     <list>   
#>  1 12658… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  2 16796… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  3 19822… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  4 14873… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  5 15889… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  6 17309… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  7 16297… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  8 16391… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  9 14579… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> 10 11842… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> # ℹ 15 more rows
#> # ℹ 4 more variables: practice_locations <list>, endpoints <list>,
#> #   created_date <dttm>, last_updated_date <dttm>

When using npi_search(), searches with greater than 200 records (for example 300 records) may result in multiple API calls. This is because the API itself returns up to 200 records per request, but allows previously requested records to be skipped. npi_search() will automatically make additional API calls up to the API’s limit of 1200 records for a unique set of query parameter values, and will still return a single tibble. However, to save time, the function only makes additional requests if needed. For example, if you request 1200 records, and 199 are returned in the first request, then the function does not need to make a second request because there are no more records to return.

nyc_300 <- npi_search(city = "New York City", limit = 300)
#> 300 records requested
#> Requesting records 0-200...
#> Requesting records 200-300...
nyc_300
#> # A tibble: 300 × 11
#>    npi    enumeration_type basic    other_names identifiers taxonomies addresses
#>  * <chr>  <chr>            <list>   <list>      <list>      <list>     <list>   
#>  1 12658… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  2 16796… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  3 19822… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  4 14873… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  5 15889… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  6 17309… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  7 16297… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  8 16391… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#>  9 14579… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> 10 11842… Individual       <tibble> <tibble>    <tibble>    <tibble>   <tibble> 
#> # ℹ 290 more rows
#> # ℹ 4 more variables: practice_locations <list>, endpoints <list>,
#> #   created_date <dttm>, last_updated_date <dttm>

The NPPES API documentation does not specify additional API rate limitations. However, if you need more than 1200 NPI records for a set of search terms, you will need to download the NPPES Data Dissemination File.

Obtaining more human-readable output

npi_summarize() provides a more human-readable overview of output already obtained through npi_search().

npi_summarize(nyc)
#> # A tibble: 10 × 6
#>    npi      name  enumeration_type primary_practice_add…¹ phone primary_taxonomy
#>    <chr>    <chr> <chr>            <chr>                  <chr> <chr>           
#>  1 1265829… MARK… Individual       1090 AMSTERDAM AVENUE… 212-… Otolaryngology  
#>  2 1679656… JUDI… Individual       425 RIVERSIDE DR #8C,… 212-… Psychiatry & Ne…
#>  3 1982278… UNKN… Individual       WESTCHESTER MEDICAL C… 914-… Student in an O…
#>  4 1487341… RAKS… Individual       JACOBI MEDICAL CENTER… 718-… Student in an O…
#>  5 1588940… DANI… Individual       1 GUSTAVE LEVY PLACE … 212-… Emergency Medic…
#>  6 1730931… SAI … Individual       1545 ATLANTIC AVENUE,… 718-… Student in an O…
#>  7 1629701… MOHA… Individual       <NA>                   212-… Social Worker   
#>  8 1639133… MIRI… Individual       325 EAST 80TH ST #1C,… 212-… Social Worker, …
#>  9 1457926… MAHM… Individual       NEW YORK PRESBYTERIAN… 718-… Student in an O…
#> 10 1184244… ABDU… Individual       <NA>                   646-… Student in an O…
#> # ℹ abbreviated name: ¹​primary_practice_address

Additionally, users can flatten all the list columns using npi_flatten().

npi_flatten(nyc)
#> # A tibble: 28 × 56
#>    npi       basic_first_name basic_last_name basic_sole_proprietor basic_gender
#>    <chr>     <chr>            <chr>           <chr>                 <chr>       
#>  1 11842447… ABDULLAH         ALANAZI         NO                    M           
#>  2 11842447… ABDULLAH         ALANAZI         NO                    M           
#>  3 12658296… MARK             ABROMS          NO                    M           
#>  4 12658296… MARK             ABROMS          NO                    M           
#>  5 14579269… MAHMOOD          AL-ORPHALY      NO                    M           
#>  6 14579269… MAHMOOD          AL-ORPHALY      NO                    M           
#>  7 14873414… RAKSHEETH        AGARWAL         NO                    M           
#>  8 14873414… RAKSHEETH        AGARWAL         NO                    M           
#>  9 15889404… DANISH           AHMAD           NO                    M           
#> 10 15889404… DANISH           AHMAD           NO                    M           
#> # ℹ 18 more rows
#> # ℹ 51 more variables: basic_enumeration_date <chr>, basic_last_updated <chr>,
#> #   basic_certification_date <chr>, basic_status <chr>,
#> #   basic_middle_name <chr>, basic_credential <chr>, basic_name_prefix <chr>,
#> #   basic_name_suffix <chr>, other_names_type <chr>, other_names_code <chr>,
#> #   other_names_first_name <chr>, other_names_last_name <chr>,
#> #   other_names_middle_name <chr>, other_names_prefix <chr>, …

Alternatively, individual columns can be flattened for each npi by using the cols argument. Only the columns specified will be flattened and returned with the npi column by default.

npi_flatten(nyc, cols = c("basic", "taxonomies"))
#> # A tibble: 12 × 19
#>    npi       basic_first_name basic_last_name basic_sole_proprietor basic_gender
#>    <chr>     <chr>            <chr>           <chr>                 <chr>       
#>  1 11842447… ABDULLAH         ALANAZI         NO                    M           
#>  2 12658296… MARK             ABROMS          NO                    M           
#>  3 14579269… MAHMOOD          AL-ORPHALY      NO                    M           
#>  4 14873414… RAKSHEETH        AGARWAL         NO                    M           
#>  5 15889404… DANISH           AHMAD           NO                    M           
#>  6 15889404… DANISH           AHMAD           NO                    M           
#>  7 16297013… MOHAMMED         AKHTAR          NO                    M           
#>  8 16391339… MIRIAM           AKINS           YES                   F           
#>  9 16391339… MIRIAM           AKINS           YES                   F           
#> 10 16796561… JUDITH           ADELSON         YES                   F           
#> 11 17309314… SAI ANUSHA       AKELLA          NO                    F           
#> 12 19822783… UNKNOWN          ADILA           NO                    F           
#> # ℹ 14 more variables: basic_enumeration_date <chr>, basic_last_updated <chr>,
#> #   basic_certification_date <chr>, basic_status <chr>,
#> #   basic_middle_name <chr>, basic_credential <chr>, basic_name_prefix <chr>,
#> #   basic_name_suffix <chr>, taxonomies_code <chr>,
#> #   taxonomies_taxonomy_group <chr>, taxonomies_desc <chr>,
#> #   taxonomies_state <chr>, taxonomies_license <chr>, taxonomies_primary <lgl>