R6 class for composite condition code specifications
Source:R/CompositeCodeSpec.R
CompositeCodeSpec.RdA CompositeCodeSpec is a composition of all versioned condition components
that collectively define a composite endpoint (e.g., ASCVD). Unlike
CodeSpec, it does not store codes directly — instead it holds references
to specific versioned CodeSpec leaf objects, accessible by name via the
component argument.
The components list is a flat named list mapping "name_vX" keys to
CodeSpec objects, e.g.:
components = list(
chd_v1 = spec_chd_v1,
stroke_v1 = spec_stroke_v1,
cerebrovasc_disease_v1 = spec_cerebrovasc_disease_v1
)The component argument is optional when calling get_codes() or
get_defs(); omitting it (or passing "all") returns every component.
The variable_type argument is forwarded to the component spec, so both
condition and outcome codes are accessible.
Active bindings
conditionShort condition identifier (read-only).
versionVersion label (read-only;
NULLfor composites).labelHuman-readable label (read-only).
Methods
CompositeCodeSpec$new()
Create a new CompositeCodeSpec.
Usage
CompositeCodeSpec$new(
condition,
label,
defs = NULL,
components = list(),
version = NULL,
components_by_variable_type = NULL
)Arguments
conditionShort identifier string, e.g.
"ascvd".labelHuman-readable label.
defsCharacter string describing the composite definition.
componentsNamed list of CodeSpec objects, keyed by
"name_vX"strings.versionOptional version label (typically
NULLfor composites).components_by_variable_typeOptional named list with elements
conditionand/oroutcome, each a character vector of component names (keys ofcomponents) to use as the default set whencomponentis omitted (or"all") for thatvariable_type. Lets a composite's default component set differ between the condition and outcome definitions (e.g. ASCVD's condition definition uses cerebrovascular disease while its outcome definition uses stroke instead). Explicitly namingcomponentalways bypasses this filter.NULL(default) means every component is used regardless ofvariable_type.
CompositeCodeSpec$components()
Return the flat named component list.
Returns
Named list of CodeSpec objects.
CompositeCodeSpec$get_codes()
Retrieve codes from one or more components as a tidy data frame.
Usage
CompositeCodeSpec$get_codes(
component = NULL,
code_type = NULL,
variable_type = c("condition", "outcome"),
periods = FALSE,
priority = 1L
)Arguments
componentOptional component name(s), e.g.
"chd_v1".NULL(default) or"all"returns every component that applies tovariable_type(seecomponents_by_variable_typein$new()), with aclasscolumn distinguishing them.code_typeOptional character vector of code types to filter.
variable_type"condition"(default) or"outcome".periodsLogical.
FALSE(default) = short format.priorityInteger vector subsetting confidence tiers to include. Default
1.
CompositeCodeSpec$get_defs()
Retrieve the narrative algorithm description from one or more components.
Usage
CompositeCodeSpec$get_defs(
component = NULL,
variable_type = c("condition", "outcome")
)