34  Geospatial

underscore <- \(x) gsub("___owner$", "", x, perl = TRUE)
char_binary <- \(x) val_match(x, "N" ~ 0L, "Y" ~ 1L)
pct_prop <- \(x) {
  cheapr::case(
    x == "0" ~ 0,
    cheapr::is_na(x) ~ NA_real_,
    .default = as.double(x) / 100
  )
}

Load Packages

Rural Health Clinics

req <- careGroup("rural_health")@groups |>
  _[["rural_health_clinic_enrollments"]] |>
  _[["endpoints"]] |>
  _[["identifier"]] |>
  request() |> 
  req_url_query(
    "filter[STATE]" = "GA"
  )

nres <- req |> 
  req_url_path_append("stats") |>
  providertwo:::perform_simple() |> 
  _[["data"]] |> 
  _[["found_rows"]]

res <- req |> 
  req_url_query(offset = 0L, size = 5000L) |> 
  req_perform() |> 
  providertwo:::resp_simple_json() |> 
  get_elem("^data$|headers", regex = TRUE)

rhc_enr <- as_tbl(res$data) |> 
  set_names(res$meta) |> 
  providertwo:::map_na_if() |> 
  roworder(`ORGANIZATION NAME`) |>
  janitor::clean_names() |>
  mtt(incorporation_date = providertwo:::as_date(incorporation_date),
      multiple_npi_flag = char_binary(multiple_npi_flag),
      address = cheapr_if_else(
        cheapr::is_na(address_line_2), 
        address_line_1, 
        paste(address_line_1, address_line_2))) |>
  slt(
    npi,
    has_mult_npi = multiple_npi_flag,
    ccn,
    pac = associate_id,
    enid = enrollment_id,
    enid_state = enrollment_state,
    org_name = organization_name,
    dba_name = doing_business_as_name,
    inc_date = incorporation_date,
    inc_state = incorporation_state,
    org_type = organization_type_structure,
    org_type_2 = organization_other_type_text,
    proprietary_nonprofit,
    address,
    city,
    state,
    zip = zip_code)


rhc_enr |> 
  purse()
#> - $npi                   c85 1639774714                        1174104657   ...
#> - $has_mult_npi          i85 0                                 0            ...
#> - $ccn                   c85 118915                            118917       ...
#> - $pac                   c85 2961814694                        2961814694   ...
#> - $enid                  c85 O20210409001138                   O20211123003 ...
#> - $enid_state            c85 GA                                GA           ...
#> - $org_name              c85 ACCESS MEDICAL CLINIC GEORGIA LLC ACCESS MEDIC ...
#> - $dba_name              c85 NA                                NA           ...
#> - $inc_date              D85 2020-07-29                        2021-01-11   ...
#> - $inc_state             c85 GA                                GA           ...
#> - $org_type              c85 LLC                               LLC          ...
#> - $org_type_2            c85 NA                                NA           ...
#> - $proprietary_nonprofit c85 P                                 P            ...
#> - $address               c85 304 N WESTBERRY ST                37 341 BYP   ...
#> - $city                  c85 SYLVESTER                         HAWKINSVILLE ...
#> - $state                 c85 GA                                GA           ...
#> - $zip                   c85 317912125                         310364839    ...
req <- careGroup("rural_health")@groups |>
  _[["rural_health_clinic_all_owners"]] |> 
  _[["endpoints"]] |>
  _[["identifier"]] |>
  request() |> 
  req_url_query("filter[STATE - OWNER]" = "GA")

nres <- req |> 
  req_url_path_append("stats") |>
  providertwo:::perform_simple() |> 
  _[["data"]] |> 
  _[["found_rows"]]

res <- req |> 
  req_url_query(offset = 0L, size = 5000L) |> 
  req_perform() |> 
  providertwo:::resp_simple_json() |> 
  get_elem("^data$|headers", regex = TRUE)

rhc_owner <- as_tbl(res$data) |> 
  set_names(res$meta) |> 
  providertwo:::map_na_if() |> 
  janitor::clean_names() |> 
  rnm(
    enid = enrollment_id,
    pac = associate_id_owner, 
    org_name = organization_name) |>
  mtt(
    association_date = providertwo:::as_date(association_date_owner),
    address = cheapr_if_else(cheapr::is_na(address_line_2_owner), address_line_1_owner, paste(address_line_1_owner, address_line_2_owner)),
    percentage_ownership = as.numeric(percentage_ownership),
    role_code = as.integer(role_code_owner)
  ) |>
  slt(
    pac,
    enid,
    org_name,
    pac_owner = associate_id, 
    org_name_owner = organization_name_owner,
    entity = type_owner,
    role_code,
    role_text = role_text_owner,
    association_date_owner,
    first_name_owner,
    middle_name_owner,
    last_name_owner,
    title_owner,
    dba_name = doing_business_as_name_owner,
    address,
    city_owner,
    state_owner,
    zip = zip_code_owner,
    percentage_ownership,
    is_for_acq = created_for_acquisition_owner,
    is_corp = corporation_owner,
    is_llc = llc_owner,
    is_med_prov_supp = medical_provider_supplier_owner,
    is_mgmt_serv_co = management_services_company_owner,
    is_med_staff_co = medical_staffing_company_owner,
    is_holding_co = holding_company_owner,
    is_invest_firm = investment_firm_owner,
    is_fin_inst = financial_institution_owner,
    is_consult_firm = consulting_firm_owner,
    is_for_profit = for_profit_owner,
    is_non_profit = non_profit_owner,
    is_other_type = other_type_owner,
    other_type = other_type_text_owner
  ) |> 
  mtt(
    is_for_acq = char_binary(is_for_acq),
    is_corp = char_binary(is_corp),
    is_llc = char_binary(is_llc),
    is_med_prov_supp = char_binary(is_med_prov_supp),
    is_mgmt_serv_co = char_binary(is_mgmt_serv_co),
    is_med_staff_co = char_binary(is_med_staff_co),
    is_holding_co = char_binary(is_holding_co),
    is_invest_firm = char_binary(is_invest_firm),
    is_fin_inst = char_binary(is_fin_inst),
    is_consult_firm = char_binary(is_consult_firm),
    is_for_profit = char_binary(is_for_profit),
    is_non_profit = char_binary(is_non_profit),
    is_other_type = char_binary(is_other_type)
  )

rhc_owner
#> # A tibble: 86 × 33
#>    pac        enid  org_name pac_owner org_name_owner entity role_code role_text
#>    <chr>      <chr> <chr>    <chr>     <chr>          <chr>      <int> <chr>    
#>  1 0547179665 O200… TMC HAR… 87299978… TMC/HIGGINS G… O             34 5% OR GR…
#>  2 1557271731 O200… HIAWASS… 15572717… HIAWASSEE FAM… O             43 OPERATIO…
#>  3 5991616039 O200… TMC WES… 59916160… TMC WEST CARR… O             34 5% OR GR…
#>  4 1850294034 O200… BACON C… 18502940… BACON COUNTY … O             34 5% OR GR…
#>  5 1850294034 O200… BACON C… 18502940… BACON COUNTY … O             43 OPERATIO…
#>  6 2264415538 O200… BOWDON-… 22644155… BOWDON- MT. Z… O             36 5% OR GR…
#>  7 2264415538 O200… BOWDON-… 22644155… BOWDON- MT. Z… O             43 OPERATIO…
#>  8 4981502622 O200… HOSPITA… 60027245… JOHN D. ARCHB… O             43 OPERATIO…
#>  9 4981502622 O200… HOSPITA… 60027245… JOHN D. ARCHB… O             43 OPERATIO…
#> 10 4183529183 O200… PHOEBE … 08401045… PHOEBE PUTNEY… O             34 5% OR GR…
#> # ℹ 76 more rows
#> # ℹ 25 more variables: association_date_owner <chr>, first_name_owner <chr>,
#> #   middle_name_owner <chr>, last_name_owner <chr>, title_owner <chr>,
#> #   dba_name <chr>, address <chr>, city_owner <chr>, state_owner <chr>,
#> #   zip <chr>, percentage_ownership <dbl>, is_for_acq <int>, is_corp <int>,
#> #   is_llc <int>, is_med_prov_supp <int>, is_mgmt_serv_co <int>,
#> #   is_med_staff_co <int>, is_holding_co <int>, is_invest_firm <int>, …
tictoc::tic()
rhc_nppes <- npi_nppes(npi = rhc_enr$npi)
tictoc::toc()
#> 1.13 sec elapsed
rhc_nppes |> 
  slt(-endpoints, -enumeration_type) |> 
  print(n = 100)
#> # A tibble: 85 × 7
#>    number     addresses    practiceLocations basic        taxonomies identifiers
#>    <chr>      <list>       <list>            <list>       <list>     <list>     
#>  1 1639774714 <df>         <NULL>            <named list> <df>       <NULL>     
#>  2 1174104657 <df>         <NULL>            <named list> <df>       <NULL>     
#>  3 1568100519 <df>         <NULL>            <named list> <df>       <NULL>     
#>  4 1821017831 <df>         <NULL>            <named list> <df>       <df>       
#>  5 1558898882 <df>         <NULL>            <named list> <df>       <NULL>     
#>  6 1750339511 <df>         <NULL>            <named list> <df>       <df>       
#>  7 1417906348 <df>         <NULL>            <named list> <df>       <df>       
#>  8 1538117932 <df>         <NULL>            <named list> <df>       <df>       
#>  9 1851969372 <df [2 × 9]> <NULL>            <named list> <df>       <NULL>     
#> 10 1639211956 <df>         <NULL>            <named list> <df>       <df>       
#> 11 1881758753 <df>         <NULL>            <named list> <df>       <df>       
#> 12 1790992352 <df>         <NULL>            <named list> <df>       <df>       
#> 13 1376750976 <df>         <NULL>            <named list> <df>       <df>       
#> 14 1427333095 <df>         <NULL>            <named list> <df>       <df>       
#> 15 1821662008 <df [2 × 9]> <NULL>            <named list> <df>       <NULL>     
#> 16 1922672120 <df>         <NULL>            <named list> <df>       <NULL>     
#> 17 1255948717 <df>         <NULL>            <named list> <df>       <df>       
#> 18 1811020407 <df>         <NULL>            <named list> <df>       <NULL>     
#> 19 1750686382 <df>         <NULL>            <named list> <df>       <NULL>     
#> 20 1700237633 <df>         <NULL>            <named list> <df>       <NULL>     
#> 21 1063832202 <df>         <NULL>            <named list> <df>       <NULL>     
#> 22 1437577350 <df>         <NULL>            <named list> <df>       <NULL>     
#> 23 1366784415 <df>         <NULL>            <named list> <df>       <NULL>     
#> 24 1912319997 <df>         <NULL>            <named list> <df>       <NULL>     
#> 25 1538586243 <df>         <NULL>            <named list> <df>       <NULL>     
#> 26 1285706879 <df>         <NULL>            <named list> <df>       <df>       
#> 27 1790088169 <df>         <NULL>            <named list> <df>       <NULL>     
#> 28 1912379082 <df>         <NULL>            <named list> <df>       <NULL>     
#> 29 1699782037 <df>         <NULL>            <named list> <df>       <df>       
#> 30 1215943915 <df>         <NULL>            <named list> <df>       <df>       
#> 31 1801801543 <df>         <NULL>            <named list> <df>       <df>       
#> 32 1366472003 <df>         <NULL>            <named list> <df>       <df>       
#> 33 1922211515 <df>         <NULL>            <named list> <df>       <df>       
#> 34 1881960151 <df [2 × 9]> <NULL>            <named list> <df>       <NULL>     
#> 35 1801128863 <df>         <NULL>            <named list> <df>       <NULL>     
#> 36 1023332970 <df>         <NULL>            <named list> <df>       <df>       
#> 37 1649670894 <df>         <NULL>            <named list> <df>       <NULL>     
#> 38 1912430224 <df>         <NULL>            <named list> <df>       <NULL>     
#> 39 1063459899 <df>         <NULL>            <named list> <df>       <df>       
#> 40 1851334015 <df>         <NULL>            <named list> <df>       <df>       
#> 41 1467602482 <df>         <NULL>            <named list> <df>       <NULL>     
#> 42 1760632780 <df>         <NULL>            <named list> <df>       <NULL>     
#> 43 1912564618 <df>         <NULL>            <named list> <df>       <NULL>     
#> 44 1518398049 <df>         <NULL>            <named list> <df>       <df>       
#> 45 1780695775 <df>         <NULL>            <named list> <df>       <df>       
#> 46 1275714438 <df>         <NULL>            <named list> <df>       <df>       
#> 47 1376778001 <df>         <NULL>            <named list> <df>       <df>       
#> 48 1891770764 <df>         <NULL>            <named list> <df>       <df>       
#> 49 1659700763 <df>         <NULL>            <named list> <df>       <NULL>     
#> 50 1053802553 <df>         <NULL>            <named list> <df>       <NULL>     
#> 51 1386339141 <df [2 × 9]> <NULL>            <named list> <df>       <NULL>     
#> 52 1841432044 <df>         <NULL>            <named list> <df>       <NULL>     
#> 53 1033428214 <df>         <NULL>            <named list> <df>       <NULL>     
#> 54 1811233828 <df>         <NULL>            <named list> <df>       <NULL>     
#> 55 1386708154 <df>         <NULL>            <named list> <df>       <NULL>     
#> 56 1649853862 <df>         <NULL>            <named list> <df>       <NULL>     
#> 57 1285893818 <df>         <NULL>            <named list> <df>       <NULL>     
#> 58 1972762508 <df>         <NULL>            <named list> <df>       <NULL>     
#> 59 1285132415 <df>         <NULL>            <named list> <df>       <NULL>     
#> 60 1568713873 <df>         <NULL>            <named list> <df>       <NULL>     
#> 61 1720227895 <df>         <NULL>            <named list> <df>       <NULL>     
#> 62 1073752143 <df>         <NULL>            <named list> <df>       <NULL>     
#> 63 1255570321 <df>         <NULL>            <named list> <df>       <NULL>     
#> 64 1740778828 <df>         <NULL>            <named list> <df>       <NULL>     
#> 65 1528110103 <df>         <NULL>            <named list> <df>       <df>       
#> 66 1235227752 <df>         <NULL>            <named list> <df>       <df>       
#> 67 1083816128 <df>         <NULL>            <named list> <df>       <df>       
#> 68 1891863569 <df>         <NULL>            <named list> <df>       <df>       
#> 69 1275775314 <df>         <NULL>            <named list> <df>       <NULL>     
#> 70 1871816918 <df>         <df [1 × 10]>     <named list> <df>       <df>       
#> 71 1487284956 <df>         <NULL>            <named list> <df>       <NULL>     
#> 72 1861022329 <df>         <NULL>            <named list> <df>       <NULL>     
#> 73 1063042562 <df>         <NULL>            <named list> <df>       <NULL>     
#> 74 1588294045 <df>         <NULL>            <named list> <df>       <NULL>     
#> 75 1649800111 <df>         <NULL>            <named list> <df>       <NULL>     
#> 76 1508801416 <df>         <NULL>            <named list> <df>       <NULL>     
#> 77 1992710610 <df>         <NULL>            <named list> <df>       <df>       
#> 78 1497760243 <df>         <NULL>            <named list> <df>       <df>       
#> 79 1982631321 <df>         <NULL>            <named list> <df>       <df>       
#> 80 1578682696 <df [2 × 9]> <NULL>            <named list> <df>       <df>       
#> 81 1427384353 <df>         <NULL>            <named list> <df>       <NULL>     
#> 82 1144276452 <df>         <NULL>            <named list> <df>       <NULL>     
#> 83 1700392438 <df>         <NULL>            <named list> <df>       <df>       
#> 84 1174024665 <df [2 × 9]> <NULL>            <named list> <df>       <NULL>     
#> 85 1629531694 <df [2 × 9]> <NULL>            <named list> <df>       <NULL>     
#> # ℹ 1 more variable: other_names <list>
rhc_nppes |> 
  slt(number, addresses) |> 
  unnest(addresses) |> 
  mtt(address = cheapr_if_else(cheapr::is_na(address_2), address_1, paste(address_1, address_2))) |> 
  slt(-address_1, -address_2, -address_type, -country_code, -country_name)
#> # A tibble: 170 × 8
#>    number    address_purpose city  state postal_code telephone_number fax_number
#>    <chr>     <chr>           <chr> <chr> <chr>       <chr>            <chr>     
#>  1 16397747… LOCATION        SYLV… GA    317912125   229-463-7071     833-606-0…
#>  2 16397747… MAILING         HARDY AR    725428002   <NA>             <NA>      
#>  3 11741046… LOCATION        HAWK… GA    310360000   478-845-4842     833-606-0…
#>  4 11741046… MAILING         HARDY AR    725428002   <NA>             870-856-2…
#>  5 15681005… LOCATION        BRUN… GA    315238285   870-856-1202     870-856-2…
#>  6 15681005… MAILING         HARDY AR    725428002   870-856-1202     866-500-4…
#>  7 18210178… MAILING         ALMA  GA    315102908   912-632-2952     912-632-8…
#>  8 18210178… LOCATION        ALMA  GA    315102908   912-632-2952     912-632-8…
#>  9 15588988… LOCATION        NICH… GA    31554       912-632-2952     <NA>      
#> 10 15588988… MAILING         ALMA  GA    315102922   912-632-8961     912-632-5…
#> # ℹ 160 more rows
#> # ℹ 1 more variable: address <chr>
rhc_nppes |> 
  slt(number, basic) |> 
  unnest_wider(basic)
#> # A tibble: 85 × 16
#>    number organization_name organizational_subpart enumeration_date last_updated
#>    <chr>  <chr>             <chr>                  <chr>            <chr>       
#>  1 16397… ACCESS MEDICAL C… NO                     2020-12-04       2021-10-06  
#>  2 11741… ACCESS MEDICAL C… NO                     2021-04-16       2022-09-13  
#>  3 15681… ACCESS MEDICAL C… NO                     2022-05-20       2024-02-27  
#>  4 18210… BACON COUNTY HEA… NO                     2006-07-19       2012-10-10  
#>  5 15588… BACON COUNTY HEA… NO                     2017-05-17       2018-05-22  
#>  6 17503… BOWDON- MT. ZION… YES                    2006-05-04       2022-02-21  
#>  7 14179… BOWDENMTZION PRI… NO                     2006-05-08       2022-03-21  
#>  8 15381… BOWDON- MT. ZION… NO                     2006-05-05       2023-02-28  
#>  9 18519… BURKE HOSPITAL C… NO                     2021-06-11       2022-10-03  
#> 10 16392… COFFEE REGIONAL … NO                     2007-02-13       2022-09-23  
#> # ℹ 75 more rows
#> # ℹ 11 more variables: certification_date <chr>, status <chr>,
#> #   authorized_official_first_name <chr>, authorized_official_last_name <chr>,
#> #   authorized_official_telephone_number <chr>,
#> #   authorized_official_title_or_position <chr>,
#> #   authorized_official_name_prefix <chr>,
#> #   authorized_official_name_suffix <chr>, …
rhc_nppes |> 
  slt(number, taxonomies) |> 
  unnest(taxonomies)
#> # A tibble: 156 × 7
#>    number     code       taxonomy_group              desc  state license primary
#>    <chr>      <chr>      <chr>                       <chr> <chr> <chr>   <lgl>  
#>  1 1639774714 207Q00000X "193200000X - Multi-Specia… Fami… <NA>  <NA>    FALSE  
#>  2 1639774714 261QR1300X ""                          Clin… <NA>  <NA>    TRUE   
#>  3 1174104657 207Q00000X "193200000X - Multi-Specia… Fami… <NA>  <NA>    FALSE  
#>  4 1174104657 261QR1300X ""                          Clin… <NA>  <NA>    TRUE   
#>  5 1568100519 207Q00000X "193200000X - Multi-Specia… Fami… <NA>  <NA>    FALSE  
#>  6 1568100519 261QR1300X ""                          Clin… <NA>  <NA>    TRUE   
#>  7 1821017831 282NR1301X ""                          Gene… <NA>  <NA>    TRUE   
#>  8 1558898882 282NR1301X ""                          Gene… <NA>  <NA>    FALSE  
#>  9 1558898882 363LF0000X "193200000X - Multi-Specia… Nurs… <NA>  <NA>    TRUE   
#> 10 1750339511 261QR1300X ""                          Clin… <NA>  <NA>    TRUE   
#> # ℹ 146 more rows
rhc_nppes |> 
  slt(number, identifiers) |> 
  unnest(identifiers) |> 
  print(n = 100)
#> # A tibble: 47 × 6
#>    number     code  desc                 issuer                 identifier state
#>    <chr>      <chr> <chr>                <chr>                  <chr>      <chr>
#>  1 1821017831 05    MEDICAID             <NA>                   000000118C GA   
#>  2 1821017831 01    Other (non-Medicare) Oscar Number           113408     GA   
#>  3 1750339511 05    MEDICAID             <NA>                   000254064A GA   
#>  4 1417906348 05    MEDICAID             <NA>                   000213749B GA   
#>  5 1417906348 05    MEDICAID             <NA>                   000573262A GA   
#>  6 1538117932 05    MEDICAID             <NA>                   000228588A GA   
#>  7 1639211956 05    MEDICAID             <NA>                   00000448D  GA   
#>  8 1881758753 05    MEDICAID             <NA>                   00002021D  GA   
#>  9 1881758753 05    MEDICAID             <NA>                   00002021E  GA   
#> 10 1790992352 05    MEDICAID             <NA>                   00000514F  GA   
#> 11 1376750976 01    Other (non-Medicare) MCR CCN                11-8907    GA   
#> 12 1427333095 05    MEDICAID             <NA>                   000548369c GA   
#> 13 1255948717 05    MEDICAID             <NA>                   003257063A GA   
#> 14 1285706879 05    MEDICAID             <NA>                   000195665I GA   
#> 15 1285706879 05    MEDICAID             <NA>                   89011JU    NC   
#> 16 1699782037 05    MEDICAID             <NA>                   000001031D GA   
#> 17 1215943915 05    MEDICAID             <NA>                   000001031B GA   
#> 18 1801801543 05    MEDICAID             <NA>                   000001031E GA   
#> 19 1366472003 05    MEDICAID             <NA>                   000001339G GA   
#> 20 1366472003 01    Other (non-Medicare) CLIA                   11D0909917 <NA> 
#> 21 1922211515 01    Other (non-Medicare) CLIA                   11D1056726 GA   
#> 22 1922211515 05    MEDICAID             <NA>                   841859123C GA   
#> 23 1023332970 05    MEDICAID             <NA>                   003110986A GA   
#> 24 1063459899 05    MEDICAID             <NA>                   00700917A  GA   
#> 25 1063459899 01    Other (non-Medicare) PALMETTO GBA RAILROAD  CE5080     GA   
#> 26 1851334015 05    MEDICAID             <NA>                   00679775A  GA   
#> 27 1851334015 01    Other (non-Medicare) PALMETTO GBA RAILROAD  CA6260     GA   
#> 28 1518398049 05    MEDICAID             <NA>                   003155331A GA   
#> 29 1518398049 01    Other (non-Medicare) Medicare Part A        11-8912    GA   
#> 30 1780695775 01    Other (non-Medicare) RAILROAD MEDICARE      080137303  GA   
#> 31 1275714438 01    Other (non-Medicare) RAILROAD MEDICARE      080137303  GA   
#> 32 1376778001 05    MEDICAID             <NA>                   003112355A GA   
#> 33 1891770764 05    MEDICAID             <NA>                   00002109E  GA   
#> 34 1528110103 05    MEDICAID             <NA>                   0000014821 GA   
#> 35 1235227752 05    MEDICAID             <NA>                   003140349A GA   
#> 36 1083816128 05    MEDICAID             <NA>                   251066475A GA   
#> 37 1891863569 05    MEDICAID             <NA>                   85000124G  GA   
#> 38 1871816918 05    MEDICAID             <NA>                   003109531A GA   
#> 39 1992710610 05    MEDICAID             <NA>                   300033792A GA   
#> 40 1992710610 01    Other (non-Medicare) clinic rendering       367607289A GA   
#> 41 1992710610 01    Other (non-Medicare) Medicare ID            DG2920     GA   
#> 42 1497760243 01    Other (non-Medicare) Clinic rendering numb… 367607289B GA   
#> 43 1497760243 05    MEDICAID             <NA>                   540960632A GA   
#> 44 1497760243 01    Other (non-Medicare) Medicare ID            CH7677     GA   
#> 45 1982631321 05    MEDICAID             <NA>                   000750274A GA   
#> 46 1578682696 01    Other (non-Medicare) RHC NUMBER             11-8516    GA   
#> 47 1700392438 05    MEDICAID             <NA>                   003213614A GA
rhc_nppes |> 
  slt(number, other_names) |> 
  unnest(other_names) |> 
  print(n = 100)
#> # A tibble: 76 × 4
#>    number     organization_name                                   type     code 
#>    <chr>      <chr>                                               <chr>    <chr>
#>  1 1174104657 ACCESS MEDICAL CLINIC                               Doing B… 3    
#>  2 1821017831 BACON COUNTY RURAL HEALTH CLINIC                    Doing B… 3    
#>  3 1558898882 NICHOLLS FAMILY HEALTHCARE                          Doing B… 3    
#>  4 1750339511 CARROLL CO PRIMARY HEALTH CARE                      Doing B… 3    
#>  5 1417906348 FRANKLIN CLINIC                                     Doing B… 3    
#>  6 1538117932 CARROLL COUNTY PRIMARY HEALTH CARE                  Doing B… 3    
#>  7 1639211956 COFFEE REGIONAL FIRST CARE                          Doing B… 3    
#>  8 1881758753 COLQUITT REGIONAL PRIMARY CARE CLINIC               Doing B… 3    
#>  9 1790992352 WARWICK HEALTH CARE CLINIC                          Doing B… 3    
#> 10 1376750976 CRISP REGIONAL CONVENIENT CARE                      Doing B… 3    
#> 11 1427333095 DAHLONEGA PEDIATRICS                                Doing B… 3    
#> 12 1821662008 DMC INTERNAL MEDICINE AND FAMILY HEALTH             Doing B… 3    
#> 13 1821662008 DMC INTERNAL AND FAMILY MEDICINE CLINIC             Doing B… 3    
#> 14 1922672120 DMC PRIMARY CARE                                    Doing B… 3    
#> 15 1255948717 EASTMAN FAMILY PRACTICE                             Doing B… 3    
#> 16 1811020407 EFFINGHAM FAMILY MEDICINE AT GOSHEN                 Doing B… 3    
#> 17 1750686382 EFFINGHAM FAMILY MEDICINE AT TWENTY-ONE             Doing B… 3    
#> 18 1700237633 ELLIJAY URGENT CARE & FAMILY PRACTICE               Doing B… 3    
#> 19 1063832202 RAY MEDICAL CLINIC                                  Doing B… 3    
#> 20 1437577350 EMANUEL FAMILY MEDICAL CLINIC                       Doing B… 3    
#> 21 1366784415 SWAINSBORO INTERNAL MEDICINE                        Doing B… 3    
#> 22 1912319997 TWIN CITY FAMILY MEDICAL CLINIC                     Doing B… 3    
#> 23 1538586243 PORTER FAMILY MEDICAL CLINIC                        Doing B… 3    
#> 24 1790088169 CANDLER MEDICAL GROUP RHC                           Doing B… 3    
#> 25 1912379082 JEFF DAVIS FAMILY MEDICAL GROUP                     Doing B… 3    
#> 26 1699782037 PHYSICIANS HEALTH GROUP WADLEY                      Doing B… 3    
#> 27 1215943915 PHYSICIANS' HEALTH GROUP                            Doing B… 3    
#> 28 1801801543 WRENS PHYSICIANS' HEALTH GROUP                      Doing B… 3    
#> 29 1366472003 THE CAMILLA PEDIATRIC CENTER                        Doing B… 3    
#> 30 1922211515 MEDICAL GROUP OF MITCHELL COUNTY                    Doing B… 3    
#> 31 1881960151 ARCHBOLD - PELHAM PRIMARY CARE CLINIC               Doing B… 3    
#> 32 1801128863 COMMUNITY MEDICAL ASSOCIATES OF LINCOLNTON          Doing B… 3    
#> 33 1023332970 COMMUNITY MEDICAL ASSOCIATES OF WASHINGTON          Doing B… 3    
#> 34 1649670894 IRWIN COUNTY HOSPITAL AUTHORITY                     Former … 4    
#> 35 1649670894 WILLACOOCHEE CLINIC                                 Doing B… 3    
#> 36 1912430224 LIFEBRITE FAMILY MEDICAL OF EARLY                   Doing B… 3    
#> 37 1063459899 MEDICAL ASSOCIATES                                  Doing B… 3    
#> 38 1851334015 NORTH JEFFERSON MEDICAL CENTER                      Doing B… 3    
#> 39 1467602482 CHI MEMORIAL FAMILY PRACTICE ASSOCIATES - TRENTON   Doing B… 3    
#> 40 1760632780 CHI MEMORIAL FAMILY PRACTICE ASSOCIATES - LAFAYETTE Doing B… 3    
#> 41 1912564618 WARM SPRINGS MEDICAL CENTER                         Doing B… 3    
#> 42 1376778001 PHOEBE SUMTER ELLAVILLE CLINIC                      Doing B… 3    
#> 43 1891770764 PHOEBE WORTH FAMILY MEDICINE                        Doing B… 3    
#> 44 1659700763 FLINT RIVER RURAL HEALTH CLINIC - OGLETHORPE        Doing B… 3    
#> 45 1053802553 PRESTON FAMILY MEDICINE                             Doing B… 3    
#> 46 1386339141 MOUNTAIN LAKES PHYSICIANS GROUP                     Doing B… 3    
#> 47 1841432044 OPTIM PRIMARY CARE - SYLVANIA                       Doing B… 3    
#> 48 1033428214 OPTIM PRIMARY CARE MILLEN                           Doing B… 3    
#> 49 1649853862 SCHPG-PRIMARY CARE                                  Doing B… 3    
#> 50 1285893818 OPTIM PRIMARY CARE-REIDSVILLE                       Doing B… 3    
#> 51 1972762508 OPTIM PRIMARY CARE- GLENNVILLE                      Doing B… 3    
#> 52 1285132415 OPTIM PRIMARY CARE METTER                           Doing B… 3    
#> 53 1568713873 TAYLOR PHYSICIANS PRACTICE # 3                      Doing B… 3    
#> 54 1720227895 APPLING PEDIATRICS                                  Doing B… 3    
#> 55 1073752143 APPLING MEDICAL GROUP                               Doing B… 3    
#> 56 1255570321 SOUTH GEORGIA MEDICAL ASSOCIATES                    Doing B… 3    
#> 57 1740778828 INTERNAL MEDICINE AND GERIATRICS-RHC                Doing B… 3    
#> 58 1740778828 HABERSHAM MEDICAL GROUP                             Doing B… 3    
#> 59 1528110103 MILLER COUNTY MEDICAL CENTER                        Doing B… 3    
#> 60 1235227752 ROBERT E JENNINGS MEDICAL CLINIC                    Doing B… 3    
#> 61 1275775314 ATRIUM HEALTH NAVICENT PRIMARY CARE FORT VALLEY     Doing B… 3    
#> 62 1275775314 VALLEY MEDICAL CENTER                               Doing B… 3    
#> 63 1871816918 SOUTHWELL MEDICAL ADEL PRIMARY CARE                 Doing B… 3    
#> 64 1871816918 COOK PRIMARY CARE                                   Doing B… 3    
#> 65 1487284956 SOUTHWELL MEDICAL SYLVESTER PRIMARY CARE            Doing B… 3    
#> 66 1861022329 SOUTHWELL MEDICAL CLINIC                            Doing B… 3    
#> 67 1063042562 SOUTHWELL MEDICAL ASHBURN PRIMARY CARE              Doing B… 3    
#> 68 1588294045 SOUTHWELL MEDICAL NASHVILLE PRIMARY CARE            Doing B… 3    
#> 69 1649800111 SOUTHWELL MEDICAL COMMUNITY HEALTH CENTER           Doing B… 3    
#> 70 1508801416 BUCHANAN MEDICAL CLINIC                             Doing B… 3    
#> 71 1992710610 PRIMARY CARE OF BREMEN                              Doing B… 3    
#> 72 1982631321 WEST CARROLL FAMILY HEALTHCARE                      Doing B… 3    
#> 73 1578682696 UNION GENERAL FAMILY MEDICINE                       Doing B… 3    
#> 74 1427384353 CHATUGE MEDICAL GROUP                               Other N… 5    
#> 75 1700392438 UPSON REGIONAL MEDICAL CENTER                       Doing B… 3    
#> 76 1174024665 C/O HOSPITAL AUTHORITY OF WASHINGTON COUNTY         Other N… 5
rhc_nppes |> 
  slt(number, practiceLocations) |> 
  unnest_wider(practiceLocations) |> 
  sbt(!is.na(state)) |> 
  print(n = 100)
#> # A tibble: 1 × 11
#>   number  country_code country_name address_purpose address_type address_1 city 
#>   <chr>   <chr>        <chr>        <chr>           <chr>        <chr>     <chr>
#> 1 187181… US           United Stat… LOCATION        DOM          308 N PA… ADEL 
#> # ℹ 4 more variables: state <chr>, postal_code <chr>, telephone_number <chr>,
#> #   fax_number <chr>

Geocode with {tidygeocoder}

geo_census <- tidygeocoder::geocode(
  rhc_enr,
  street = address,
  city    = city,
  state   = state,
  postalcode = zip,
  method = "census", 
  full_results = TRUE)
#> Passing 84 addresses to the US Census batch geocoder
#> Query completed in: 1 seconds
geo_census
#> # A tibble: 85 × 26
#>    npi    has_mult_npi ccn   pac   enid  enid_state org_name dba_name inc_date  
#>    <chr>         <int> <chr> <chr> <chr> <chr>      <chr>    <chr>    <date>    
#>  1 16397…            0 1189… 2961… O202… GA         ACCESS … <NA>     2020-07-29
#>  2 11741…            0 1189… 2961… O202… GA         ACCESS … <NA>     2021-01-11
#>  3 15681…            0 1189… 2961… O202… GA         ACCESS … <NA>     2020-07-29
#>  4 18210…            1 1134… 1850… O200… GA         BACON C… BACON C… 1995-06-15
#>  5 15588…            0 1185… 1850… O201… GA         BACON C… NICHOLL… 1995-06-15
#>  6 17503…            0 1138… 2264… O200… GA         BOWDON-… CARROLL… 1980-10-09
#>  7 14179…            0 1138… 2264… O200… GA         BOWDON-… FRANLKI… 1980-10-09
#>  8 15381…            0 1138… 2264… O201… GA         BOWDON-… CARROLL… 1980-10-09
#>  9 18519…            0 1185… 3476… O202… GA         BURKE H… BURKE M… NA        
#> 10 16392…            0 1134… 4587… O201… GA         COFFEE … COFFEE … NA        
#> # ℹ 75 more rows
#> # ℹ 17 more variables: inc_state <chr>, org_type <chr>, org_type_2 <chr>,
#> #   proprietary_nonprofit <chr>, address <chr>, city <chr>, state <chr>,
#> #   zip <chr>, lat <dbl>, long <dbl>, id <int>, input_address <chr>,
#> #   match_indicator <chr>, match_type <chr>, matched_address <chr>,
#> #   tiger_line_id <int>, tiger_side <chr>
geo_arcgis <- tidygeocoder::geocode(
  rhc_enr,
  street = address,
  city    = city,
  state   = state,
  postalcode = zip,
  method = "arcgis", 
  full_results = TRUE)
#> Passing 84 addresses to the ArcGIS single address geocoder
#> Query completed in: 35.6 seconds
geo_arcgis
#> # A tibble: 85 × 87
#>    npi    has_mult_npi ccn   pac   enid  enid_state org_name dba_name inc_date  
#>    <chr>         <int> <chr> <chr> <chr> <chr>      <chr>    <chr>    <date>    
#>  1 16397…            0 1189… 2961… O202… GA         ACCESS … <NA>     2020-07-29
#>  2 11741…            0 1189… 2961… O202… GA         ACCESS … <NA>     2021-01-11
#>  3 15681…            0 1189… 2961… O202… GA         ACCESS … <NA>     2020-07-29
#>  4 18210…            1 1134… 1850… O200… GA         BACON C… BACON C… 1995-06-15
#>  5 15588…            0 1185… 1850… O201… GA         BACON C… NICHOLL… 1995-06-15
#>  6 17503…            0 1138… 2264… O200… GA         BOWDON-… CARROLL… 1980-10-09
#>  7 14179…            0 1138… 2264… O200… GA         BOWDON-… FRANLKI… 1980-10-09
#>  8 15381…            0 1138… 2264… O201… GA         BOWDON-… CARROLL… 1980-10-09
#>  9 18519…            0 1185… 3476… O202… GA         BURKE H… BURKE M… NA        
#> 10 16392…            0 1134… 4587… O201… GA         COFFEE … COFFEE … NA        
#> # ℹ 75 more rows
#> # ℹ 78 more variables: inc_state <chr>, org_type <chr>, org_type_2 <chr>,
#> #   proprietary_nonprofit <chr>, address <chr>, city <chr>, state <chr>,
#> #   zip <chr>, lat <dbl>, long <dbl>, arcgis_address <chr>, score <dbl>,
#> #   location.x <dbl>, location.y <dbl>, attributes.Loc_name <chr>,
#> #   attributes.Status <chr>, attributes.Score <dbl>,
#> #   attributes.Match_addr <chr>, attributes.LongLabel <chr>, …

Retrieve Georgia counties shapefile from {tigris}

tig_cnt <- tigris::counties(
  state = "GA",
  year = 2022,
  progress_bar = FALSE)

tig_cnt
#> Simple feature collection with 159 features and 17 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -85.6 ymin: 30.4 xmax: -80.8 ymax: 35
#> Geodetic CRS:  NAD83
#> First 10 features:
#>     STATEFP COUNTYFP COUNTYNS GEOID     NAME        NAMELSAD LSAD CLASSFP MTFCC
#> 16       13      189 00348794 13189 McDuffie McDuffie County   06      H1 G4020
#> 53       13      025 00351605 13025 Brantley Brantley County   06      H1 G4020
#> 54       13      171 00326713 13171    Lamar    Lamar County   06      H1 G4020
#> 83       13      115 00353665 13115    Floyd    Floyd County   06      H1 G4020
#> 101      13      273 00352238 13273  Terrell  Terrell County   06      H1 G4020
#> 102      13      063 01672399 13063  Clayton  Clayton County   06      H1 G4020
#> 105      13      073 00348865 13073 Columbia Columbia County   06      H1 G4020
#> 126      13      193 00346957 13193    Macon    Macon County   06      H1 G4020
#> 146      13      049 00357747 13049 Charlton Charlton County   06      H1 G4020
#> 147      13      233 00343585 13233     Polk     Polk County   06      H1 G4020
#>     CSAFP CBSAFP METDIVFP FUNCSTAT      ALAND   AWATER    INTPTLAT     INTPTLON
#> 16   <NA>   <NA>     <NA>        A  666591525 23112523 +33.4806126 -082.4795333
#> 53   <NA>   <NA>     <NA>        A 1147972258 10291563 +31.1973339 -081.9829779
#> 54   <NA>   <NA>     <NA>        A  475264405  6044329 +33.0744405 -084.1466893
#> 83   <NA>   <NA>     <NA>        A 1320431515 22387093 +34.2636901 -085.2136849
#> 101  <NA>   <NA>     <NA>        A  869695791  4951325 +31.7771909 -084.4394464
#> 102  <NA>   <NA>     <NA>        A  367145192  6928044 +33.5516027 -084.4128678
#> 105  <NA>   <NA>     <NA>        A  751598754 45345677 +33.5520746 -082.2496077
#> 126  <NA>   <NA>     <NA>        A 1037709945 13841916 +32.3626859 -084.0512306
#> 146  <NA>   <NA>     <NA>        A 2020415648  5963237 +30.7799036 -082.1396442
#> 147  <NA>   <NA>     <NA>        A  803775591  4664760 +33.9960153 -085.1883384
#>                           geometry
#> 16  MULTIPOLYGON (((-82.6 33.6,...
#> 53  MULTIPOLYGON (((-81.9 31.1,...
#> 54  MULTIPOLYGON (((-84.2 33.1,...
#> 83  MULTIPOLYGON (((-85 34.3, -...
#> 101 MULTIPOLYGON (((-84.3 31.7,...
#> 102 MULTIPOLYGON (((-84.5 33.6,...
#> 105 MULTIPOLYGON (((-82.4 33.6,...
#> 126 MULTIPOLYGON (((-83.8 32.4,...
#> 146 MULTIPOLYGON (((-82.4 30.8,...
#> 147 MULTIPOLYGON (((-85.2 33.9,...
summary(tig_cnt)
#>    STATEFP            COUNTYFP           COUNTYNS            GEOID          
#>  Length:159         Length:159         Length:159         Length:159        
#>  Class :character   Class :character   Class :character   Class :character  
#>  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
#>                                                                             
#>                                                                             
#>                                                                             
#>      NAME             NAMELSAD             LSAD             CLASSFP         
#>  Length:159         Length:159         Length:159         Length:159        
#>  Class :character   Class :character   Class :character   Class :character  
#>  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
#>                                                                             
#>                                                                             
#>                                                                             
#>     MTFCC              CSAFP              CBSAFP            METDIVFP        
#>  Length:159         Length:159         Length:159         Length:159        
#>  Class :character   Class :character   Class :character   Class :character  
#>  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
#>                                                                             
#>                                                                             
#>                                                                             
#>    FUNCSTAT             ALAND                AWATER            INTPTLAT        
#>  Length:159         Min.   : 308985572   Min.   :   488463   Length:159        
#>  Class :character   1st Qu.: 645741035   1st Qu.:  6553565   Class :character  
#>  Mode  :character   Median : 887636774   Median : 11818093   Mode  :character  
#>                     Mean   : 940165210   Mean   : 27790668                     
#>                     3rd Qu.:1151923513   3rd Qu.: 19959364                     
#>                     Max.   :2329020700   Max.   :509854701                     
#>    INTPTLON                  geometry  
#>  Length:159         MULTIPOLYGON :159  
#>  Class :character   epsg:4269    :  0  
#>  Mode  :character   +proj=long...:  0  
#>                                        
#>                                        
#> 
sf_cnt <- ms_simplify(tig_cnt)

sf_cnt$mid <- st_centroid(sf_cnt$geometry)

Map with {ggplot}

ggplot(sf_cnt) +
  geom_sf(
    fill = "skyblue",
    colour = "white",
    alpha = 0.5) +
  geom_sf_text(
    aes(geometry = geometry, 
        label = NAME),
    size = 3.5,
    check_overlap = TRUE) +
  geom_jitter(
    data = geo_census,
    mapping = aes(long, lat),
    fill = "yellow",
    color = "darkred",
    alpha = 0.75,
    size = 4,
    shape = 21,
    stroke = 1) +
  theme_void()