Skip to contents

To add a new column with the days exposed. To add multiple columns use addDrugUtilisation() for efficiency.

Usage

addDaysExposed(
  cohort,
  conceptSet,
  gapEra,
  indexDate = "cohort_start_date",
  censorDate = "cohort_end_date",
  restrictIncident = TRUE,
  nameStyle = "days_exposed_{concept_name}",
  name = NULL
)

Arguments

cohort

A cohort_table object.

conceptSet

List of concepts to be included.

gapEra

Number of days between two continuous exposures to be considered in the same era.

indexDate

Name of a column that indicates the date to start the analysis.

censorDate

Name of a column that indicates the date to stop the analysis, if NULL end of individuals observation is used.

restrictIncident

Whether to include only incident prescriptions in the analysis. If FALSE all prescriptions that overlap with the study period will be included.

nameStyle

Character string to specify the nameStyle of the new columns.

name

Name of the new computed cohort table, if NULL a temporary table will be created.

Value

The same cohort with the added column.

Examples

# \donttest{
library(DrugUtilisation)

cdm <- mockDrugUtilisation()
codelist <- CodelistGenerator::getDrugIngredientCodes(
  cdm,
  name = "acetaminophen"
)
cdm <- generateDrugUtilisationCohortSet(
  cdm = cdm, name = "dus_cohort", conceptSet = codelist
)
#>  Subsetting drug_exposure table
#>  Checking whether any record needs to be dropped.
#>  Collapsing overlaping records.
#>  Collapsing records with gapEra = 1 days.

cdm$dus_cohort |>
  addDaysExposed(conceptSet = codelist, gapEra = 1)
#> # Source:   table<og_029_1734615693> [?? x 5]
#> # Database: DuckDB v1.1.3 [unknown@Linux 6.8.0-1017-azure:R 4.4.2/:memory:]
#>   cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                  <int>      <int> <date>            <date>         
#> 1                    1          5 2022-11-04        2022-11-30     
#> 2                    1          9 2016-10-20        2018-07-20     
#> 3                    1          9 2020-04-01        2020-08-22     
#> 4                    1          9 2020-11-07        2021-01-19     
#> 5                    1          1 2001-06-15        2006-07-13     
#> 6                    1          8 1995-08-19        1995-12-08     
#> 7                    1          9 2018-11-06        2019-12-30     
#> 8                    1          3 2012-12-13        2013-04-06     
#> # ℹ 1 more variable: days_exposed_161_acetaminophen <int>
# }