Last updated: 2022-03-16
Checks: 5 2
Knit directory: codemapper/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.
The global environment had objects present when the code in the R Markdown file was run. These objects can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment. Use wflow_publish or wflow_build to ensure that the code is always run in an empty environment.
The following objects were defined in the global environment when these results were created:
| Name | Class | Size |
|---|---|---|
| install_codemapper | function | 1.2 Kb |
The command set.seed(20210923) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version b425304. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Renviron
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: _targets/
Ignored: all_lkps_maps.db
Ignored: all_lkps_maps.db.gz
Ignored: renv/library/
Ignored: renv/staging/
Ignored: tar_make.R
Unstaged changes:
Modified: R/clinical_codes.R
Modified: R/lookups_and_mappings.R
Modified: R/utils.R
Modified: _targets.R
Modified: analysis/read2_icd10_mapping.Rmd
Modified: analysis/read3_icd10_mapping.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/read2_icd10_mapping.Rmd) and HTML (public/read2_icd10_mapping.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.
| File | Version | Author | Date | Message |
|---|---|---|---|---|
| Rmd | b425304 | rmgpanw | 2022-03-15 | add code and tests to reformat read2 to icd10 mapping table |
| Rmd | dfbc621 | Chuin Ying Ung | 2022-02-22 | add mapping notes |
| Rmd | 5b80a79 | Chuin Ying Ung | 2022-02-22 | update notes |
library(tidyverse)
library(reactable)
library(readxl)
library(crosstalk)
library(targets)
library(codemapper)
library(flextable)
all_lkps_maps <- tar_read(all_lkps_maps_raw) %>%
purrr::map(codemapper:::rm_footer_rows_all_lkps_maps_df) %>%
purrr::map(~ tibble::rowid_to_column(.data = .x,
var = ".rowid"))
read_v2_icd10 <- all_lkps_maps$read_v2_icd10
icd10_lkp <- all_lkps_maps$icd10_lkp
# utility functions
append_read_icd10_descriptions <- function(df,
read_type = "read2") {
match.arg(read_type,
c("read2", "read3"))
# get read and icd10 descriptions
read_df <- df$read_code %>%
lookup_codes(code_type = read_type,
unrecognised_codes = "warning") %>%
select(read_code = code,
description_read3 = description)
icd10_df <- df$icd10_code %>%
lookup_codes(code_type = "icd10",
unrecognised_codes = "warning") %>%
select(icd10_code = code,
description_icd10 = description)
# append descriptions
list(df,
read_df,
icd10_df) %>%
reduce(full_join) %>%
select(contains("read"),
contains("icd10"),
everything())
}
Where a Read 2 code maps to multiple ICD10 codes, a range of ICD10 codes is presented in the icd10_code column. This needs reformatting (to allow programmatic mapping from Read 2 to ICD10) so that each ICD10 code appears on a separate row.
The following additional reformatting operations are also required to ensure that the ICD10 codes in this mapping table match the ALT_CODE format in lookup table icd10_lkp:
Remove appended ‘D’/‘A’ characters from dagger/asterisk ICD10 codes, and create a separate indicator column for these instead.
Some undivided 3 character ICD10 codes appear inconsistently without an appended ‘X’. For example, ‘A64X’ appears as ‘A50-A64’, ‘A65X’ appears as ‘A65-A69’, ‘A70X’ as ‘A70-A74’, ‘A89X’ as ‘A80-A89’ and ‘A99X’ as ‘A92-A99’. The ‘X’ is re-appended to these codes during reformatting to match the ALT_CODE format in lookup table icd10_lkp.
ICD10 code “C836” (“Diffuse non-Hodgkin’s lymphoma - Undifferentiated (diffuse)”) has been removed from ICD10 and does not exist in the icd10_lkp table. It is therefore also removed from the reformatted read_v2_icd10 mapping table.
It is often appropriate to map a single Read 2 code to multiple ICD10 codes, where more than one ICD10 code is required to define a single specific Read 2 cod (see examples below). However, it may not be desirable to map a single Read 2 code with a non-specific description to multiple specific ICD10 codes. For example, the Read 2 code for ‘Diabetes mellitus’, ‘C10..’, is mapped to ICD10 codes ‘E10-E14’, which include both type 1 and type 2 diabetes as well as all their potential complications (e.g. renal and ophthalmic complications). The map_codes function in codemapper excludes this category of mappings (flagged as icd10_code_def ‘2’ in the read_v2_icd10 mapping table) by default.
[1] TRUE
All Read 2 codes in the read_v2_icd10 mapping table are present in the read_v2_lkp lookup table.
# identify unrecognised ICD10 codes
unrecognised_icd10_codes <- subset(read_v2_icd10$icd10_code,
!read_v2_icd10$icd10_code %in% all_lkps_maps$icd10_lkp$ALT_CODE) %>%
unique()
There are 1438 ICD10 codes in the read_v2_icd10 mapping table that are not present in the icd10_lkp table (ALT_CODE format). These are mostly flagged by values in column icd10_code_def, with two exceptions:
icd10_lkptable.read_v2_icd10 mapping table.Some examples, ‘C836’ and ‘A64’ (the latter should appear as ‘A64X’):
read_v2_icd10 %>%
filter(str_detect(icd10_code,
pattern = "A64|C836")) %>%
append_read_icd10_descriptions() %>%
select(-.rowid) %>%
flextable()
read_code | description_read3 | icd10_code | icd10_code_def | description_icd10 |
A9... | Syphilis and other venereal diseases | A50-A64X | 2 | |
A99.. | Other venereal diseases | A55X-A64X | 2 | |
A99z. | Venereal disease NOS | A64X | 1 | Unspecified sexually transmitted disease |
A9z.. | Syphilis or venereal disease NOS | A50-A64 | 2 | |
Ayu4. | [X]Infections with a predominantly sexual mode of transmission | A50-A64X | 2 | |
Ayu4J | [X]Unspecified sexually transmitted disease | A64X | 1 | Unspecified sexually transmitted disease |
Ayu4N | [X]Sexually transmitted infectious disease | A50-A64 | 2 | |
B6278 | Diffuse non-Hodgkin's lymphoma undifferentiated (diffuse) | C836 | 1 |
icd10_code_defColumn icd10_code_def signifies, for example, whether or not the Read 2 code matches to a single ICD-10 code, if the ICD-10 code is a parent code that links to several child codes, if the ICD-10 code is asterisk or dagger code, a dagger-asterisk combination, etc.
Below are some example codes for each value in icd10_code_def:
read_v2_icd10 %>%
filter(!is.na(icd10_code_def)) %>%
mutate(
icd10_contains_dash = ifelse(str_detect(icd10_code,
"-"),
yes = "dash",
no = NA_character_),
icd10_contains_comma = ifelse(str_detect(icd10_code,
","),
yes = "comma",
no = NA_character_),
icd10_contains_space = ifelse(str_detect(icd10_code,
"\\s"),
yes = "space",
no = NA_character_),
icd10_contains_plus = ifelse(str_detect(icd10_code,
"\\+"),
yes = "plus",
no = NA_character_),
icd10_contains_da_ending = ifelse(str_detect(icd10_code,
"[D|A]$"),
yes = "DAending",
no = NA_character_)
) %>%
unite(col = "icd10_pattern",
starts_with("icd10_contains_"),
sep = "_",
remove = TRUE,
na.rm = TRUE) %>%
group_by(icd10_code_def,
icd10_pattern) %>%
slice(1L) %>%
ungroup() %>%
append_read_icd10_descriptions() %>%
arrange(description_icd10) %>%
select(icd10_code_def,
icd10_pattern,
everything()) %>%
select(-.rowid) %>%
flextable::as_grouped_data("icd10_code_def") %>%
flextable() %>%
suppressWarnings()
icd10_code_def | icd10_pattern | read_code | description_read3 | icd10_code | description_icd10 |
1 | |||||
A00.. | Cholera | A00 | Cholera | ||
15 | |||||
plus | A3805 | Vancomycin resistant enterococcal septicaemia | A408+U830 | ||
space_plus | A365. | Meningococcal meningitis with acute meningococcal septicaemia | A390D G01XA+A392 | ||
2 | |||||
dash | A0... | Intestinal infectious diseases | A00-A09 | ||
dash_DAending | A13.. | Tuberculosis of meninges and central nervous system | A170D-A179D | ||
3 | |||||
comma | A34.. | Streptococcal sore throat and scarlatina | J020,A38X | ||
5 | |||||
DAending | Cy0.. | Nutritional and metabolic disorders in diseases classified elsewhere | E90XA | ||
7 | |||||
space_DAending | A0221 | Salmonella meningitis | A022D G01XA | ||
8 | |||||
DAending | A13y. | Other specified tuberculosis of central nervous system | A178D |
Mappings categorised as icd10_code_def ‘1’, ‘5’ or ‘8’ are one-to-one, whereas the other categories are one-to-many. Read codes in category ‘2’ have non-specific descriptions and map to multiple specific ICD10 codes, which may be conflicting. The examples above are re-shown below with ICD10 code descriptions appended.
read_v2_icd10 %>%
filter(!is.na(icd10_code_def)) %>%
mutate(
icd10_contains_dash = ifelse(str_detect(icd10_code,
"-"),
yes = "dash",
no = NA_character_),
icd10_contains_comma = ifelse(str_detect(icd10_code,
","),
yes = "comma",
no = NA_character_),
icd10_contains_space = ifelse(str_detect(icd10_code,
"\\s"),
yes = "space",
no = NA_character_),
icd10_contains_plus = ifelse(str_detect(icd10_code,
"\\+"),
yes = "plus",
no = NA_character_),
icd10_contains_da_ending = ifelse(str_detect(icd10_code,
"[D|A]$"),
yes = "DAending",
no = NA_character_)
) %>%
unite(col = "icd10_pattern",
starts_with("icd10_contains_"),
sep = "_",
remove = TRUE,
na.rm = TRUE) %>%
group_by(icd10_code_def,
icd10_pattern) %>%
slice(1L) %>%
ungroup() %>%
codemapper:::reformat_read_v2_icd10(icd10_lkp = all_lkps_maps$icd10_lkp) %>%
append_read_icd10_descriptions() %>%
arrange(description_icd10) %>%
select(icd10_code_def,
icd10_pattern,
everything()) %>%
select(-.rowid) %>%
reactable(filterable = TRUE,
searchable = TRUE,
showPageSizeOptions = TRUE,
pageSizeOptions = c(10, 25, 50, 10),
groupBy = "icd10_code_def")
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] flextable_0.6.10 codemapper_0.0.0.9000 ukbwranglr_0.0.0.9000
[4] targets_0.8.0 crosstalk_1.1.1 readxl_1.3.1
[7] reactable_0.2.3 forcats_0.5.1 stringr_1.4.0
[10] dplyr_1.0.7 purrr_0.3.4 readr_2.0.2
[13] tidyr_1.1.4 tibble_3.1.4 ggplot2_3.3.5
[16] tidyverse_1.3.1 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] fs_1.5.0 bit64_4.0.5 lubridate_1.7.10 httr_1.4.2
[5] rprojroot_2.0.2 tools_4.1.0 backports_1.2.1 bslib_0.3.1
[9] utf8_1.2.2 R6_2.5.1 DBI_1.1.1 colorspace_2.0-2
[13] withr_2.4.3 tidyselect_1.1.1 processx_3.5.2 bit_4.0.4
[17] compiler_4.1.0 git2r_0.28.0 cli_3.0.1 rvest_1.0.1
[21] xml2_1.3.2 officer_0.4.1 sass_0.4.0 scales_1.1.1
[25] callr_3.7.0 systemfonts_1.0.4 digest_0.6.28 rmarkdown_2.11
[29] base64enc_0.1-3 pkgconfig_2.0.3 htmltools_0.5.2 dbplyr_2.1.1
[33] fastmap_1.1.0 highr_0.9 htmlwidgets_1.5.4 rlang_0.4.11
[37] RSQLite_2.2.9 rstudioapi_0.13 shiny_1.7.0 jquerylib_0.1.4
[41] generics_0.1.0 jsonlite_1.7.2 zip_2.2.0 magrittr_2.0.1
[45] Rcpp_1.0.7 munsell_0.5.0 fansi_0.5.0 gdtools_0.2.4
[49] lifecycle_1.0.1 stringi_1.7.4 whisker_0.4 yaml_2.2.1
[53] blob_1.2.2 grid_4.1.0 promises_1.2.0.1 crayon_1.4.1
[57] haven_2.4.3 hms_1.1.1 knitr_1.34 ps_1.6.0
[61] pillar_1.6.3 uuid_0.1-4 igraph_1.2.6 codetools_0.2-18
[65] reprex_2.0.1 glue_1.4.2 evaluate_0.14 data.table_1.14.2
[69] renv_0.13.2 modelr_0.1.8 vctrs_0.3.8 tzdb_0.1.2
[73] httpuv_1.6.3 cellranger_1.1.0 gtable_0.3.0 reactR_0.4.4
[77] assertthat_0.2.1 cachem_1.0.6 xfun_0.24 mime_0.12
[81] xtable_1.8-4 broom_0.7.9 later_1.3.0 memoise_2.0.0
[85] ellipsis_0.3.2