7  Comprehensive Search

Individual Provider

individual_search <- function(npi) {
  
  dplyr::lst(
    nppes        = provider::nppes(npi = npi),
    enrollment   = provider::providers(npi = npi),
    order_refer  = provider::order_refer(npi = npi, pivot = FALSE),
    reassignment = provider::reassignments(npi = npi),
    clinician    = provider::clinicians(npi = npi),
    affiliations = provider::affiliations(npi = npi) |> 
      _[["facility_ccn"]] |> 
      purrr::map_dfr(\(x) provider::hospitals(facility_ccn = x)) |> 
      funique(cols = c(1:20)),
    taxonomy = handle_na(sbt(
        arktax::taxonomy_raw(taxonomy_code = nppes$tx_code), 
        year == fmax(year) & version == fmax(version))
      ))
}

x <- individual_search(npi = 1043245657)

x |> 
  purse()
- $nppes       $npi                   c1  1043245657                        ...
- $nppes       $entity_type           f1  Individual                        ...
- $nppes       $enum_date             D1  2006-07-11                        ...
- $nppes       $last_update           D1  2013-10-08                        ...
- $nppes       $status                f1  Active                            ...
- $nppes       $prefix                c1  Dr.                               ...
- $nppes       $first                 c1  MARK                              ...
- $nppes       $middle                c1  K                                 ...
- $nppes       $last                  c1  FUNG                              ...
- $nppes       $gender                f1  Unknown                           ...
- $nppes       $credential            c1  MD, PhD                           ...
- $nppes       $sole_prop             l1  F                                 ...
- $nppes       $purpose               f1  Practice                          ...
- $nppes       $address               c1  111 COLCHESTER AVE FLETCHER ALLEN ...
- $nppes       $city                  c1  BURLINGTON                        ...
- $nppes       $state                 f1  VT                                ...
- $nppes       $zip                   c1  054011473                         ...
- $nppes       $country               c1  US                                ...
- $nppes       $phone                 c1  802-847-3000                      ...
- $nppes       $fax                   c1  802-847-3509                      ...
- $nppes       $tx_code               c1  207ZB0001X                        ...
- $nppes       $tx_primary            l1  T                                 ...
- $nppes       $tx_desc               c1  Pathology, Blood Banking & Transf ...
- $nppes       $tx_license            c1  042-0010655                       ...
- $nppes       $tx_state              f1  VT                                ...
- $nppes       $id_code               c1  05                                ...
- $nppes       $id_desc               c1  MEDICAID                          ...
- $nppes       $id_state              f1  VT                                ...
- $nppes       $id_identifier         c1  1010070                           ...
- $enrollment  $npi                   c1  1043245657              
- $enrollment  $pac                   c1  7810891009              
- $enrollment  $enid                  c1  I20031120000251         
- $enrollment  $specialty_code        c1  14-22                   
- $enrollment  $specialty_description c1  PRACTITIONER - PATHOLOGY
- $enrollment  $state                 f1  VT                      
- $enrollment  $first                 c1  MARK                    
- $enrollment  $middle                c1  K                       
- $enrollment  $last                  c1  FUNG                    
- $enrollment  $gender                f1  Male                    
- $order_refer $npi                   c1  1043245657
- $order_refer $last_name             c1  FUNG      
- $order_refer $first_name            c1  MARK      
- $order_refer $partb                 l1  T         
- $order_refer $dme                   l1  T         
- $order_refer $hha                   l1  T         
- $order_refer $pmd                   l1  T         
- $order_refer $hospice               l1  T         
- $reassignment$npi                   c1  1043245657                        ...
- $reassignment$pac                   c1  7810891009                        ...
- $reassignment$enid                  c1  I20031120000251                   ...
- $reassignment$first                 c1  MARK                              ...
- $reassignment$last                  c1  FUNG                              ...
- $reassignment$associations          i1  1                                 ...
- $reassignment$organization          c1  UNIVERSITY OF VERMONT MEDICAL CEN ...
- $reassignment$pac_org               c1  3779491071                        ...
- $reassignment$enid_org              c1  O20060822000040                   ...
- $reassignment$state_org             f1  VT                                ...
- $reassignment$reassignments         i1  97                                ...
- $reassignment$entry                 f1  Reassignment                      ...
- $clinician   $npi                   c1  1043245657                        ...
- $clinician   $pac                   c1  7810891009                        ...
- $clinician   $enid                  c1  I20031120000251                   ...
- $clinician   $first                 c1  MARK                              ...
- $clinician   $middle                c1  K                                 ...
- $clinician   $last                  c1  FUNG                              ...
- $clinician   $gender                f1  Male                              ...
- $clinician   $credential            c1  MD                                ...
- $clinician   $school                c1  UNIVERSITY OF ALABAMA SCHOOL OF M ...
- $clinician   $grad_year             i1  1999                              ...
- $clinician   $specialty             c1  PATHOLOGY                         ...
- $clinician   $facility_name         c1  UNIVERSITY OF VERMONT MEDICAL CEN ...
- $clinician   $pac_org               c1  3779491071                        ...
- $clinician   $members_org           i1  1027                              ...
- $clinician   $address_org           c1  111 COLCHESTER AVE                ...
- $clinician   $city_org              c1  BURLINGTON                        ...
- $clinician   $state_org             f1  VT                                ...
- $clinician   $zip_org               c1  054011473                         ...
- $clinician   $phone_org             c1  8028470000                        ...
- $affiliations$npi_org               c3  1033270699                        ...
- $affiliations$pac_org               c3  2769396878                        ...
- $affiliations$enid_org              c3  O20120110000201                   ...
- $affiliations$enid_state            f3  NY                                ...
- $affiliations$facility_ccn          c3  330250                            ...
- $affiliations$organization          c3  CHAMPLAIN VALLEY PHYSICIANS HOSPI ...
- $affiliations$doing_business_as     c3  THE UNIVERSITY OF VT HEALTH NETWO ...
- $affiliations$specialty_code        c3  00-09                             ...
- $affiliations$specialty             c3  PART A PROVIDER - HOSPITAL        ...
- $affiliations$incorp_date           D3  1926-01-01                        ...
- $affiliations$incorp_state          f3  NY                                ...
- $affiliations$structure             c3  CORPORATION                       ...
- $affiliations$address               c3  75 BEEKMAN ST                     ...
- $affiliations$city                  c3  PLATTSBURGH                       ...
- $affiliations$state                 f3  NY                                ...
- $affiliations$zip                   c3  129011438                         ...
- $affiliations$location_type         c3  MAIN/PRIMARY HOSPITAL LOCATION    ...
- $affiliations$registration          f3  Non-Profit                        ...
- $affiliations$multi_npi             l3  F                                 ...
- $affiliations$reh_conversion        l3  F                                 ...
- $affiliations$subgroup              f3  Acute Care                        ...
- $taxonomy    $year                  d1  2024                              ...
- $taxonomy    $version               i1  1                                 ...
- $taxonomy    $code                  c1  207ZB0001X                        ...
- $taxonomy    $display_name          c1  Blood Banking & Transfusion Medic ...
- $taxonomy    $section               c1  Individual                        ...
- $taxonomy    $grouping              c1  Allopathic & Osteopathic Physicia ...
- $taxonomy    $classification        c1  Pathology                         ...
- $taxonomy    $specialization        c1  Blood Banking & Transfusion Medic ...
- $taxonomy    $definition            c1  A physician who specializes in bl ...
- $taxonomy    $notes                 c1  Source: American Board of Medical ...
library(dm)

xdm <- new_dm(x) |> 
  dm_add_pk(nppes, npi) |> 
  dm_add_pk(enrollment, npi) |> 
  dm_add_pk(reassignment, npi) |> 
  dm_add_pk(order_refer, npi) |> 
  dm_add_pk(clinician, npi) |> 
  dm_add_pk(affiliations, facility_ccn) |> 
  # dm_add_pk(hospitals, facility_ccn) |> 
  dm_add_pk(taxonomy, code) |> 
  dm_add_fk(nppes, npi, enrollment) |> 
  dm_add_fk(nppes, tx_code, taxonomy, code) |> 
  # dm_add_fk(nppes, npi, affiliations, npi) |> 
  dm_add_fk(enrollment, npi, clinician) |> 
  dm_add_fk(enrollment, npi, order_refer) |> 
  dm_add_fk(order_refer, npi, reassignment) |> 
  # dm_add_fk(clinician, npi, affiliations, npi) |> 
  dm_add_fk(clinician, pac_org, affiliations, pac_org) |> 
  dm_add_fk(reassignment, pac_org, affiliations, pac_org) |> 
  dm_add_fk(affiliations, facility_ccn, affiliations)

xdm |> 
  dm_set_colors(
    darkblue = nppes,
    tomato = taxonomy,
    mediumpurple = c(enrollment, order_refer, reassignment),
    seagreen = c(clinician, affiliations)) |> 
  dm_draw(
    font_size = c(
      header = 18L, 
      table_description = 9L, 
      column = 15L),
    column_types = TRUE,
    rankdir = "TB")

Organizational Provider

organizational_search <- \(org) {
  dplyr::lst(
    hospitals    = provider::hospitals(organization = org),
    affiliations = purrr::map_dfr(
      uniq_narm(hospitals$facility_ccn),
      \(x) provider::affiliations(facility_ccn = x)) |> 
      handle_na() #,
    # providers = purrr::map_dfr(
    #   uniq_narm(affiliations$npi),
    #   \(x) provider::providers(npi = x)) |> 
    #   handle_na()
  )
}

organizational_search(org = "Elizabethtown Community Hospital") |>
  purse()
- $hospitals   $npi_org        c2  1891785184                               ...
- $hospitals   $pac_org        c2  3577554138                               ...
- $hospitals   $enid_org       c2  O20101110000259                          ...
- $hospitals   $enid_state     f2  NY                                       ...
- $hospitals   $facility_ccn   c2  331302                                   ...
- $hospitals   $organization   c2  ELIZABETHTOWN COMMUNITY HOSPITAL         ...
- $hospitals   $specialty_code c2  00-85                                    ...
- $hospitals   $specialty      c2  PART A PROVIDER - CRITICAL ACCESS HOSPIT ...
- $hospitals   $incorp_date    D2  1926-05-08                               ...
- $hospitals   $incorp_state   f2  NY                                       ...
- $hospitals   $structure      c2  CORPORATION                              ...
- $hospitals   $address        c2  75 PARK ST                               ...
- $hospitals   $city           c2  ELIZABETHTOWN                            ...
- $hospitals   $state          f2  NY                                       ...
- $hospitals   $zip            c2  129322300                                ...
- $hospitals   $location_type  c2  OTHER HOSPITAL PRACTICE LOCATION         ...
- $hospitals   $registration   f2  Non-Profit                               ...
- $hospitals   $multi_npi      l2  T                                        ...
- $hospitals   $reh_conversion l2  F                                        ...
- $hospitals   $subgroup       f2  None                                     ...
- $affiliations$npi            c196 1003815184     1003845272 1013910256    ...
- $affiliations$pac            c196 4082693676     1759384035 5890719371    ...
- $affiliations$first          c196 ARMIN          LAURA      JOSE          ...
- $affiliations$middle         c196 NA             A          M             ...
- $affiliations$last           c196 AFSAR KESHMIRI GREENE     ACOSTAMADIEDO ...
- $affiliations$suffix         c196 NA             NA         NA            ...
- $affiliations$facility_type  f196 Hospital       Hospital   Hospital      ...
- $affiliations$facility_ccn   c196 331302         331302     331302        ...
- $affiliations$parent_ccn     c196 NA             NA         NA            ...