Skip to contents

Filter the cohort table keeping only the cohort records for which the required amount of time has passed since the last cohort entry ended for that individual.

Usage

requirePriorDrugWashout(
  cohort,
  days,
  cohortId = NULL,
  name = omopgenerics::tableName(cohort)
)

Arguments

cohort

A cohort table in a cdm reference.

days

The number of days required to have passed since the last cohort record finished. Any records with fewer days than this will be dropped. Note that setting days to Inf will lead to the same result as that from using the requireIsFirstDrugEntry function (with only an individual´s first cohort record kept).

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.

Value

The cohort table having applied the washout requirement.

Examples

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

cdm <- mockDrugUtilisation()
#> Warning: ! 6 column in person do not match expected column type:
#>  `gender_concept_id` is numeric but expected integer
#>  `race_concept_id` is numeric but expected integer
#>  `ethnicity_concept_id` is numeric but expected integer
#>  `location_id` is numeric but expected integer
#>  `provider_id` is numeric but expected integer
#>  `care_site_id` is numeric but expected integer
#> Warning: ! 1 column in observation_period do not match expected column type:
#>  `period_type_concept_id` is numeric but expected integer
#> Warning: ! 2 column in visit_occurrence do not match expected column type:
#>  `visit_concept_id` is numeric but expected integer
#>  `visit_type_concept_id` is numeric but expected integer
#> Warning: ! 10 column in condition_occurrence do not match expected column type:
#>  `condition_concept_id` is numeric but expected integer
#>  `condition_type_concept_id` is numeric but expected integer
#>  `condition_status_concept_id` is numeric but expected integer
#>  `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: ! 2 column in drug_exposure do not match expected column type:
#>  `drug_concept_id` is numeric but expected integer
#>  `drug_type_concept_id` is numeric but expected integer
#> Warning: ! 2 column in observation do not match expected column type:
#>  `observation_concept_id` is numeric but expected integer
#>  `observation_type_concept_id` is numeric but expected integer
#> Warning: ! 4 column in concept do not match expected column type:
#>  `concept_id` is numeric 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
#> Warning: ! 2 column in concept_relationship do not match expected column type:
#>  `concept_id_1` is numeric but expected integer
#>  `concept_id_2` is numeric but expected integer
#> Warning: ! 4 column in concept_ancestor do not match expected column type:
#>  `ancestor_concept_id` is numeric but expected integer
#>  `descendant_concept_id` is numeric but expected integer
#>  `min_levels_of_separation` is numeric but expected integer
#>  `max_levels_of_separation` is numeric but expected integer
#> Warning: ! 9 column in drug_strength do not match expected column type:
#>  `drug_concept_id` is numeric but expected integer
#>  `ingredient_concept_id` is numeric but expected integer
#>  `amount_unit_concept_id` is numeric but expected integer
#>  `numerator_unit_concept_id` is numeric but expected integer
#>  `denominator_unit_concept_id` is numeric but expected integer
#>  `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
#> Warning: ! 6 column in person do not match expected column type:
#>  `gender_concept_id` is numeric but expected integer
#>  `race_concept_id` is numeric but expected integer
#>  `ethnicity_concept_id` is numeric but expected integer
#>  `location_id` is numeric but expected integer
#>  `provider_id` is numeric but expected integer
#>  `care_site_id` is numeric but expected integer
#> Warning: ! 1 column in observation_period do not match expected column type:
#>  `period_type_concept_id` is numeric but expected integer

cdm$cohort1 <- cdm$cohort1 |>
  requirePriorDrugWashout(days = 90)

attrition(cdm$cohort1) |> glimpse()
#> Rows: 6
#> Columns: 7
#> $ cohort_definition_id <int> 1, 1, 2, 2, 3, 3
#> $ number_records       <int> 5, 5, 2, 2, 3, 3
#> $ number_subjects      <int> 5, 5, 2, 2, 3, 3
#> $ reason_id            <int> 1, 2, 1, 2, 1, 2
#> $ reason               <chr> "Initial qualifying events", "require prior use d…
#> $ excluded_records     <int> 0, 0, 0, 0, 0, 0
#> $ excluded_subjects    <int> 0, 0, 0, 0, 0, 0
# }