Skip to content

Commit

Permalink
fix: descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Jul 1, 2024
1 parent 9a63cc9 commit a77048d
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 42 deletions.
124 changes: 86 additions & 38 deletions data-raw/descriptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,97 @@ source(here::here("data-raw", "source_setup", "setup.R"))
"two_descriptions"
"hcpcs_noc"

hcpcs_desc <- get_pin("hcpcs_desc_raw") |>
dplyr::count(hcpcs_code, hcpcs_desc_type, sort = TRUE) |>
dplyr::filter(hcpcs_desc_type == "Clinician") |>
rvu_desc <- get_pin("rvu_descriptions")
cpt_desc <- get_pin("cpt_descriptions")
two_desc <- get_pin("two_descriptions")
noc_desc <- get_pin("hcpcs_noc")

nocs <- noc_desc |>
dplyr::reframe(
hcpcs_code = hcpcs,
hcpcs_desc_type = "NOC",
hcpcs_description = long_description,
noc_add_date = add_date,
noc_term_date = term_date
)

hcpcs_desc <- vctrs::vec_rbind(
rvu_desc,
cpt_desc,
two_desc,
nocs |>
dplyr::select(
-dplyr::contains("date")
)
) |>
dplyr::distinct(
hcpcs_code,
hcpcs_description,
.keep_all = TRUE
) |>
dplyr::mutate(
hcpcs_desc_type = forcats::as_factor(hcpcs_desc_type),
hcpcs_desc_type = forcats::fct_infreq(hcpcs_desc_type, ordered = TRUE)
) |>
dplyr::arrange(
hcpcs_code,
hcpcs_desc_type
)

hcpcs_desc |>
dplyr::filter(hcpcs_desc_type == "Short") |>
dplyr::group_by(hcpcs_code) |>
dplyr::filter(n() > 1) |>
dplyr::mutate(
hcpcs_description = stringr::str_to_upper(hcpcs_description)
) |>
dplyr::ungroup() |>
dplyr::distinct(
hcpcs_code,
hcpcs_description,
.keep_all = TRUE
) |>
dplyr::group_by(hcpcs_code) |>
dplyr::filter(n() > 1)

# Remove 'Short' Duplicates ---------------------
hcpcs_desc <- hcpcs_desc |>
dplyr::mutate(rowid = dplyr::row_number(),
.before = hcpcs_code)

hcpcs_no_short <- hcpcs_desc |>
dplyr::filter(hcpcs_desc_type != "Short")


hcpcs_short <- hcpcs_desc |>
dplyr::filter(hcpcs_desc_type == "Short") |>
dplyr::group_by(hcpcs_code) |>
dplyr::filter(n() > 1) |>
dplyr::mutate(
hcpcs_description = stringr::str_to_upper(
hcpcs_description)) |>
dplyr::ungroup() |>
dplyr::distinct(
hcpcs_code,
hcpcs_description,
.keep_all = TRUE
)

rows <- hcpcs_short |>
dplyr::group_by(hcpcs_code) |>
dplyr::filter(n() > 1) |>
dplyr::slice_max(rowid) |>
dplyr::pull(rowid)

hcpcs_desc <- hcpcs_short |>
dplyr::filter(!hcpcs_code %in% rows) |>
dplyr::bind_rows(hcpcs_no_short) |>
dplyr::mutate(rowid = NULL) |>
dplyr::arrange(
hcpcs_code,
hcpcs_desc_type
)

# Add Levels and Categories ---------------------
hcpcs_desc <- hcpcs_desc |>
dplyr::mutate(
Expand All @@ -35,44 +117,10 @@ hcpcs_desc <- hcpcs_desc |>
hcpcs_code, stringr::regex("[T]")) ~ "III",
.default = NA_character_
) |> forcats::as_factor(),
.after = hcpcs_code,
hcpcs_desc_type = forcats::as_factor(hcpcs_desc_type),
hcpcs_desc_type = forcats::fct_infreq(hcpcs_desc_type, ordered = TRUE)
.after = hcpcs_code
) |>
dplyr::arrange(hcpcs_code, hcpcs_desc_type)


# Remove 'Short' Duplicates ---------------------
hcpcs_desc <- hcpcs_desc |>
dplyr::mutate(
rowid = dplyr::row_number(),
.before = hcpcs_code
)

vec_short_dupes <- hcpcs_desc |>
dplyr::filter(hcpcs_desc_type == "Short") |>
dplyr::count(hcpcs_code, sort = TRUE) |>
dplyr::filter(n > 1) |>
dplyr::pull(hcpcs_code)

dupes_rowid <- hcpcs_desc |>
dplyr::filter(
hcpcs_desc_type == "Short",
hcpcs_code %in% vec_short_dupes
) |>
dplyr::slice_max(rowid, by = hcpcs_code) |>
dplyr::pull(rowid)

hcpcs_desc <- hcpcs_desc |>
dplyr::filter(!rowid %in% dupes_rowid) |>
dplyr::mutate(
hcpcs_description = dplyr::case_when(
hcpcs_desc_type == "Short" ~ stringr::str_to_upper(hcpcs_description),
.default = hcpcs_description
),
rowid = NULL
)

# Add Sections and Ranges ---------------------
hcpcs_desc <- hcpcs_desc |>
dplyr::mutate(
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/pins/_pins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ denials_site_2:
examples:
- examples/20240628T010539Z-7eb2f/
hcpcs_descriptions:
- hcpcs_descriptions/20240627T025507Z-9bffb/
- hcpcs_descriptions/20240701T224459Z-b0e57/
hcpcs_desc_raw:
- hcpcs_desc_raw/20240627T020527Z-5dba8/
hcpcs_lvl2:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
file: hcpcs_descriptions.qs
file_size: 1201292
pin_hash: 9bffbb205abf7040
file_size: 1124134
pin_hash: b0e57df30919136a
type: qs
title: HCPCS Descriptions Master File
description: HCPCS Descriptions Master File
tags: ~
urls: ~
created: 20240627T025507Z
created: 20240701T224459Z
api_version: 1
Binary file not shown.

0 comments on commit a77048d

Please sign in to comment.