Skip to contents

Writes every column that `add_lmed_v20260922()` writes, and adds `approach4`, `rd_approach4_single` and `rd_approach4_multiple`. It reads `inst/2023-mht/product_table_20260924.xlsx` and `inst/2023-mht/dataDictionary20260924.xlsx`, and no other workbook.

Usage

add_lmed_v20260924(
  skeleton,
  lmed,
  id_name = "lopnr",
  create_rd = TRUE,
  verbose = TRUE
)

Arguments

skeleton

A person-week `data.table` with `id` and `isoyearweek`. Weekly rows only, as for `add_lmed_v20260922()`.

lmed

A `data.table` of dispensed prescriptions.

id_name

The person identifier column of `lmed`.

create_rd

Logical. If `FALSE`, writes no `rd_approach*` column.

verbose

Logical. If `TRUE`, report progress with `message()`.

Value

`invisible(skeleton)`. Mutation is in place.

Details

Every column other than the three approach 4 columns equals the output of `add_lmed_v20260922()`. Approach 4 splits systemic oestrogen by route and by progestogen type. The `post_grouping` sheet gives it these levels:

  • `oral_estrogen_progesterone`: B4 or B11, or oral oestrogen (A2 or A6) with C1 or C5.

  • `oral_estrogen_other_progestogen`: B2, B3, B5, B6, B8, B9, B10 or B12, or A2 or A6 with C3, C4, D1, D2, D3, E1, I1 or I2.

  • `transdermal_estrogen_progesterone`: transdermal oestrogen (A1) with C1 or C5.

  • `transdermal_estrogen_other_progestogen`: B1 or B7, or A1 with C3, C4, D1, D2, D3, E1, I1 or I2.

  • `estrogen_only`: A1, A2 or A6, in a week with no B1 to B12, C1 to C5, D1 to D3, E1, I1 or I2.

  • `tibolone`: F1.

  • `local_or_none_mht`: a week that lights no level above.

The resolver is that of `add_lmed_v20260922()`. When two levels are lit, `approach4` reports the level that started most recently. Two levels that start in the same week are `clashingprescriptions` until the treated episode ends.

See also

add_lmed_v20260922, which documents the behaviour the two entry points share. `vignette("lmed-v20260924")` explains approach 4, and checks each of its worked cases when it builds.

Examples

library(data.table)

skeleton <- copy(fake_skeleton_mht)
lmed <- copy(fake_lmed_2026)

# Utrogestan takes a codebook rule keyed on strength, so it needs `lnmn`.
lmed[, lnmn := NA_character_]
#>      lopnr     produkt     edatum  fddd   lnmn
#>      <int>      <char>     <Date> <num> <char>
#>   1:     1     Divigel 2015-01-05    90   <NA>
#>   2:     1     Divigel 2015-03-30    90   <NA>
#>   3:     1     Divigel 2015-06-22    90   <NA>
#>   4:     1     Divigel 2015-09-14    90   <NA>
#>   5:     1     Divigel 2015-12-07    90   <NA>
#>  ---                                          
#> 124:    16     Divigel 2016-02-26    90   <NA>
#> 125:    16   Cerazette 2016-03-01    90   <NA>
#> 126:    17     Divigel 2015-01-07   -30   <NA>
#> 127:    17     Divigel 2015-03-31    90   <NA>
#> 128:    18 Paracetamol 2015-01-02    28   <NA>
lmed[produkt == "Utrogestan", lnmn := "Utrogestan, kapsel, mjuk 100 mg"]
#> Index: <produkt>
#>      lopnr     produkt     edatum  fddd   lnmn
#>      <int>      <char>     <Date> <num> <char>
#>   1:     1     Divigel 2015-01-05    90   <NA>
#>   2:     1     Divigel 2015-03-30    90   <NA>
#>   3:     1     Divigel 2015-06-22    90   <NA>
#>   4:     1     Divigel 2015-09-14    90   <NA>
#>   5:     1     Divigel 2015-12-07    90   <NA>
#>  ---                                          
#> 124:    16     Divigel 2016-02-26    90   <NA>
#> 125:    16   Cerazette 2016-03-01    90   <NA>
#> 126:    17     Divigel 2015-01-07   -30   <NA>
#> 127:    17     Divigel 2015-03-31    90   <NA>
#> 128:    18 Paracetamol 2015-01-02    28   <NA>

# The product table holds no row for the fixture-only name `Paracetamol`.
lmed <- lmed[produkt != "Paracetamol"]

# the fixture holds one negative-duration row, which warns
skeleton <- suppressWarnings(
  add_lmed_v20260924(skeleton, lmed, verbose = FALSE)
)
skeleton[, .N, keyby = .(approach4)]
#> Key: <approach4>
#>                                 approach4     N
#>                                    <char> <int>
#> 1:                          estrogen_only   640
#> 2:                      local_or_none_mht  4779
#> 3:        oral_estrogen_other_progestogen    28
#> 4:             oral_estrogen_progesterone    10
#> 5:                               tibolone     5
#> 6: transdermal_estrogen_other_progestogen    82
#> 7:      transdermal_estrogen_progesterone    72