diff --git a/NAMESPACE b/NAMESPACE index 15bdde8..b805614 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,9 +21,12 @@ export(list_ill_defined_icd11) importFrom(dplyr,bind_rows) importFrom(dplyr,case_when) importFrom(dplyr,mutate) +importFrom(dplyr,rename_with) importFrom(dplyr,select) importFrom(methods,is) importFrom(rlang,.data) importFrom(stringr,str_count) importFrom(stringr,str_detect) +importFrom(stringr,str_replace_all) +importFrom(stringr,str_trim) importFrom(tibble,tibble) diff --git a/R/codeditr-package.R b/R/codeditr-package.R index a212c8b..68edb2c 100644 --- a/R/codeditr-package.R +++ b/R/codeditr-package.R @@ -15,8 +15,8 @@ #' @name codeditr #' @importFrom methods is #' @importFrom tibble tibble -#' @importFrom dplyr mutate select case_when bind_rows +#' @importFrom dplyr mutate select case_when bind_rows rename_with #' @importFrom rlang .data -#' @importFrom stringr str_detect str_count +#' @importFrom stringr str_detect str_count str_replace_all str_trim #' "_PACKAGE" diff --git a/R/data.R b/R/data.R index d2efec3..2d0350c 100644 --- a/R/data.R +++ b/R/data.R @@ -43,6 +43,23 @@ "icd11_example" +#' +#' Unlikely causes of death for ICD 10 +#' +#' @format A data frame with 2 columns and 424 rows: +#' +#' | **Variable** | **Description** | +#' | :--- | :--- | +#' | *code* | ICD 10 Cause of Death code | +#' | *title* | Cause of death title | +#' +#' @examples +#' icd10_unlikely_cod +#' +#' @source https://icd.who.int/browse10/Content/statichtml/ICD10Volume2_en_2019.pdf +#' +"icd10_unlikely_cod" + #' #' Unlikely causes of death for ICD 11 diff --git a/data-raw/process_unlikely_cod.R b/data-raw/process_unlikely_cod.R index f3a578a..b4882cf 100644 --- a/data-raw/process_unlikely_cod.R +++ b/data-raw/process_unlikely_cod.R @@ -19,3 +19,118 @@ icd11_unlikely_cod <- rvest::read_html(x = "data-raw/value_sets.html") |> usethis::use_data(icd11_unlikely_cod, compress = "xz") +## ICD 10 unlikely causes of death ---- + +icd_10_guide <- pdftools::pdf_text("data-raw/ICD10Volume2_en_2019.pdf") + + +icd10_unlikely_cod <- icd_10_guide |> + (\(x) x[238:255])() |> + stringr::str_split(pattern = "\n") |> + lapply( + FUN = function(x) ifelse( + stringr::str_detect( + string = x, + pattern = "List of conditions unlikely to cause death|INTERNATIONAL CLASSIFICATION OF DISEASES|[0-9]{3}|Code|HIV|SP3" + ), + "", x + ) |> + (\(x) x[x != ""])() |> + stringr::str_trim(side = "left") |> + stringr::str_replace_all(pattern = "–", replacement = "-") |> + stringr::str_replace_all(pattern = ", ", replacement = ",") + ) + + +icd10_unlikely_cod[[2]] <- icd10_unlikely_cod[[2]] |> + (\(x) c(x[1:23], paste(x[24], x[25]), x[26:27]))() |> + (\(x) c(x[1:24], paste(x[25], x[26])))() + +icd10_unlikely_cod[[3]] <- icd10_unlikely_cod[[3]] |> + (\(x) + c(x[1:2], paste(x[3], x[4]), x[5:7], paste(x[8], x[9]), + x[10:11], paste(x[12], x[13]), paste(x[14], x[15]), x[16:27]) + )() + +icd10_unlikely_cod[[4]] <- icd10_unlikely_cod[[4]] |> + (\(x) c(x[1], paste(x[2], x[3]), x[4:9], paste(x[10], x[11]), x[12:27]))() + +icd10_unlikely_cod[[5]] <- icd10_unlikely_cod[[5]] |> + (\(x) c(x[1:17], paste(x[18], x[19]), x[20:25]))() + +icd10_unlikely_cod[[7]] <- icd10_unlikely_cod[[7]] |> + (\(x) c(x[1:14], paste(x[15], x[16]), x[17:25]))() + +icd10_unlikely_cod[[9]] <- icd10_unlikely_cod[[9]] |> + (\(x) c(x[1:17], paste(x[18], x[19]), x[20], paste(x[21], x[22]), x[23:26]))() + +icd10_unlikely_cod[[10]] <- icd10_unlikely_cod[[10]] |> + (\(x) c(x[1:21], paste(x[22], x[23]), x[24:27]))() + +icd10_unlikely_cod[[13]] <- icd10_unlikely_cod[[13]] |> + (\(x) c(x[1:6], paste(x[7], x[8]), x[9:25]))() + +icd10_unlikely_cod[[14]] <- icd10_unlikely_cod[[14]] |> + (\(x) + c(paste(x[1], x[2]), x[3:6], paste(x[7], x[8]), x[9:11], + paste(x[12], x[13]), x[14:20], paste(x[21], x[22]), paste(x[23], x[24]), + paste(x[25], x[26]), paste(x[27], x[28]), + paste(x[29], icd10_unlikely_cod[[15]][1])) + )() + +icd10_unlikely_cod[[15]] <- icd10_unlikely_cod[[15]] |> + (\(x) + c(paste(x[2], x[3]), paste(x[4], x[5]), paste(x[6], x[7]), x[8], + paste(x[9], x[10]), x[11:15], paste(x[16], x[17]), x[18:22], + paste(x[23], x[24]), x[25:28]) + )() + +icd10_unlikely_cod[[16]] <- icd10_unlikely_cod[[16]] |> + (\(x) c(x[1:19], paste(x[20], x[21]), x[22:25], paste(x[26], x[27])))() + +icd10_unlikely_cod[[17]] <- icd10_unlikely_cod[[17]] |> + (\(x) + c(x[1:11], paste(x[12], x[13]), x[14:16], paste(x[17], x[18]), + paste(x[19], x[20]), x[21:27]) + )() + +icd10_unlikely_cod[[18]] <- icd10_unlikely_cod[[18]] |> + (\(x) c(x[1:11], paste(x[12], x[13]), x[14], paste(x[15], x[16]), x[17]))() + +icd10_unlikely_cod <- lapply( + X = icd10_unlikely_cod, + FUN = stringr::str_split, + pattern = " ", + n = 2, + simplify = TRUE +) |> + (\(x) do.call(rbind, x))() |> + data.frame() |> + dplyr::rename_with(.fn = function(x) c("code", "title")) + +icd10_unlikely_cod$code[45] <- paste0( + icd10_unlikely_cod$code[45], icd10_unlikely_cod$code[46] +) + +icd10_unlikely_cod$code[75] <- paste0( + icd10_unlikely_cod$code[75], icd10_unlikely_cod$code[76] +) + +icd10_unlikely_cod$code[212] <- paste0( + icd10_unlikely_cod$code[212], icd10_unlikely_cod$code[213] +) + +icd10_unlikely_cod$code[399] <- paste0( + icd10_unlikely_cod$code[399], icd10_unlikely_cod$code[400] +) + +icd10_unlikely_cod$code[409] <- paste0( + icd10_unlikely_cod$code[409], icd10_unlikely_cod$code[410] +) + +icd10_unlikely_cod <- icd10_unlikely_cod |> + dplyr::filter(title != "") |> + dplyr::mutate(title = stringr::str_trim(title)) |> + tibble::tibble() + +usethis::use_data(icd10_unlikely_cod, overwrite = TRUE, compress = "xz") diff --git a/data/icd10_unlikely_cod.rda b/data/icd10_unlikely_cod.rda new file mode 100644 index 0000000..1d23b3b Binary files /dev/null and b/data/icd10_unlikely_cod.rda differ diff --git a/inst/WORDLIST b/inst/WORDLIST index 55c82eb..59d969f 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -16,9 +16,9 @@ YYYY codedit icd icdcdn -illdefined int referenceguide +statichtml tibble valuesets www diff --git a/man/icd10_unlikely_cod.Rd b/man/icd10_unlikely_cod.Rd new file mode 100644 index 0000000..a4cb26b --- /dev/null +++ b/man/icd10_unlikely_cod.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{icd10_unlikely_cod} +\alias{icd10_unlikely_cod} +\title{Unlikely causes of death for ICD 10} +\format{ +A data frame with 2 columns and 424 rows:\tabular{ll}{ + \strong{Variable} \tab \strong{Description} \cr + \emph{code} \tab ICD 10 Cause of Death code \cr + \emph{title} \tab Cause of death title \cr +} +} +\source{ +https://icd.who.int/browse10/Content/statichtml/ICD10Volume2_en_2019.pdf +} +\usage{ +icd10_unlikely_cod +} +\description{ +Unlikely causes of death for ICD 10 +} +\examples{ +icd10_unlikely_cod + +} +\keyword{datasets} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index b8d8d1a..49e2067 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -73,6 +73,7 @@ reference: contents: - icd10_example - icd11_example + - icd10_unlikely_cod - icd11_unlikely_cod - icd11_cod_by_sex