Creates boolean skeleton columns from filter expressions evaluated against
quality registry data (e.g., Riksstroke, NKBC). Unlike add_diagnoses()
which matches ICD code prefixes, this function evaluates arbitrary R
expressions against the dataset columns.
Usage
add_quality_registry(skeleton, dataset, id_name, date_col, codes = list())Arguments
- skeleton
A data.table containing the main skeleton structure created by
create_skeleton.- dataset
A data.table containing quality registry data with person ID and a date column.
- id_name
Character string specifying the name of the ID variable in the dataset.
- date_col
Character string specifying the name of the date column in the dataset (must be Date or IDate class).
- codes
Named list of filter definitions. Names become variable names in skeleton. Values are either
TRUE(event flag) orquote()expressions evaluated against dataset columns. Example:list("stroke_event" = TRUE, "stroke_tia" = quote(tia == 1))
Value
The skeleton data.table is modified by reference with boolean variables added. New columns are FALSE on non-event weeks, and FALSE when filter expressions evaluate to NA (missing data).
The function also returns the skeleton, invisibly. The return is the object the caller passed, while that object has a free column slot for every new column. Past that point data.table cannot grow the column list in place, so the new columns land on the returned table alone. A caller that passes an expression rather than a variable MUST use the return value.
Any other name that pointed at the same table before the call is stale afterwards. R cannot grow a list in place. A growth therefore leaves the caller's binding on a NEW object, and every other name on the old one. Take an alias after the call, never before it.
Details
Each entry in codes produces one boolean column on the skeleton:
TRUE: event indicator, TRUE on any week with a registry eventquote(expr): filter expression evaluated against dataset columns. TRUE when the expression evaluates to TRUE, FALSE otherwise (including NA).
Multiple events in the same person-week are aggregated with any().
See also
add_diagnoses for ICD code matching,
add_rx for prescription data
Other data_integration:
add_annual(),
add_cancer_without_morphology(),
add_cods(),
add_diagnoses(),
add_onetime(),
add_operations(),
add_rx()
Examples
# Create fake data
data("fake_person_ids", package = "swereg")
skeleton <- create_skeleton(fake_person_ids[1:5], 2020, "2020-53")
fake_registry <- data.table::data.table(
lopnr = c(fake_person_ids[1], fake_person_ids[2]),
event_date = as.Date(c("2020-03-15", "2020-06-20")),
severity = c(5, 18),
treated = c(1, 2)
)
add_quality_registry(skeleton, fake_registry, "lopnr",
date_col = "event_date",
codes = list(
"reg_event" = TRUE,
"reg_severe" = quote(severity >= 15),
"reg_treated" = quote(treated == 1)
)
)
