Skip to contents

A helper function primarily used by table_one() to calculate the span in years between the first and last (clinical) documents per person. It does not take into account gaps in the the patient record; for something like that, one should explore the get_observation_periods() function.

Note that the function will use the clinical_document table if it is present in the dataset, and the document table otherwise.

Usage

get_person_clinical_document_span(ds, return_dates = FALSE)

Arguments

ds

A PicnicHealth data set list object.

return_dates

A boolean which defaults to FALSE. If set to TRUE, return start and end dates of clinical document span.

Value

A data frame, one row per person, with a column for person_id and clinical_document_span, i.e. the years between the first and last clinical document for a person and, if specified, the start and end dates of the span, i.e. span_start_date and span_end_date.

Details

Beyond its use in table_one(), this function may be useful to add an additional column to an existing analytic data.frame that already contains person_id using dplyr::left_join() to include clinical_document_span and optionally, span_start_date and span_end_date. See examples.

Examples

if (FALSE) { # \dontrun{
# Add `clinical_document_span` and optionally `span_start_date` and `span_end_date` to an analytic data set that contains `person_id`:
analytic_dataset %>%
  left_join(get_person_clinical_document_span(ds))
} # }