Restrict cohort to only cohort records with the given amount of prior observation time in the database
Source:R/require.R
requireObservationBeforeDrug.Rd
Filter the cohort table keeping only the cohort records for which the individual has the required observation time in the database prior to their cohort start date.
Usage
requireObservationBeforeDrug(
cohort,
days,
cohortId = NULL,
name = omopgenerics::tableName(cohort)
)
Arguments
- cohort
A cohort table in a cdm reference.
- days
Number of days of prior observation required before cohort start date. Any records with fewer days will be dropped.
- cohortId
IDs of the cohorts to modify. The default is NULL meaning all cohorts will be used; otherwise, only the specified cohorts will be modified, and the rest will remain unchanged.
- name
Name of the table with the filtered cohort records. The default name is the original cohort name, where the original table will be overwritten.
Examples
# \donttest{
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
cdm$cohort1 <- cdm$cohort1 |>
requireObservationBeforeDrug(days = 365)
attrition(cdm$cohort1) |> glimpse()
#> Rows: 6
#> Columns: 7
#> $ cohort_definition_id <int> 1, 1, 2, 2, 3, 3
#> $ number_records <int> 3, 3, 4, 1, 3, 2
#> $ number_subjects <int> 3, 3, 4, 1, 3, 2
#> $ reason_id <int> 1, 2, 1, 2, 1, 2
#> $ reason <chr> "Initial qualifying events", "require prior obser…
#> $ excluded_records <int> 0, 0, 0, 3, 0, 1
#> $ excluded_subjects <int> 0, 0, 0, 3, 0, 1
# }