andrewallenbruce / provider

Public Healthcare Provider APIs :stethoscope:
https://andrewallenbruce.github.io/provider/
Other
18 stars 2 forks source link

Better Support for Taxonomy Codes #20

Closed andrewallenbruce closed 3 months ago

andrewallenbruce commented 8 months ago

Exploring the possibility of an implementation of retrieval and storage of the most current set of the NUCC Taxonomy Codeset.

nucc <- download_nucc_csv()

#> # A tibble: 874 × 7
#>    taxonomy_code taxonomy_category taxonomy_grouping      taxonomy_classificat…¹
#>    <chr>         <chr>             <chr>                  <chr>                 
#>  1 193200000X    Individual        Group                  Multi-Specialty       
#>  2 193400000X    Individual        Group                  Single Specialty      
#>  3 207K00000X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  4 207KA0200X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  5 207KI0005X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  6 207L00000X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  7 207LA0401X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  8 207LC0200X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  9 207LH0002X    Individual        Allopathic & Osteopat… Anesthesiology        
#> 10 207LP2900X    Individual        Allopathic & Osteopat… Anesthesiology        
#> # ℹ 864 more rows
#> # ℹ abbreviated name: ¹​taxonomy_classification
#> # ℹ 3 more variables: taxonomy_specialization <chr>,
#> #   taxonomy_display_name <chr>, taxonomy_definition <chr>

Step 1: Get the provider's NPIs from their Medicare Enrollment

liz <- providers(organization = "Elizabethtown Community Hospital")

#> # A tibble: 4 × 7
#>   npi        pac   enid  specialty_code specialty_description 
#>   <chr>      <chr> <chr> <chr>          <chr>                        
#> 1 1891785184 3577… O200… 12-70          PART B SUPPLIER - CLINIC/GROUP PRACTICE
#> 2 1891785184 3577… O201… 00-85          PART A PROVIDER - CRITICAL ACCESS HOSPITAL
#> 3 1487923637 3577… O201… 12-59          PART B SUPPLIER - AMBULANCE SERVICE SUPPLIER
#> 4 1407061591 3577… O202… 00-85          PART A PROVIDER - CRITICAL ACCESS HOSPITAL 

Step 2: Get the provider's Taxonomy Codes from NPPES

npi <- unique(liz$npi) |> map_dfr(~nppes(npi = .x))

#> # A tibble: 3 × 3
#>   tx_code    tx_primary tx_desc                                     
#>   <chr>      <chr>      <chr>                                       
#> 1 282NC0060X TRUE       General Acute Care Hospital, Critical Access
#> 2 341600000X TRUE       Ambulance                                   
#> 3 275N00000X TRUE       Medicare Defined Swing Bed Unit

Step 3: Crosswalk the Taxonomies to Medicare Specialties

xwalk2 <- npi |> 
  pull(tx_code) |> 
  map_dfr(~taxonomy_crosswalk(taxonomy_code = .x))
#> ✖ No results for taxonomy_code = 341600000X

#> # A tibble: 2 × 3
#>   specialty_code specialty_description       taxonomy_description               
#>   <chr>          <chr>                       <chr>                              
#> 1 A0[7]          Critical Access Hospital    Hospitals/General Acute Care Hospi…
#> 2 A0[7]          Hospital-Swing Bed Approved Hospital Units/Medicare Defined Sw…

Step 4: Join Specialty data with the Taxonomy dataset

tax <- xwalk2 |> 
  inner_join(nucc, by = join_by(taxonomy_code))

#> Rows: 2
#> Columns: 5
#> $ specialty_code          <chr> "A0[7]", "A0[7]"
#> $ specialty_description   <chr> "Critical Access Hospital", "Hospital-Swing Be…
#> $ taxonomy_category       <chr> "Non-Individual", "Non-Individual"
#> $ taxonomy_grouping       <chr> "Hospitals", "Hospital Units"
#> $ taxonomy_classification <chr> "General Acute Care Hospital", "Medicare Defin…

Created on 2023-10-15 with reprex v2.0.2

andrewallenbruce commented 8 months ago

Testing out an implementation of the {pins} package, could wrap this approach into a function:

library(pins)
library(provider)

github_raw <- function(x) paste0("https://raw.githubusercontent.com/", x)

board <- board_url(github_raw("andrewallenbruce/provider/main/pkgdown/assets/pins-board/"))

board
#> Pin board <pins_board_url>
#> Cache size: 85.2K

board |> pin_list()
#> [1] "taxonomy_codes"

board |> pin_versions("taxonomy_codes")
#> # A tibble: 1 × 3
#>   version                created             hash 
#>   <chr>                  <dttm>              <chr>
#> 1 20231015T181028Z-2e167 2023-10-15 14:10:28 2e167

board |> pin_read("taxonomy_codes")
#> # A tibble: 874 × 9
#>    taxonomy_code taxonomy_category taxonomy_grouping      taxonomy_classificat…¹
#>    <chr>         <chr>             <chr>                  <chr>                 
#>  1 193200000X    Individual        Group                  Multi-Specialty       
#>  2 193400000X    Individual        Group                  Single Specialty      
#>  3 207K00000X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  4 207KA0200X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  5 207KI0005X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  6 207L00000X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  7 207LA0401X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  8 207LC0200X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  9 207LH0002X    Individual        Allopathic & Osteopat… Anesthesiology        
#> 10 207LP2900X    Individual        Allopathic & Osteopat… Anesthesiology        
#> # ℹ 864 more rows
#> # ℹ abbreviated name: ¹​taxonomy_classification
#> # ℹ 5 more variables: taxonomy_specialization <chr>,
#> #   taxonomy_display_name <chr>, taxonomy_definition <chr>, version <dbl>,
#> #   release_date <date>

Created on 2023-10-16 with reprex v2.0.2

andrewallenbruce commented 7 months ago
library(provider)

taxonomy_codes(shape = 'wide')
#> # A tibble: 874 × 9
#>    taxonomy_code taxonomy_category taxonomy_grouping      taxonomy_classificat…¹
#>    <chr>         <chr>             <chr>                  <chr>                 
#>  1 193200000X    Individual        Group                  Multi-Specialty       
#>  2 193400000X    Individual        Group                  Single Specialty      
#>  3 207K00000X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  4 207KA0200X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  5 207KI0005X    Individual        Allopathic & Osteopat… Allergy & Immunology  
#>  6 207L00000X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  7 207LA0401X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  8 207LC0200X    Individual        Allopathic & Osteopat… Anesthesiology        
#>  9 207LH0002X    Individual        Allopathic & Osteopat… Anesthesiology        
#> 10 207LP2900X    Individual        Allopathic & Osteopat… Anesthesiology        
#> # ℹ 864 more rows
#> # ℹ abbreviated name: ¹​taxonomy_classification
#> # ℹ 5 more variables: taxonomy_specialization <chr>,
#> #   taxonomy_display_name <chr>, taxonomy_definition <chr>, version <dbl>,
#> #   release_date <date>

taxonomy_codes(shape = 'long')
#> # A tibble: 3,255 × 3
#>    Code       Level               Description                        
#>    <chr>      <ord>               <chr>                              
#>  1 193200000X I. Category         Individual                         
#>  2 193200000X II. Grouping        Group                              
#>  3 193200000X III. Classification Multi-Specialty                    
#>  4 193400000X I. Category         Individual                         
#>  5 193400000X II. Grouping        Group                              
#>  6 193400000X III. Classification Single Specialty                   
#>  7 207K00000X I. Category         Individual                         
#>  8 207K00000X II. Grouping        Allopathic & Osteopathic Physicians
#>  9 207K00000X III. Classification Allergy & Immunology               
#> 10 207KA0200X I. Category         Individual                         
#> # ℹ 3,245 more rows

Created on 2023-11-19 with reprex v2.0.2