Skip to contents

conceptCohort() creates a cohort table from patient records from the clinical tables in the OMOP CDM.

The following tables are currently supported for creating concept cohorts:

  • condition_occurrence

  • device_exposure

  • drug_exposure

  • measurement

  • observation

  • procedure_occurrence

  • visit_occurrence

Cohort duration is based on record start and end (e.g. condition_start_date and condition_end_date for records coming from the condition_occurrence tables). So that the resulting table satisfies the requirements of an OMOP CDM cohort table:

  • Cohort entries will not overlap. Overlapping records will be combined based on the overlap argument.

  • Cohort entries will not go out of observation. If a record starts outside of an observation period it will be silently ignored. If a record ends outside of an observation period it will be trimmed so as to end at the preceding observation period end date.

Usage

conceptCohort(
  cdm,
  conceptSet,
  name,
  exit = "event_end_date",
  overlap = "merge",
  inObservation = TRUE,
  table = NULL,
  useSourceFields = FALSE,
  subsetCohort = NULL,
  subsetCohortId = NULL
)

Arguments

cdm

A cdm reference.

conceptSet

A conceptSet, which can either be a codelist or a conceptSetExpression.

name

Name of the new cohort table created in the cdm object.

exit

How the cohort end date is defined. Can be either "event_end_date" or "event_start_date".

overlap

How to deal with overlapping records. In all cases cohort start will be set as the earliest start date. If "merge", cohort end will be the latest end date. If "extend", cohort end date will be set by adding together the total days from each of the overlapping records.

inObservation

If TRUE, only records in observation will be used. If FALSE, records before the start of observation period will be considered, with startdate the start of observation.

table

Name of OMOP tables to search for records of the concepts provided. If NULL, each concept will be search at the assigned domain in the concept table.

useSourceFields

If TRUE, the source concept_id fields will also be used when identifying relevant clinical records. If FALSE, only the standard concept_id fields will be used.

subsetCohort

A character refering to a cohort table containing individuals for whom cohorts will be generated. Only individuals in this table will appear in the generated cohort.

subsetCohortId

Optional. Specifies cohort IDs from the subsetCohort table to include. If none are provided, all cohorts from the subsetCohort are included.

Value

A cohort table

Examples

# \donttest{
library(CohortConstructor)

cdm <- mockCohortConstructor(conditionOccurrence = TRUE, drugExposure = TRUE)

cdm$cohort <- conceptCohort(cdm = cdm, conceptSet = list(a = 444074), name = "cohort")
#> Warning: ! `codelist` casted to integers.
#>  Subsetting table condition_occurrence using 1 concept with domain: condition.
#>  Combining tables.
#>  Creating cohort attributes.
#>  Applying cohort requirements.
#>  Merging overlapping records.
#>  Cohort cohort created.

cdm$cohort |> attrition()
#> # A tibble: 6 × 7
#>   cohort_definition_id number_records number_subjects reason_id reason          
#>                  <int>          <int>           <int>     <int> <chr>           
#> 1                    1             10               6         1 Initial qualify…
#> 2                    1             10               6         2 Record start <=…
#> 3                    1             10               6         3 Record in obser…
#> 4                    1             10               6         4 Non-missing sex 
#> 5                    1             10               6         5 Non-missing yea…
#> 6                    1              6               6         6 Merge overlappi…
#> # ℹ 2 more variables: excluded_records <int>, excluded_subjects <int>

# Create a cohort based on a concept set. The cohort exit is set to the event start date.
# If two records overlap, the cohort end date is set as the sum of the duration of
# all overlapping records. Only individuals included in the existing `cohort` will be considered.

conceptSet <- list("nitrogen" = c(35604434, 35604439),
"potassium" = c(40741270, 42899580, 44081436))

cohort_drugs <- conceptCohort(cdm,
                             conceptSet = conceptSet,
                             name = "cohort_drugs",
                             exit = "event_start_date",
                             overlap = "extend",
                             subsetCohort = "cohort"
)
#> Warning: ! `codelist` casted to integers.
#>  Subsetting table drug_exposure using 5 concepts with domain: drug.
#>  Combining tables.
#>  Creating cohort attributes.
#>  Applying cohort requirements.
#>  Adding overlapping records.
#>  Re-appplying cohort requirements.
#>  Cohort cohort_drugs created.

cohort_drugs |> attrition()
#> # A tibble: 20 × 7
#>    cohort_definition_id number_records number_subjects reason_id reason         
#>                   <int>          <int>           <int>     <int> <chr>          
#>  1                    1              9               6         1 Initial qualif…
#>  2                    1              9               6         2 Record start <…
#>  3                    1              9               6         3 Record in obse…
#>  4                    1              9               6         4 Non-missing sex
#>  5                    1              9               6         5 Non-missing ye…
#>  6                    1              9               6         6 Add overlappin…
#>  7                    1              9               6         7 Record start <…
#>  8                    1              9               6         8 Record in obse…
#>  9                    1              9               6         9 Non-missing sex
#> 10                    1              9               6        10 Non-missing ye…
#> 11                    2             17               6         1 Initial qualif…
#> 12                    2             17               6         2 Record start <…
#> 13                    2             17               6         3 Record in obse…
#> 14                    2             17               6         4 Non-missing sex
#> 15                    2             17               6         5 Non-missing ye…
#> 16                    2             17               6         6 Add overlappin…
#> 17                    2             17               6         7 Record start <…
#> 18                    2             17               6         8 Record in obse…
#> 19                    2             17               6         9 Non-missing sex
#> 20                    2             17               6        10 Non-missing ye…
#> # ℹ 2 more variables: excluded_records <int>, excluded_subjects <int>
# }