Skip to contents

Adds a new cohort table to the cdm reference with individuals who have drug exposure records with the specified concepts. Cohort start and end dates will be based on drug record start and end dates, respectively. Records that overlap or have fewer days between them than the specified gap era will be concatenated into a single cohort entry.

Usage

generateDrugUtilisationCohortSet(
  cdm,
  name,
  conceptSet,
  gapEra = 1,
  subsetCohort = NULL,
  subsetCohortId = NULL,
  numberExposures = FALSE,
  daysPrescribed = FALSE,
  durationRange = lifecycle::deprecated(),
  imputeDuration = lifecycle::deprecated(),
  priorUseWashout = lifecycle::deprecated(),
  priorObservation = lifecycle::deprecated(),
  cohortDateRange = lifecycle::deprecated(),
  limit = lifecycle::deprecated()
)

Arguments

cdm

A cdm reference.

name

The name of the new cohort table to add to the cdm reference.

conceptSet

The concepts used to create the cohort, provide as a codelist or concept set expression.

gapEra

Number of days between two continuous exposures to be considered in the same era. Records that have fewer days between them than this gap will be concatenated into the same cohort record.

subsetCohort

Cohort table to subset.

subsetCohortId

Cohort id to subset.

numberExposures

Whether to include the number of exposures used to create each era.

daysPrescribed

Whether to include the number of days prescribed used to create each era.

durationRange

Deprecated.

imputeDuration

Deprecated.

priorUseWashout

Deprecated.

priorObservation

Deprecated.

cohortDateRange

Deprecated.

limit

Deprecated.

Value

The function returns the cdm reference provided with the addition of the new cohort table.

Examples

# \donttest{
library(CDMConnector)
library(DrugUtilisation)
library(dplyr)

cdm <- mockDrugUtilisation()
#> Warning: ! 7 column in condition_occurrence do not match expected column type:
#>  `stop_reason` is logical but expected character
#>  `provider_id` is logical but expected integer
#>  `visit_occurrence_id` is logical but expected integer
#>  `visit_detail_id` is logical but expected integer
#>  `condition_source_value` is logical but expected character
#>  `condition_source_concept_id` is logical but expected integer
#>  `condition_status_source_value` is logical but expected character
#> Warning: ! 3 column in concept do not match expected column type:
#>  `valid_start_date` is character but expected date
#>  `valid_end_date` is character but expected date
#>  `invalid_reason` is logical but expected character
#> Warning: ! 4 column in drug_strength do not match expected column type:
#>  `box_size` is logical but expected integer
#>  `valid_start_date` is character but expected date
#>  `valid_end_date` is character but expected date
#>  `invalid_reason` is logical but expected character

druglist <- CodelistGenerator::getDrugIngredientCodes(
  cdm, c("acetaminophen", "metformin"), nameStyle = "{concept_name}"
)
#> Warning: ! `codelist` contains numeric values, they are casted to integers.

cdm <- generateDrugUtilisationCohortSet(
  cdm = cdm,
  name = "drug_cohorts",
  conceptSet = druglist,
  gapEra = 30,
  numberExposures = TRUE,
  daysPrescribed = TRUE
)
#>  Subsetting drug_exposure table
#>  Checking whether any record needs to be dropped.
#>  Collapsing overlaping records.
#>  Collapsing records with gapEra = 30 days.

cdm$drug_cohorts |>
  glimpse()
#> Rows: ??
#> Columns: 6
#> Database: DuckDB v1.1.3-dev165 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#> $ cohort_definition_id <int> 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1
#> $ subject_id           <int> 10, 3, 8, 2, 2, 1, 9, 3, 8, 2, 4, 6
#> $ cohort_start_date    <date> 2015-10-21, 2018-01-09, 2021-05-28, 2021-07-09, 2…
#> $ cohort_end_date      <date> 2018-02-05, 2019-08-04, 2021-06-07, 2021-09-24, 2…
#> $ number_exposures     <int> 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1
#> $ days_prescribed      <int> 1619, 573, 11, 78, 4, 958, 25, 9, 37, 31, 43, 48
# }