跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
搜索与研究

admiral-bds

Derives ADaM Basic Data Structure (BDS) datasets using the {admiral} R package. Initial scope covers ADVS (vital signs) and ADLB (laboratory values). Use when a user needs to create a BDS findings dataset from SDTM domains, derive parameter assignments, baseline values, change from baseline, visit windowing, or analysis flags, following CDISC ADaM conventions. Requires SDTM input data, an ADaM BDS specification, and a completed ADSL.

RConsortium · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add RConsortium/pharma-skills --skill admiral-bds

技能说明


name: admiral-bds description: > Derives ADaM Basic Data Structure (BDS) datasets using the {admiral} R package. Initial scope covers ADVS (vital signs) and ADLB (laboratory values). Use when a user needs to create a BDS findings dataset from SDTM domains, derive parameter assignments, baseline values, change from baseline, visit windowing, or analysis flags, following CDISC ADaM conventions. Requires SDTM input data, an ADaM BDS specification, and a completed ADSL. license: MIT metadata: author: Navitas Data Sciences version: "0.1" pharmaverse: "true" parent: admiral compatibility: > Requires R with admiral, dplyr, lubridate, and pharmaversesdtm installed. Requires a completed ADSL dataset. Designed for use in a GxP-compliant environment with access to SDTM datasets and an ADaM BDS specification.

admiral-bds

Shared conventions (library setup, pipe style, date rules, flag convention, # REVIEW: annotations, stopifnot() patterns) are defined in the parent ../SKILL.md. The workflow below is BDS-specific.

Derives CDISC-conformant BDS findings datasets using {admiral}. Outputs executable, QC-ready R code for ADVS and ADLB with full derivation traceability.

See bds-conventions reference for BDS variable conventions and record structure. See ../admiral-adsl/references/admiral-functions.md for function selection guidance shared across the admiral family.


Inputs

Before generating code, confirm the following are available or explicitly noted as absent:

InputRequiredNotes
VS or LBYesSource SDTM domain for ADVS or ADLB respectively
ADSLYesProvides TRTSDT, TRTEDT, treatment variables, and population flags
ADaM BDS specYesParameter list, derivation rules, visit windows, baseline definition
Study contextYesBaseline window, analysis flag definitions, visit map

If ADSL is absent, stop and request it. ADSL variables are required before baseline flagging and analysis flags can be derived.


Workflow

Follow these steps in order. Generate code section by section, not as a single block.

Step 1 — Setup and domain loading

library(admiral)
library(dplyr)
library(lubridate)
library(pharmaversesdtm)

# Load source domain — replace with vs/lb per dataset being derived
vs  <- pharmaversesdtm::vs
adsl <- <loaded ADSL dataset>

# Remove DOMAIN to avoid conflicts in derive_vars_merged() calls
vs <- select(vs, -DOMAIN)

Step 2 — Merge ADSL backbone variables

Bring required ADSL variables into the source dataset before any derivations. At minimum: TRTSDT, TRTEDT, population flags used as analysis set criteria.

# REVIEW: Confirm which population flags and ADSL variables are required by
#   the ADaM spec for this dataset. Add or remove from new_vars accordingly.
advs <- vs |>
  derive_vars_merged(
    dataset_add = adsl,
    by_vars     = exprs(STUDYID, USUBJID),
    new_vars    = exprs(TRTSDT, TRTEDT, TRT01P, TRT01PN, TRT01A, TRT01AN,
                        SAFFL, ITTFL)
  )

Step 3 — Parameter assignment

Map SDTM test codes to ADaM parameters. Use derive_vars_merged_lookup() with a lookup table driven by the ADaM spec. Do not use derive_vars_merged() here — it is not a lookup function and will not correctly handle unmatched records. Do not use case_when() or hardcoded if_else() chains.

# REVIEW: PARAMCD mapping must match the ADaM spec parameter list exactly.
#   Confirm VSTESTCD values in VS and align with ADaM PARAMCD conventions.
#   Remove parameters not in scope for this study.
param_lookup <- tibble::tribble(
  ~VSTESTCD, ~PARAMCD, ~PARAM,                    ~PARAMN,
  "SYSBP",   "SYSBP",  "Systolic Blood Pressure",  1L,
  "DIABP",   "DIABP",  "Diastolic Blood Pressure",  2L,
  "PULSE",   "PULSE",  "Pulse Rate",                3L,
  "WEIGHT",  "WEIGHT", "Weight",                    4L,
  "HEIGHT",  "HEIGHT", "Height",                    5L,
  "TEMP",    "TEMP",   "Temperature",               6L
)

advs <- advs |>
  derive_vars_merged_lookup(
    dataset_add = param_lookup,
    by_vars     = exprs(VSTESTCD),
    new_vars    = exprs(PARAMCD, PARAM, PARAMN)
  ) |>
  filter(!is.na(PARAMCD))   # drop records for out-of-scope tests

For ADLB, map from LBTESTCD. Include units in PARAM text per ADaM spec.

Step 4 — Analysis value (AVAL, AVALC)

AVAL is the numeric analysis value. AVALC is the character analysis value. Derive from the SDTM result variables, applying unit conversions if required.

advs <- advs |>
  mutate(
    AVAL  = VSSTRESN,    # numeric result in standard units
    AVALC = VSSTRESC,    # character result (for non-numeric or verbatim)
    AVALU = VSSTRESU     # analysis value units
  )

For ADLB, use LBSTRESN and LBSTRESC. If unit standardisation is required (e.g. converting mg/dL to mmol/L), apply before AVAL assignment and add a # REVIEW: comment referencing the protocol-specified units.

Step 5 — Date derivation (ADT, ADTF, ADY)

advs <- advs |>
  # ADT: analysis date from VSDTC
  derive_vars_dt(
    dtc             = VSDTC,
    new_vars_prefix = "A",
    date_imputation = "first",
    flag_imputation = "auto"
  ) |>
  # ADY: study day relative to TRTSDT
  derive_vars_dy(
    reference_date = TRTSDT,
    source_vars    = exprs(ADT)
  )

For ADLB, replace VSDTC with LBDTC.

Step 6 — Visit assignment (AVISIT, AVISITN)

Map SDTM VISIT/VISITNUM to ADaM AVISIT/AVISITN. Use the visit map from the ADaM spec — do not pass VISIT through directly to AVISIT.

# REVIEW: Visit map must come from the ADaM spec. The example below is
#   illustrative. Confirm VISIT names and AVISITN codes against the study CRF
#   and ADaM spec before use.
visit_map <- tibble::tribble(
  ~VISIT,        ~AVISIT,       ~AVISITN,
  "SCREENING 1", "Screening",   -1L,
  "BASELINE",    "Baseline",     0L,
  "WE
阅读完整来源 ↗