Skip to contents

`r lifecycle::badge("experimental")` Same as `addPriorObservation()`, except query is not computed to a table.

Usage

addPriorObservationQuery(
  x,
  indexDate = "cohort_start_date",
  priorObservationName = "prior_observation",
  priorObservationType = "days"
)

Arguments

x

Table with individuals in the cdm.

indexDate

Variable in x that contains the date to compute the prior observation.

priorObservationName

name of the new column to be added.

priorObservationType

Whether to return a "date" or the number of "days".

Value

cohort table with added column containing prior observation of the individuals.

Examples

# \donttest{
cdm <- mockPatientProfiles()

cdm$cohort1 |>
  addPriorObservationQuery()
#> # Source:   SQL [?? x 5]
#> # Database: DuckDB v1.2.2 [unknown@Linux 6.11.0-1015-azure:R 4.5.0/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    3          1 1989-06-26        1990-06-02     
#>  2                    3          2 1975-11-15        1976-01-16     
#>  3                    3          3 1944-06-21        1952-04-10     
#>  4                    2          4 1924-11-01        1933-10-20     
#>  5                    3          5 1926-01-11        1927-10-07     
#>  6                    3          6 1943-11-01        1944-02-01     
#>  7                    3          7 1928-11-03        1958-07-19     
#>  8                    3          8 1962-09-04        1966-04-25     
#>  9                    3          9 1960-02-21        1965-03-05     
#> 10                    3         10 1970-11-08        1975-02-12     
#> # ℹ 1 more variable: prior_observation <int>

mockDisconnect(cdm = cdm)
# }