Skip to content

Commit 0826da0

Browse files
committed
Added Swedish version of ICD 10
#148
1 parent 957d871 commit 0826da0

File tree

127 files changed

+24791
-4570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+24791
-4570
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: coder
22
Type: Package
33
Title: Deterministic Categorization of Items Based on External Code Data
4-
Version: 0.13.10
4+
Version: 1.0
55
Authors@R:
66
c(
77
person("Erik", "Bulow", email = "[email protected]",
@@ -28,7 +28,8 @@ Description:
2828
'RxRisk V', or the 'comorbidity-polypharmacy' score (CPS), as well as adverse
2929
events after hip and knee replacement surgery.
3030
License: GPL-2
31-
Depends: R (>= 3.3)
31+
Depends:
32+
R (>= 3.5)
3233
Suggests:
3334
covr,
3435
testthat,
@@ -42,7 +43,7 @@ Imports:
4243
methods,
4344
tibble
4445
LazyData: TRUE
45-
RoxygenNote: 7.2.3
46+
RoxygenNote: 7.3.2
4647
Roxygen: list(markdown = TRUE)
4748
VignetteBuilder:
4849
knitr

MAKE.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ codemetar::write_codemeta()
2626
devtools::spell_check()
2727
devtools::check()
2828
goodpractice::goodpractice()
29-
rhub::check_for_cran()
29+
# rhub::check_for_cran()
3030
devtools::check_win_release()
3131
devtools::check_win_devel()
3232
devtools::check_win_oldrelease()

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# coder 1.0
2+
3+
Added Swedish Charlson version (only ICD-10) based on article by Ludvigsson et al. (2021).
4+
15
# coder 0.13.9
26

37
Small bug fix for CRAN checks

R/manual_for_datasets.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
#' All liver diseases (including mild) are included in
9898
#' "moderate or severe liver disease".
9999
#' All diabetes is included in "diabetes complication"
100+
#' - `icd10_swe:` Swedish version using ICD-10 by Ludvigsson et al. (2021).
101+
#' Note that chronic pulmonary disease is combined (separated as chronic and other in the article).
102+
#' Note that mild kidney disease combined with `R18`should also count as moderate or severe kidney disease
103+
#' (not implemented so must be handled manually).
100104
#' - `icd8_brusselaers:` Back translated version from ICD-10 to
101105
#' ICD-8 by Brusselaers et al. (2017).
102106
#' "Moderate and severe liver disease" contains all liver disease and
@@ -131,6 +135,10 @@
131135
#' administrative databases.
132136
#' Journal of Clinical Epidemiology, 45(6), 613–619.
133137
#'
138+
#' Ludvigsson, J. F., Appelros, P., Askling, J., Byberg, L., Carrero, J.-J., Ekström, A. M., Ekström, M., Smedby, K. E., Hagström, H., James, S., Järvholm, B., Michaelsson, K., Pedersen, N. L., Sundelin, H., Sundquist, K., Sundström, J.
139+
#' Adaptation of the Charlson Comorbidity Index for Register-Based Research in Sweden.
140+
#' CLEP 2021, 13, 21–41. https://doi.org/10.2147/CLEP.S282475.
141+
#'
134142
#' Quan Hude et al. (2005). Coding algorithms for defining
135143
#' comorbidities in ICD-9-CM and ICD-10 administrative data.
136144
#' Medical care, 1130-1139.

README.md

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,83 +57,105 @@ remotes::install_github("eribul/coder")
5757
Assume we have some patients with surgery at specified dates:
5858

5959

60-
```r
60+
``` r
6161
library(coder)
6262
ex_people
6363
#> # A tibble: 100 × 2
6464
#> name surgery
6565
#> <chr> <date>
66-
#> 1 Chen, Trevor 2023-02-28
67-
#> 2 Graves, Acineth 2022-11-20
68-
#> 3 Trujillo, Yanelly 2022-11-07
69-
#> 4 Simpson, Kenneth 2023-02-09
70-
#> 5 Chin, Nelson 2023-01-23
71-
#> 6 Le, Christina 2022-08-27
72-
#> 7 Kang, Xuan 2022-11-29
73-
#> 8 Shuemaker, Lauren 2022-08-28
74-
#> 9 Boucher, Teresa 2023-02-03
75-
#> 10 Le, Soraiya 2023-01-08
76-
#> # … with 90 more rows
66+
#> 1 Chen, Trevor 2025-04-21
67+
#> 2 Graves, Acineth 2025-01-11
68+
#> 3 Trujillo, Yanelly 2024-12-29
69+
#> 4 Simpson, Kenneth 2025-04-02
70+
#> 5 Chin, Nelson 2025-03-16
71+
#> 6 Le, Christina 2024-10-18
72+
#> 7 Kang, Xuan 2025-01-20
73+
#> 8 Shuemaker, Lauren 2024-10-19
74+
#> 9 Boucher, Teresa 2025-03-27
75+
#> 10 Le, Soraiya 2025-03-01
76+
#> # 90 more rows
7777
```
7878

7979
Those patients (among others) were also recorded in a national patient register with date of hospital admissions and diagnoses codes coded by the International Classification of Diseases (ICD) version 10:
8080

8181

82-
```r
82+
``` r
8383
ex_icd10
8484
#> # A tibble: 2,376 × 4
8585
#> name admission icd10 hdia
8686
#> <chr> <date> <chr> <lgl>
87-
#> 1 Tran, Kenneth 2022-09-11 S134A FALSE
88-
#> 2 Tran, Kenneth 2023-02-25 W3319 FALSE
89-
#> 3 Tran, Kenneth 2023-02-04 Y0262 TRUE
90-
#> 4 Tran, Kenneth 2022-12-28 X0488 FALSE
91-
#> 5 Sommerville, Dominic 2023-02-16 V8104 FALSE
92-
#> 6 Sommerville, Dominic 2022-09-27 B853 FALSE
93-
#> 7 Sommerville, Dominic 2023-02-11 Q174 FALSE
94-
#> 8 Sommerville, Dominic 2022-10-02 A227 FALSE
95-
#> 9 Sommerville, Dominic 2023-02-06 H702 FALSE
96-
#> 10 Sommerville, Dominic 2022-05-31 X6051 TRUE
97-
#> # … with 2,366 more rows
87+
#> 1 Tran, Kenneth 2024-11-02 S134A FALSE
88+
#> 2 Tran, Kenneth 2025-04-18 W3319 FALSE
89+
#> 3 Tran, Kenneth 2025-03-28 Y0262 TRUE
90+
#> 4 Tran, Kenneth 2025-02-18 X0488 FALSE
91+
#> 5 Sommerville, Dominic 2025-04-09 V8104 FALSE
92+
#> 6 Sommerville, Dominic 2024-11-18 B853 FALSE
93+
#> 7 Sommerville, Dominic 2025-04-04 Q174 FALSE
94+
#> 8 Sommerville, Dominic 2024-11-23 A227 FALSE
95+
#> 9 Sommerville, Dominic 2025-03-30 H702 FALSE
96+
#> 10 Sommerville, Dominic 2024-07-22 X6051 TRUE
97+
#> # 2,366 more rows
9898
```
9999

100100
Using those two data sets, as well as a classification scheme (`classcodes` object; see below), we can easily identify all Charlson comorbidities for each patient:
101101

102102

103-
```r
103+
``` r
104104
ch <-
105105
categorize(
106106
ex_people, # patients of interest
107107
codedata = ex_icd10, # Medical codes from national patient register
108108
cc = "charlson", # Calculate Charlson comorbidity
109109
id = "name", code = "icd10" # Specify column names
110110
)
111-
#> Error in UseMethod("categorize"): no applicable method for 'categorize' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
111+
#> Classification based on: icd10
112112

113113
ch
114-
#> Error in eval(expr, envir, enclos): object 'ch' not found
114+
#> # A tibble: 100 × 25
115+
#> name surgery myocardial.infarction congestive.heart.fai…¹ peripheral.vascular.…² cerebrovascular.dise…³ dementia
116+
#> <chr> <date> <lgl> <lgl> <lgl> <lgl> <lgl>
117+
#> 1 Chen, Trevor 2025-04-21 FALSE FALSE FALSE FALSE FALSE
118+
#> 2 Graves, Acineth 2025-01-11 FALSE FALSE FALSE FALSE FALSE
119+
#> 3 Trujillo, Yane… 2024-12-29 FALSE FALSE FALSE FALSE FALSE
120+
#> 4 Simpson, Kenne… 2025-04-02 FALSE FALSE FALSE FALSE FALSE
121+
#> 5 Chin, Nelson 2025-03-16 FALSE FALSE FALSE FALSE FALSE
122+
#> 6 Le, Christina 2024-10-18 FALSE FALSE FALSE FALSE FALSE
123+
#> 7 Kang, Xuan 2025-01-20 FALSE FALSE FALSE FALSE FALSE
124+
#> 8 Shuemaker, Lau… 2024-10-19 FALSE FALSE FALSE FALSE FALSE
125+
#> 9 Boucher, Teresa 2025-03-27 FALSE FALSE TRUE FALSE FALSE
126+
#> 10 Le, Soraiya 2025-03-01 FALSE FALSE FALSE FALSE FALSE
127+
#> # ℹ 90 more rows
128+
#> # ℹ abbreviated names: ¹​congestive.heart.failure, ²​peripheral.vascular.disease, ³​cerebrovascular.disease
129+
#> # ℹ 18 more variables: chronic.pulmonary.disease <lgl>, rheumatic.disease <lgl>, peptic.ulcer.disease <lgl>,
130+
#> # mild.liver.disease <lgl>, diabetes.without.complication <lgl>, hemiplegia.or.paraplegia <lgl>, renal.disease <lgl>,
131+
#> # diabetes.complication <lgl>, malignancy <lgl>, moderate.or.severe.liver.disease <lgl>, metastatic.solid.tumor <lgl>,
132+
#> # AIDS.HIV <lgl>, charlson <dbl>, deyo_ramano <dbl>, dhoore <dbl>, ghali <dbl>, quan_original <dbl>, quan_updated <dbl>
115133
```
116134

117135
How many patients were diagnosed with malignancy?
118136

119137

120-
```r
138+
``` r
121139
sum(ch$malignancy)
122-
#> Error in eval(expr, envir, enclos): object 'ch' not found
140+
#> [1] 5
123141
```
124142

125143
What is the distribution of the combined comorbidity index for each patient?
126144

127145

128-
```r
146+
``` r
129147
barplot(table(ch$charlson))
130-
#> Error in table(ch$charlson): object 'ch' not found
131148
```
132149

150+
<div class="figure">
151+
<img src="man/figures/READMEunnamed-chunk-5-1.png" alt="plot of chunk unnamed-chunk-5" width="100%" />
152+
<p class="caption">plot of chunk unnamed-chunk-5</p>
153+
</div>
154+
133155
There are many versions of the Charlson comorbidity index, which might be controlled by the `index` argument. We might also be interested only in diagnoses from 90 days before surgery as specified with an argument list `codify_args`as passed to `codify()`:
134156

135157

136-
```r
158+
``` r
137159
ch <-
138160
categorize(
139161
ex_people, codedata = ex_icd10, cc = "charlson", id = "name", code = "icd10",
@@ -146,25 +168,29 @@ ch <-
146168
days = c(-90, -1) # Time window
147169
)
148170
)
149-
#> Error in UseMethod("categorize"): no applicable method for 'categorize' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
171+
#> Classification based on: icd10
150172
```
151173

152174
Number of malignancies during this period?
153175

154176

155-
```r
177+
``` r
156178
sum(ch$malignancy, na.rm = TRUE)
157-
#> Error in eval(expr, envir, enclos): object 'ch' not found
179+
#> [1] 3
158180
```
159181

160182
Distribution of the index as proposed by Quan et al 2011 during the 90 day period:
161183

162184

163-
```r
185+
``` r
164186
barplot(table(ch$quan_updated))
165-
#> Error in table(ch$quan_updated): object 'ch' not found
166187
```
167188

189+
<div class="figure">
190+
<img src="man/figures/READMEunnamed-chunk-8-1.png" alt="plot of chunk unnamed-chunk-8" width="100%" />
191+
<p class="caption">plot of chunk unnamed-chunk-8</p>
192+
</div>
193+
168194
## Classification schemes
169195

170196
Classification schemes (`classcodes` objects, see `vignette("classcodes")`) are based on regular expressions for computational speed (see `vignette("Interpret_regular_expressions")`), but their content can be summarized and visualized for clarity. Arbitrary `classcodes` objects can also be specified by the user.
@@ -174,9 +200,18 @@ The package includes default `classcodes` for medical patient data based on the
174200
Default `classcades` are listed in the table. Each classification (classcodes column) can be based on several code systems (regex column) and have several alternative weighted indices (indices column). Those might be combined freely.
175201

176202

177-
```r
203+
``` r
178204
coder::all_classcodes()
179-
#> Error: 'all_classcodes' is not an exported object from 'namespace:coder'
205+
#> # A tibble: 7 × 3
206+
#> classcodes regex indices
207+
#> <chr> <chr> <chr>
208+
#> 1 charlson icd10, icd9cm_deyo, icd9cm_enhanced, icd10_rcs, icd10_swe, icd8_brusselaers, icd9_brusselaers "charlson, deyo_ra…
209+
#> 2 cps icd10 "only_ordinary"
210+
#> 3 elixhauser icd10, icd10_short, icd9cm, icd9cm_ahrqweb, icd9cm_enhanced "sum_all, sum_all_…
211+
#> 4 hip_ae icd10, kva, icd10_fracture ""
212+
#> 5 hip_ae_hailer icd10, kva ""
213+
#> 6 knee_ae icd10, kva ""
214+
#> 7 rxriskv atc_pratt, atc_caughey, atc_garland "pratt, sum_all"
180215
```
181216

182217
# Relation to other packages

_pkgdown.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
destination: docs
2-
url: ropensci.github.io/coder
2+
url: https://docs.ropensci.org/coder/
3+
4+
template:
5+
bootstrap: 5
36

47
authors:
58
Erik Bulow:

codemeta.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"codeRepository": "https://github.com/ropensci/coder",
88
"issueTracker": "https://github.com/ropensci/coder/issues",
99
"license": "https://spdx.org/licenses/GPL-2.0",
10-
"version": "0.13.10",
10+
"version": "1.0",
1111
"programmingLanguage": {
1212
"@type": "ComputerLanguage",
1313
"name": "R",
1414
"url": "https://r-project.org"
1515
},
16-
"runtimePlatform": "R version 4.2.0 (2022-04-22 ucrt)",
16+
"runtimePlatform": "R version 4.5.0 (2025-04-11)",
1717
"provider": {
1818
"@id": "https://cran.r-project.org",
1919
"@type": "Organization",
@@ -105,7 +105,7 @@
105105
"@type": "SoftwareApplication",
106106
"identifier": "R",
107107
"name": "R",
108-
"version": ">= 3.3"
108+
"version": ">= 3.5"
109109
},
110110
"2": {
111111
"@type": "SoftwareApplication",
@@ -162,7 +162,7 @@
162162
},
163163
"SystemRequirements": null
164164
},
165-
"fileSize": "329.777KB",
165+
"fileSize": "348.64KB",
166166
"relatedLink": ["https://docs.ropensci.org/coder/", "https://CRAN.R-project.org/package=coder"],
167167
"releaseNotes": "https://github.com/ropensci/coder/blob/master/NEWS.md",
168168
"readme": "https://github.com/ropensci/coder/blob/master/README.md",

data-raw/classcodes.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ rm(list = ls())
55
xl_path <- "data-raw/classcodes.xlsx"
66

77
# Read all classcodes from excel-file and give attributes
8-
tibble::tibble(names = readxl::excel_sheets(xl_path)) %>%
9-
mutate(
10-
data = map(names, ~ readxl::read_excel(xl_path, .)),
11-
classcode = map(data, as.classcodes) %>%
12-
set_names(names)
13-
) %>%
14-
{attach(.$classcode)} # Must be able to refer to each object by name in use_data
8+
ccs <-
9+
tibble::tibble(names = readxl::excel_sheets(xl_path)) |>
10+
dplyr::mutate(
11+
data = purrr::map(names, ~ readxl::read_excel(xl_path, .)),
12+
classcode = purrr::map(data, as.classcodes) |> setNames(names)
13+
)
14+
attach(ccs$classcode) # Must be able to refer to each object by name in use_data
1515

1616

1717

@@ -23,7 +23,7 @@ mutate(
2323
# I do not want to make a manual copy of all those codes but simply add a
2424
# fracture column based on existing codes.
2525
hip_ae$icd10_fracture <-
26-
if_else(
26+
dplyr::if_else(
2727
hip_ae$group == "DM1 other",
2828
paste0(hip_ae$icd10, "|N3(0[089]|90)"),
2929
hip_ae$icd10

data-raw/classcodes.xlsx

558 Bytes
Binary file not shown.

data/charlson.rda

227 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)