Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 📝 moved logic into algorithm.csv #190

Open
wants to merge 4 commits into
base: docs/design-into-algorithm-and-pseudocode
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified R/sysdata.rda
Binary file not shown.
19 changes: 12 additions & 7 deletions data-raw/algorithm.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
register,name,title,logic,comments
lab_forsker,hba1c,HbA1c inclusion,(analysiscode == 'NPU27300' AND value >= 48) OR (analysiscode == 'NPU03835' AND value >= 6.5),Is the IFCC units for NPU27300 and DCCT units for NPU03835
lmdb,gld,Glucose-lowering drug inclusion,atc =~ '^A10' AND !(atc =~ '^(A10BJ|A10BK01|A10BK03)'),Do not keep GLP-RAs or dapagliflozin/empagliflozin drugs
lpr_diag,lpr2,Relevant LPR2 diagnoses codes,c_diag =~ '^(DO0[0-6]|DO8[0-4]|DZ3[37]|DE1[0-4]|249|250)' AND (c_diagtype == 'A' OR c_diagtype == 'B'),'A' c_diagtype means primary diagnosis
lab_forsker,hba1c,HbA1c inclusion,(analysiscode == 'NPU27300' AND value >= 48) OR (analysiscode == 'NPU03835' AND value >= 6.5),Is the IFCC units for NPU27300 and DCCT units for NPU03835.
lmdb,gld,Glucose-lowering drug inclusion,atc =~ '^A10' AND !(atc =~ '^(A10BJ|A10BK01|A10BK03)'),Do not keep GLP-RAs or dapagliflozin/empagliflozin drugs.
lpr_diag,lpr2,Relevant LPR2 diagnoses codes,c_diag =~ '^(DO0[0-6]|DO8[0-4]|DZ3[37]|DE1[0-4]|249|250)' AND (c_diagtype == 'A' OR c_diagtype == 'B'),'A' `c_diagtype` means primary diagnosis.
lwjohnst86 marked this conversation as resolved.
Show resolved Hide resolved
lpr_diag,lpr2_has_t1d,LPR2 diagnoses codes for T1D,c_diag =~ '^(DE10|249)',
lpr_diag,lpr2_has_t2d,LPR2 diagnoses codes for T2D,c_diag =~ '^(DE11|250)',
lpr_diag,lpr2_has_pregnancy_event,LPR2 diagnoses codes for pregnancy-related outcomes,c_diag =~ '^(DO0[0-6]|DO8[0-4]|DZ3[37])',These are recorded pregnancy endings like live births and miscarriages
lpr_adm,lpr2_is_endocrinology_department,LPR2 endocrinology department,"na_if(c_spec, !(c_spec %in% 8:30)) == 8","True is when the department is endocrinology, false is when it is other medical departments, and missing is all other cases."
kontakter,lpr3_is_endocrinology_department,LPR3 endocrinology department,"na_if(hovedspeciale_ans, !(hovedspeciale_ans %in% c('medicinsk endokrinologi', 'blandet medicin og kirurgi', 'intern medicin', 'geriatri', 'hepatologi', 'hæmatologi', 'infektionsmedicin', 'kardiologi', 'medicinsk allergologi', 'medicinsk gastroenterologi', 'medicinsk lungesygdomme', 'nefrologi', 'reumatologi', 'palliativ medicin', 'akut medicin', 'dermato-venerologi', 'neurologi', 'onkologi', 'fysiurgi', 'tropemedicin'))) == 'medicinsk endokrinologi'","True is when the department is endocrinology, false is when it is other medical departments, and missing is all other cases."
,exclude_pregnancy,Remove events within a potential pregnancy period,!(has_pregnancy_event AND has_elevated_hba1c AND (date >= (pregnancy_event_date - weeks(40)) OR date <= (pregnancy_event_date + weeks(12)))),
lpr_diag,lpr2_has_pregnancy_event,LPR2 diagnoses codes for pregnancy-related outcomes,c_diag =~ '^(DO0[0-6]|DO8[0-4]|DZ3[37])',These are recorded pregnancy endings like live births and miscarriages.
lpr_adm,lpr2_is_endocrinology_department,LPR2 endocrinology department,"na_if(c_spec, !(c_spec %in% 8:30)) == 8","`TRUE` when the department is endocrinology,`FALSE` when it is other medical departments, and missing is all other cases."
kontakter,lpr3_is_endocrinology_department,LPR3 endocrinology department,"na_if(hovedspeciale_ans, !(hovedspeciale_ans %in% c('medicinsk endokrinologi', 'blandet medicin og kirurgi', 'intern medicin', 'geriatri', 'hepatologi', 'hæmatologi', 'infektionsmedicin', 'kardiologi', 'medicinsk allergologi', 'medicinsk gastroenterologi', 'medicinsk lungesygdomme', 'nefrologi', 'reumatologi', 'palliativ medicin', 'akut medicin', 'dermato-venerologi', 'neurologi', 'onkologi', 'fysiurgi', 'tropemedicin'))) == 'medicinsk endokrinologi'","`TRUE` when the department is endocrinology, `FALSE` when it is other medical departments, and missing in all other cases."
diagnoser,lpr3,Relevant LPR3 diagnoses codes,diagnosekode =~ '^(DO0[0-6]|DO8[0-4]|DZ3[37]|DE1[0-4])' AND (diagnosetype == 'A' OR diagnosetype == 'B') AND (senere_afkraeftet == "Nej"),'A' `diagnosekode` means primary diagnosis and `senere_afkraeftet` means diagnosis was later retracted.
diagnoser,lpr3_has_t1d,LPR3 diagnoses codes for T1D,diagnosekode =~ '^(DE10)',
diagnoser,lpr3_has_t2d,LPR3 diagnoses codes for T2D,diagnosekode =~ '^(DE11)',
,no_pregnancy,Remove events within a potential pregnancy period,!(has_pregnancy_event AND has_elevated_hba1c AND (date >= (pregnancy_event_date - weeks(40)) OR date <= (pregnancy_event_date + weeks(12)))),
,podiatrist_services,speciale =~ '^54' AND barnmak != 0,`barnmak` means the services were provided to a child of the individual.
,no_potential_pcos,"koen == 2 AND atc =~ '^A10BA02$' AND ((date - foed_dato) < 40 OR indication_code %in% c('0000092', '0000276', '0000781'))",Woman is defined as 2 in `koen`.
lwjohnst86 marked this conversation as resolved.
Show resolved Hide resolved
Binary file modified data/algorithm.rda
Binary file not shown.
Binary file modified data/register_data.rda
Binary file not shown.
163 changes: 83 additions & 80 deletions vignettes/algorithm.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,18 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
comment = "#>",
echo = FALSE
)
```

```{r setup}
library(osdc)
library(dplyr)
```

## `lpr_diag`

```{r, echo=FALSE}
algorithm |>
filter(register == "lpr_diag") |>
knitr::kable()
```

## `lpr_adm`

```{r, echo=FALSE}
algorithm |>
filter(register == "lpr_adm") |>
knitr::kable()
```

## `diagnoser`

- `diagnosekode` starts with "DO0[0-6]", "DO8[0-4]", "DZ3[37]" or
"DE1[0-4]".
- Is T1D if `diagnosekode` starts with "DE10".
- Is T2D if `diagnosekode` starts with "DE11".
- `diagnosetype` is equal to either "A" or "B".
- Is a primary diagnosis if it equals "A".
- `senere_afkraeftet` (if the diagnosis was later retracted) is equal
to "Nej".

## `kontakter`

- `hovedspeciale_ans` (hospital department) is categorized as
"endocrinology" if it equals "medicinsk endokrinologi" or as "other
medical" if it equals any of "Blandet medicin og kirurgi", "Intern
medicin", "Geriatri", "Hepatologi", "Hæmatologi",
"Infektionsmedicin", "Kardiologi", "Medicinsk allergologi",
"Medicinsk gastroenterologi", "Medicinsk lungesygdomme",
"Nefrologi", "Reumatologi", "Palliativ medicin", "Akut medicin",
"Dermato-venerologi", "Neurologi", "Onkologi", "Fysiurgi", or
"Tropemedicin".

## `lab_forsker`

```{r, echo=FALSE}
algorithm |>
filter(name == "hba1c") |>
knitr::kable()
```
## General description

## `ssyi` and `sssy`

- `speciale` starts with "54".
- `barnmark` (services provided to a child of the individual) is not
equal to 0.

## `lmdb`

```{r, echo=FALSE}
algorithm |>
filter(name == "gld") |>
knitr::kable()
```

## `bef` and only GLD (via `lmdb`)

To remove those with potential polycystic ovary syndrome:

- `atc` starts with "A10BA02" and `koen` is equal to 2 (woman) and
(`date` minus `foed_dato` (birth date) is less than 40 or
`indication_code` equals one of "0000092", "0000276" or "0000781")

## Pregnancy events

```{r, echo=FALSE}
algorithm |>
filter(name == "exclude_pregnancy") |>
knitr::kable()
```
A more complete description of the classifier is found in Anders Aasted
Isaksen's [PhD Thesis](https://aastedet.github.io/dissertation/) as well
as the validation paper [@Isaksen2023]. The description of the algorithm
Expand Down Expand Up @@ -157,4 +81,83 @@ year prior to the index date.

Individuals not classified as T1D cases are classified as T2D cases.

## Detailed and technical description

Below are the technical, exact implementation of the above description.
These are the logical conditions and exact variables and registers used
that results in the classification of diabetes status and types. They are
shown in the form of tables for each register, as well as for each

### `lpr_diag`

```{r}
algorithm |>
filter(register == "lpr_diag") |>
knitr::kable()
```

### `lpr_adm`

```{r}
algorithm |>
filter(register == "lpr_adm") |>
knitr::kable()
```

### `diagnoser`

```{r}
algorithm |>
filter(register == "diagnoser") |>
knitr::kable()
```

### `kontakter`

```{r}
algorithm |>
filter(register == "kontakter") |>
knitr::kable()
```

### `lab_forsker`

```{r}
algorithm |>
filter(name == "hba1c") |>
knitr::kable()
```

### `ssyi` and `sssy` for podiatrist services

```{r}
algorithm |>
filter(name == "podiatrist_services") |>
knitr::kable()
```

### `lmdb` for glucose lowering drugs

```{r}
algorithm |>
filter(name == "gld") |>
knitr::kable()
```

### `bef` and only GLD (via `lmdb`) for potential polycystic ovary syndrome

```{r}
algorithm |>
filter(name == "no_potential_pcos") |>
knitr::kable()
```

### Pregnancy events

```{r}
algorithm |>
filter(name == "no_pregnancy") |>
knitr::kable()
```

## References