Skip to contents

Add the maximum number of ingredients to which an individual is simultaneously exposed within a specified window

Usage

addPolypharmacy(
  x,
  indexDate = "cohort_start_date",
  window = c(0, 0),
  overlap = TRUE,
  group = "ingredient drug_era",
  categories = NULL,
  nameStyle = "polypharmacy",
  name = tableName(x)
)

Arguments

x

A cdm_table containing a person identifier column named person_id or subject_id.

indexDate

A character string naming the Date column in x that defines the index date.

window

A numeric vector of length two, c(min, max), defining the window for polypharmacy in days relative to indexDate. Use -Inf or Inf for an unbounded lower or upper limit.

overlap

Logical; if TRUE, count drug records that overlap in time. If FALSE, count drug records that occur within the window without requiring them to overlap one another.

group

Group at which drug records will be considered, it must be a choice between:

  • "concept_id" Records are not grouped, each drug_concept_id counts as 1.

  • "ingredient drug_era" Records are grouped using the drug_era table.

  • "ingredient drug_exposure" Records are grouped at ingredient level using the drug_exposure table.

  • "ATC 1st", "ATC 2nd", "ATC 3rd", "ATC 4th", "ATC 5th" Records are grouped using different ATC groups levels. ATC codelists are retrieved using CodelistGenerator::getATCCodes().

  • Custom conceptSet a custom codelist, codelist_with_details or concept_set_expression concept set definition, drug_concept_ids not included in the conceptSet will be omitted.

categories

A named list of numeric vectors, each containing the lower and upper bounds of a score interval. An additional column with the suffix _categories is added. Intervals are evaluated in the order supplied, and missing scores are labelled missing.

nameStyle

A character string specifying the name of the new column.

name

A character string specifying the name of the output table. If NULL, a temporary table is created.

Value

The table x with a new column containing the maximum number of simultaneous ingredients in the window of interest.

Examples

# \donttest{
library(omock)
library(duckdb)
library(OmopIndices)
library(dplyr)
library(CohortConstructor)

cdm <- mockCdmFromDataset(datasetName = "GiBleed", source = "duckdb")
#> ℹ Loading bundled GiBleed tables from package data.
#> ℹ Adding drug_strength table.
#> ℹ Creating local <cdm_reference> object.
#> ℹ Inserting <cdm_reference> into duckdb.
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/RtmptcUckz/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
cdm$cohort <- conceptCohort(
  cdm = cdm,
  conceptSet = list(sinusitis = c(257012L, 4283893L, 4294548L, 40481087L)),
  name = "cohort"
)
#> ℹ Subsetting table condition_occurrence using 4 concepts with domain:
#>   condition.
#> ℹ Combining tables.
#> ℹ Creating cohort attributes.
#> ℹ Applying cohort requirements.
#> ℹ Merging overlapping records.
#> ✔ Cohort cohort created.

cdm$cohort |>
  addPolypharmacy(window = c(-30, 0)) |>
  select(subject_id, cohort_start_date, polypharmacy) |>
  glimpse()
#> Rows: ??
#> Columns: 3
#> $ subject_id        <int> 123, 245, 245, 331, 331, 404, 411, 449, 863, 890, 89…
#> $ cohort_start_date <date> 1957-07-09, 1960-11-15, 1972-10-24, 1944-08-19, 195…
#> $ polypharmacy      <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0…
# }