Skip to contents

Stores the code sets and narrative algorithm description for a single version of a medical condition definition. Each version is a distinct object (e.g., spec_acei_v1, spec_acei_v2).

The spec stores:

  • defs: named list with elements condition and outcome, each holding a narrative algorithm description string (or NULL if not defined).

  • codes: named list of key-level lists keyed by {code_type}_{encounter} (e.g., dx_icd9). Each key-level list has:

    • codes: character vector of exact short-format codes (no periods).

    • condition: logical vector parallel to codes; TRUE if the code belongs to the condition/history definition.

    • outcome: logical vector parallel to codes; TRUE if the code belongs to the outcome definition.

    • definitions: optional character vector of code definitions, parallel to codes.

    • exclusions: optional character string describing codes to exclude.

Active bindings

condition

Short condition identifier (read-only).

version

Version label, e.g. "v1" (read-only).

label

Human-readable condition label (read-only).

Methods


CodeSpec$new()

Create a new CodeSpec.

Usage

CodeSpec$new(
  condition,
  label,
  defs = NULL,
  codes = NULL,
  version = NULL,
  versions = NULL
)

Arguments

condition

Short identifier string, e.g. "htn".

label

Human-readable label, e.g. "Hypertension".

defs

Named list with elements condition and outcome (character strings or NULL).

codes

Named list of key-level lists. See class description.

version

Optional version label string, e.g. "v1".

versions

Deprecated. Use defs/codes/version directly.


CodeSpec$print()

Print a summary of the spec.

Usage

CodeSpec$print(...)


CodeSpec$keys()

Return code-set keys.

Usage

CodeSpec$keys()

Returns

Character vector of keys like "dx_icd9".


CodeSpec$get_codes()

Retrieve codes from the spec as a tidy data frame.

Usage

CodeSpec$get_codes(
  code_type = NULL,
  variable_type = c("condition", "outcome"),
  periods = FALSE,
  priority = 1L
)

Arguments

code_type

Optional character vector of code types to return. Valid values: "dx_icd9", "dx_icd10", "proc_icd9", "proc_icd10", "hcpcs", "cpt", "rev". NULL returns all.

variable_type

"condition" (default) or "outcome". If the spec has no codes flagged for "outcome", falls back to "condition".

periods

Logical. If TRUE, return codes with decimal periods (e.g., "401.0"). Default FALSE returns short format ("4010").

priority

Integer vector subsetting confidence tiers to include (1 = core, 2 = probable, 3 = cautious). Default 1.

Returns

A tibble with columns type, code, priority, version, and definition.


CodeSpec$get_defs()

Retrieve the narrative algorithm description.

Usage

CodeSpec$get_defs(variable_type = c("condition", "outcome"))

Arguments

variable_type

"condition" (default) or "outcome".

Returns

Character string, or NULL if no definition exists for that variable type.


CodeSpec$clone()

The objects of this class are cloneable with this method.

Usage

CodeSpec$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.