-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved
search_taxonomy
from northstar
- Loading branch information
1 parent
c434b42
commit 88b56b5
Showing
16 changed files
with
463 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#' NUCC Provider Taxonomy Codeset | ||
#' | ||
#' `search_taxonomy()` returns a [tibble()] of the current Health Care Provider | ||
#' Taxonomy code set | ||
#' | ||
#' __Update Frequency__: _Biannually_ | ||
#' | ||
#' @section Taxonomy Codes: | ||
#' The Health Care Provider Taxonomy code set is a collection of unique | ||
#' alphanumeric codes, ten characters in length. They contain no embedded logic. | ||
#' | ||
#' The code set Levels are organized to allow for drilling down to the | ||
#' provider's most specific level of specialization, with three distinct "Levels": | ||
#' | ||
#' @section __Level I__ _Provider Grouping_: | ||
#' A major grouping of service(s) or occupation(s) of health care providers. | ||
#' | ||
#' _Examples:_ Allopathic & Osteopathic Physicians, Dental Providers, Hospitals | ||
#' | ||
#' @section __Level II__ _Classification_: | ||
#' A more specific service or occupation related to the Provider Grouping. | ||
#' | ||
#' For example, the classification for Allopathic & Osteopathic Physicians is | ||
#' based upon the General Specialty Certificates as issued by the appropriate | ||
#' national boards. | ||
#' | ||
#' The following boards will, however, have their general certificates appear as | ||
#' Level III Areas of specialization strictly due to display limitations of the | ||
#' code set for Boards that have multiple general certificates: | ||
#' | ||
#' _Medical Genetics, Preventive Medicine, Psychiatry & Neurology, Radiology,_ | ||
#' _Surgery, Otolaryngology, Pathology_ | ||
#' | ||
#' @section __Level III__ _Area of Specialization_: | ||
#' A more specialized area of the Classification in which a provider chooses to | ||
#' practice or make services available. | ||
#' | ||
#' For example, the area of specialization for Allopathic & Osteopathic | ||
#' Physicians is based upon the Subspecialty Certificates as issued by the | ||
#' appropriate national boards. | ||
#' | ||
#' @section __Categories__ _(Level 0)_: | ||
#' The code set includes three specialty categories: | ||
#' | ||
#' __Group (of Individuals)__: | ||
#' 1. Multi-Specialty | ||
#' 1. Single Specialty | ||
#' | ||
#' __Individuals__: | ||
#' 1. Allopathic & Osteopathic Physicians | ||
#' 1. Behavioral Health and Social Service Providers | ||
#' 1. Chiropractic Providers | ||
#' 1. Dental Providers | ||
#' 1. Dietary and Nutritional Service Providers | ||
#' 1. Emergency Medical Service Providers | ||
#' 1. Eye and Vision Service Providers | ||
#' 1. Nursing Service Providers | ||
#' 1. Nursing Service Related Providers | ||
#' 1. Other Service Providers | ||
#' 1. Pharmacy Service Providers | ||
#' 1. Physician Assistants and Advanced Practice Nursing Providers | ||
#' 1. Podiatric Medicine and Surgery Service Providers | ||
#' 1. Respiratory, Developmental, Rehabilitative and Restorative Service Providers | ||
#' 1. Speech, Language and Hearing Service Providers | ||
#' 1. Student, Health Care | ||
#' 1. Technologists, Technicians, and Other Technical Service Providers | ||
#' | ||
#' __Non-Individuals__: | ||
#' 1. Agencies | ||
#' 1. Ambulatory Health Care Facilities | ||
#' 1. Hospital Units | ||
#' 1. Hospitals | ||
#' 1. Laboratories | ||
#' 1. Managed Care Organizations | ||
#' 1. Nursing and Custodial Care Facilities | ||
#' 1. Other Service Providers | ||
#' 1. Residential Treatment Facilities | ||
#' 1. Respite Care Facilities | ||
#' 1. Suppliers | ||
#' 1. Transportation Services | ||
#' | ||
#' @section Display Name: | ||
#' The display name is a combination of the code name and the Level in | ||
#' which the code is nested, which more precisely identifies the code. | ||
#' | ||
#' For example, Addiction Medicine is a physician subspecialty in Anesthesiology, | ||
#' Family Medicine, Internal Medicine, Preventive Medicine, and Psychiatry & | ||
#' Neurology. | ||
#' | ||
#' "Addiction Medicine" does not identify the specialty of | ||
#' the physician, but the display name of "Addiction Medicine (Internal | ||
#' Medicine) Physician" clearly does. | ||
#' | ||
#' In another example, "Radiology" could be confused with several | ||
#' taxonomies, but "Radiology Chiropractor" more accurately specifies the provider. | ||
#' | ||
#' @section Description: | ||
#' + `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 | ||
#' | ||
#' @source | ||
#' [National Uniform Claim Committee](https://www.nucc.org/index.php/code-sets-mainmenu-41/provider-taxonomy-mainmenu-40/csv-mainmenu-57) | ||
#' | ||
#' @param code `<chr>` vector of taxonomy codes | ||
#' | ||
#' @param shape `<chr>` shape of data to return, `wide` (default) or `long` | ||
#' | ||
#' @param unnest `<lgl>`unnest `hierarchy` column, default is `FALSE` | ||
#' | ||
#' @template args-dots | ||
#' | ||
#' @template returns | ||
#' | ||
#' @examples | ||
#' taxonomies(code = c("207K00000X", "193200000X")) | ||
#' | ||
#' taxonomies(code = "207K00000X", | ||
#' shape = "long", | ||
#' unnest = TRUE) | ||
#' | ||
#' @autoglobal | ||
#' | ||
#' @export | ||
taxonomies <- function(code = NULL, | ||
shape = c('wide', 'long'), | ||
unnest = FALSE, | ||
...) { | ||
|
||
shape <- match.arg(shape) | ||
|
||
txn <- switch( | ||
shape, | ||
"wide" = pins::pin_read(mount_board(), "taxonomy"), | ||
"long" = pins::pin_read(mount_board(), "taxlong") | ||
) | ||
|
||
txn <- fuimus::search_in_if(txn, txn$code, code) | ||
|
||
if (shape == "long" && unnest) { | ||
txn <- tidyr::unnest(txn, cols = c(hierarchy)) | ||
} | ||
return(txn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
x <- rvest::session("https://www.nucc.org") |> | ||
rvest::session_follow_link("Code Sets") |> | ||
rvest::session_follow_link("Taxonomy") |> | ||
rvest::session_follow_link("CSV") |> | ||
rvest::html_elements("a") |> | ||
rvest::html_attr("href") |> | ||
stringr::str_subset("taxonomy") |> | ||
stringr::str_subset("csv") | ||
|
||
x <- rvest::session(paste0("https://www.nucc.org", x)) |> | ||
rvest::session_follow_link("Version") | ||
|
||
x <- x$response$url | ||
|
||
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::mutate(version = as.character(240), | ||
release_date = lubridate::ymd("2024-01-01")) | ||
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 <- taxonomy |> | ||
dplyr::select(code, display_name, definition, notes) | ||
|
||
long <- taxonomy |> | ||
dplyr::select(code, | ||
section, | ||
grouping, | ||
classification, | ||
specialization) |> | ||
dplyr::mutate(section_level = 0, .before = section) |> | ||
dplyr::mutate(grouping_level = 1, .before = grouping) |> | ||
dplyr::mutate(classification_level = 2, .before = classification) |> | ||
dplyr::mutate(specialization_level = 3, .before = specialization) |> | ||
tidyr::unite("section", section:section_level, remove = TRUE) |> | ||
tidyr::unite("grouping", grouping:grouping_level, remove = TRUE) |> | ||
tidyr::unite("classification", classification:classification_level, remove = TRUE, na.rm = TRUE) |> | ||
tidyr::unite("specialization", specialization:specialization_level, remove = TRUE, na.rm = TRUE) |> | ||
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)) | ||
|
||
longnest <- long |> | ||
dplyr::left_join(info, by = "code") |> | ||
tidyr::nest(hierarchy = c(level, description)) |> | ||
dplyr::select(code, display_name, hierarchy, definition, notes) | ||
|
||
# Update Pin | ||
board <- pins::board_folder(here::here("inst/extdata/pins")) | ||
|
||
board |> | ||
pins::pin_write(taxonomy, | ||
name = "taxonomy", | ||
title = "Provider Taxonomy Code Set", | ||
description = "NUCC Health Care Provider Taxonomy Code Set January 2024", | ||
type = "qs") | ||
|
||
board |> | ||
pins::pin_write(longnest, | ||
name = "taxlong", | ||
title = "Provider Taxonomy Code Set", | ||
description = "NUCC Health Care Provider Taxonomy Code Set January 2024", | ||
type = "qs") | ||
|
||
board |> pins::write_board_manifest() | ||
|
||
# pins::pin_delete(board, "tax_long") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
taxlong: | ||
- taxlong/20240409T213644Z-972c7/ | ||
taxonomy: | ||
- taxonomy/20240409T213637Z-1a818/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 20240409T213644Z | ||
api_version: 1 |
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
inst/extdata/pins/taxonomy/20240409T213637Z-1a818/data.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
file: taxonomy.qs | ||
file_size: 100601 | ||
pin_hash: 1a81842c74dcf89c | ||
type: qs | ||
title: Provider Taxonomy Code Set | ||
description: NUCC Health Care Provider Taxonomy Code Set January 2024 | ||
tags: ~ | ||
urls: ~ | ||
created: 20240409T213637Z | ||
api_version: 1 |
Binary file not shown.
Oops, something went wrong.