Skip to content

Commit

Permalink
refactored taxonomy pins
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Mar 21, 2024
1 parent 46f9f1e commit 528f1b6
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 46 deletions.
2 changes: 0 additions & 2 deletions R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ utils::globalVariables(c(
"price",
# <opps>
"procstat",
# <taxonomy>
"results",
# <case_section>
"section",
# <level2>
Expand Down
26 changes: 16 additions & 10 deletions R/taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@
#' taxonomies, but "Radiology Chiropractor" more accurately specifies the provider.
#'
#' @section Description:
#' + `taxonomy_code`: Provider Taxonomy Code
#' + `taxonomy_category`: Indicates whether Taxonomy is Individual or Non-Individual, i.e., a group taxonomy
#' + `taxonomy_grouping`: Level I, Provider Grouping
#' + `taxonomy_classification`: Level II, Classification
#' + `taxonomy_specialization`: Level III, Area of Specialization
#' + `taxonomy_display_name`: Consumer-friendly taxonomy name, made of the code name and the Level in which the code is nested.
#' + `taxonomy_definition`: Definition of Taxonomy
#' + `code`: Provider Taxonomy Code
#' + `category`: Indicates whether Taxonomy is Individual or Non-Individual, i.e., a group taxonomy
#' + `grouping`: Level I, Provider Grouping
#' + `classification`: Level II, Classification
#' + `specialization`: Level III, Area of Specialization
#' + `display_name`: Consumer-friendly taxonomy name, made of the code name and the Level in which the code is nested.
#' + `definition`: Definition of Taxonomy
#' + `version`: Three digit version of the code set. The first two digits indicate the year and the third digit indicates either the first release of the year ("0") or the second release of the year ("1").
#' + `release_date`: Date the version of the code set was released
#'
Expand All @@ -113,16 +113,22 @@
#' @return A [tibble][tibble::tibble-package] with the columns:
#'
#' @examplesIf interactive()
#' taxonomy()
#' taxonomy("wide")
#'
#' taxonomy("long")
#' @autoglobal
#' @export
taxonomy <- function(shape = c('wide', 'long')) {

shape <- match.arg(shape)

if (shape == 'wide') {return(pins::pin_read(mount_board(), "taxonomy"))}
if (shape == 'wide') {
results <- pins::pin_read(mount_board(), "taxonomy")
}

if (shape == 'long') {return(pins::pin_read(mount_board(), "tax_long"))}
if (shape == 'long') {
results <- pins::pin_read(mount_board(), "tax_long")
}

return(results)
}
49 changes: 27 additions & 22 deletions data-raw/taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,35 @@ x <- rvest::session(paste0("https://www.nucc.org", x)) |>

x <- x$response$url

x <- data.table::fread(x) |>
taxonomy <- data.table::fread(x) |>
dplyr::tibble() |>
janitor::clean_names() |>
dplyr::mutate(
dplyr::across(dplyr::everything(), ~ dplyr::na_if(., "")),
dplyr::across(dplyr::everything(), ~ stringr::str_squish(.)))
# dplyr::select(
# taxonomy_code = code,
# taxonomy_category = section,
# taxonomy_grouping = grouping,
# taxonomy_classification = classification,
# taxonomy_specialization = specialization,
# taxonomy_display_name = display_name,
# taxonomy_definition = definition)

x <- x |>
dplyr::mutate(version = as.integer(240),
dplyr::across(dplyr::everything(), ~ stringr::str_squish(.))) |>
dplyr::mutate(version = as.character(240),
release_date = lubridate::ymd("2024-01-01"))
x
taxonomy <- taxonomy |>
dplyr::select(
code,
display_name,
section,
grouping,
classification,
specialization,
definition,
notes,
version,
release_date
)
# https://www.nucc.org/images/stories/CSV/nucc_taxonomy_240.csv
# "2023-07-01"
# "2024-01-01"

info <- x |>
info <- taxonomy |>
dplyr::select(code, display_name, definition, notes)

long <- x |>
long <- taxonomy |>
dplyr::select(code,
section,
grouping,
Expand All @@ -55,13 +57,16 @@ long <- x |>
tidyr::pivot_longer(!code, names_to = "level", values_to = "description") |>
dplyr::filter(description != "3") |>
tidyr::separate_wider_delim(description, delim = "_", names = c("description", "group")) |>
dplyr::mutate(group = NULL, level = factor(level,
levels = c("section", "grouping", "classification", "specialization"),
labels = c("I. Section", "II. Grouping", "III. Classification", "IV. Specialization"), ordered = TRUE))
dplyr::mutate(group = NULL,
level = factor(level,
levels = c("section", "grouping", "classification", "specialization"),
labels = c("I. Section", "II. Grouping", "III. Classification", "IV. Specialization"),
ordered = TRUE))

longnest <- long |>
dplyr::left_join(info, by = "code") |>
tidyr::nest(hierarchy = c(level, description))
tidyr::nest(hierarchy = c(level, description)) |>
dplyr::select(code, display_name, hierarchy, definition, notes)

# Update Pin
board <- pins::board_folder(here::here("pins"))
Expand All @@ -74,8 +79,8 @@ board |>
type = "qs")

board |>
pins::pin_write(x,
name = "tax_long",
pins::pin_write(longnest,
name = "taxlong",
title = "Provider Taxonomy Code Set",
description = "NUCC Health Care Provider Taxonomy Code Set January 2024",
type = "qs")
Expand Down
18 changes: 10 additions & 8 deletions man/taxonomy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pins/_pins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ rbcs:
- rbcs/20240311T110445Z-95e7b/
rvu:
- rvu/20240308T222534Z-f2d79/
taxlong:
- taxlong/20240321T212817Z-972c7/
taxonomy:
- taxonomy/20240320T230832Z-a71a1/
- taxonomy/20240321T212812Z-28971/
tax_long:
- tax_long/20240320T232744Z-a71a1/
10 changes: 10 additions & 0 deletions pins/taxlong/20240321T212817Z-972c7/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
file: taxlong.qs
file_size: 105576
pin_hash: 972c745ebfbd01bf
type: qs
title: Provider Taxonomy Code Set
description: NUCC Health Care Provider Taxonomy Code Set January 2024
tags: ~
urls: ~
created: 20240321T212817Z
api_version: 1
Binary file added pins/taxlong/20240321T212817Z-972c7/taxlong.qs
Binary file not shown.
Binary file removed pins/taxonomy/20240320T230832Z-a71a1/taxonomy.qs
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
file: taxonomy.qs
file_size: 101270
pin_hash: a71a19811243ea18
file_size: 101
pin_hash: 28971fd5683abb7d
type: qs
title: Provider Taxonomy Code Set
description: NUCC Health Care Provider Taxonomy Code Set January 2024
tags: ~
urls: ~
created: 20240320T230832Z
created: 20240321T212812Z
api_version: 1
Binary file added pins/taxonomy/20240321T212812Z-28971/taxonomy.qs
Binary file not shown.

0 comments on commit 528f1b6

Please sign in to comment.