SDTM mapper guide¶
The sdtm-mapper skill and the pharmaskills sdtm commands turn raw EDC exports into a
reviewable SDTM package. The model proposes a mapping specification (never data). The
deterministic engine executes it, so the same inputs always give byte-identical files. Failures
are repaired by changing the spec, never by editing data.
Everything is a draft for qualified human review. See Guardrails.
Scope (v1)¶
Domains DM (with SUPPDM), AE (with SUPPAE), CM, VS, LB, EX and TS, written as XPT v5 and Dataset-JSON v1.1, plus Define-XML 2.1, a cSDRG draft, a traceability matrix and a run manifest. ADaM beyond ADSL and ADAE and further SDTM domains are on the roadmap.
Study folder¶
<study>/study.yaml <study>/raw/*.csv <study>/dictionaries/*.csv <study>/protocol.docx
study.yaml holds STUDYID, arms, epochs, visits and the trial summary. Optional inputs:
protocol DOCX (needed for TS and the visit schedule), eCRF annotations, licensed MedDRA or
WHODrug files (path in pharmaskills.toml), and a CDISC CT package (pharmaskills ct sync).
Pipeline¶
| Step | Command | Who does it |
|---|---|---|
| 1. Draft study metadata | pharmaskills sdtm init <study> --protocol protocol.docx |
tool, you confirm |
| 2. Profile raw files | pharmaskills sdtm profile <study> |
tool |
| 3. Propose the spec | pharmaskills sdtm propose <study> --no-model then the agent completes it |
tool and model |
| 4. Validate the spec | pharmaskills sdtm validate-spec <study> --spec spec.yaml |
tool |
| 5. Review gate | pharmaskills sdtm review <study> --spec spec.yaml |
you |
| 6. Build | pharmaskills sdtm build <study> --spec spec.yaml |
tool |
| 7. Validate datasets | pharmaskills sdtm validate <study> |
tool |
| 8. Repair loop (max 5) | pharmaskills sdtm repair <study> --max-iter 5 |
tool and model |
| 9. Document | pharmaskills sdtm document <study> |
tool |
| All of it | pharmaskills sdtm run <study> |
tool |
pharmaskills sdtm explain shows the SDTMIG definition, core status and codelist of a variable.
Mapping DSL reference¶
The mapping specification is YAML. The engine supports only these operations; each is unit tested. A spec never contains code.
| Operation | Purpose | Key parameters |
|---|---|---|
direct |
copy a source column | src |
constant |
fixed value | value |
concat |
join with a separator, null if any part is null | src (list), sep |
ct_map |
map raw values to CT submission values; unmapped values are errors | src, values, codelist, ci, passthrough |
iso8601 |
dates and times to ISO 8601, partial dates stay partial | src (date or [date, time]), formats |
study_day |
study day from a --DTC and RFSTDTC, no day 0 | dtc |
seq |
sequence per subject, sorted | by, sort |
epoch |
EPOCH from the epoch ranges in study.yaml | dtc |
lookup |
value from another file or dictionary | from, on, agg, formats, ci |
unit_convert |
standard result and unit from the bundled table | test, src, unit, output |
baseline_flag |
last non-missing record on or before first dose (--LOBXFL) | dtc, result, by |
expr |
restricted expression (no imports, no I/O) | value |
supp |
non-standard variable to SUPP-- | qnam, qlabel, src, qorig |
transpose |
domain level, wide to long | id, columns |
Domain level keys: source, joins, transpose, row_filter, distinct, omit.
Reference rules¶
file.COLUMNalways means the raw column.@NAME(andv_NAMEinexpr) always means the derived variable.- A plain name used as a data source means the raw column when one exists, otherwise the derived
variable. A plain name in
dtc,by,sort,test,unit,resultmeans the derived variable when one exists. Variable order in the spec does not matter. - Variables whose names start with
_are helpers and are not written to the dataset.
expr functions¶
floor, ceil, round, abs, min, max, upper, lower, trim, len, substr, concat, coalesce, isnull,
num, str, fmt, years_between, days_between, study_day; operators + - * / // % **, comparisons,
and, or, not, and a if cond else b. Null propagates.
Example¶
domains:
AE:
source: ae
distinct: [SITE, SUBJ, AE_ID] # exact duplicate entries
variables:
STUDYID: {op: constant, value: PSK-001}
DOMAIN: {op: constant, value: AE}
USUBJID: {op: concat, src: [STUDYID, SITE, SUBJ], sep: "-"}
AETERM: {op: direct, src: AE_VERBATIM}
AESEV:
op: ct_map
src: SEV
codelist: C66769
values: {Mild: MILD, Mod: MODERATE, Severe: SEVERE}
confidence: 0.95
rationale: values resolved against CT
AESTDTC: {op: iso8601, src: [START_DATE], formats: ["%d-%b-%Y", "%Y-%m-%d"]}
AESEQ: {op: seq, by: [USUBJID], sort: [AESTDTC, AETERM]}
AESTDY: {op: study_day, dtc: AESTDTC}
supp:
- {op: supp, qnam: AEOTHSP, qlabel: Other Specify, src: OTHER_SPEC}
One row per target variable carries confidence (0 to 1) and rationale. Required variables
must be covered; Expected variables are covered or justified under omit.
Review workflow¶
Every spec row has confidence, rationale and status (proposed, approved,
auto_approved, rejected).
- A row enters
review_queue.xlsxwhen confidence is below the threshold (default 0.8) or when a Required SDTMIG variable is mapped by a derivation (expr, lookup, study_day, epoch, seq, baseline_flag, unit_convert). - The reviewer fills the
decisioncolumn withapprovedorrejected; apply withpharmaskills sdtm review <study> --apply review_queue.xlsx. - Batch mode:
--auto-approve-above 0.8approves rows at or above the threshold. Rows that stayproposedare listed in the cSDRG section "Mapping review status". - Rejected rows must be replaced before a build is trusted.
- Record the rationale of every change; previous specs are archived in
.history/.
Reading the validation report¶
validation_report.json names the engine.
cdisc-coremeans a CDISC CORE executable ran (configurePHARMASKILLS_CORE_PATH).pharmaskills-nativemeans the built-in structural and terminology checks ran. They are not CDISC CORE rules and must never be described as CORE results.
CDISC CORE could not be exercised in the build environment of this release, so every published result in these docs comes from the native engine. Run CORE yourself for submission-grade validation.
Native rule groups: PSK-0001 to PSK-0004 variable presence and non-standard variables; PSK-0005 and PSK-0021 controlled terminology; PSK-0006 to PSK-0008 keys and sequence numbers; PSK-0009, PSK-0011, PSK-0012 dates and study days; PSK-0010, PSK-0014, PSK-0019 XPT limits; PSK-0015 supplemental qualifiers; PSK-0013, PSK-0016 to PSK-0018, PSK-0020 consistency.
Build issues (B-codes): B001 value without a mapping, B003 date left blank, B007 unit conversion failed, B012 study day without RFSTDTC. Fix the spec, not the data.
Output contract¶
Under <study>/out/:
| File | Content |
|---|---|
sdtm/xpt/*.xpt, sdtm/json/*.json |
Datasets |
../spec.yaml and review_queue.xlsx |
Mapping specification and the review queue |
define/define.xml, define/define.html |
Define-XML 2.1 and its rendering |
csdrg.md, csdrg.docx |
Clinical study data reviewer's guide draft |
traceability.csv |
Raw file and row for every SDTM record |
validation_report.json |
Engine, version, errors, warnings, notes |
run_manifest.json |
Versions, input and output hashes, verification results |
Terminology and dictionaries¶
Controlled terminology comes from a CDISC CT package (pharmaskills ct sync, or --ct-file).
MedDRA and WHODrug are licensed and not included: supply your licensed files by path. Without
them, coded variables are left uncoded and listed, never guessed.
See also the skill page, the CLI reference and the benchmarks.