Trial Design Domains API¶
fleet.sdtm.design
¶
Study design aggregate — define the trial design once, derive every domain.
StudyDesign is the single typed source of truth for a study's structure:
elements, arms (as ordered element paths), visits, criteria, and summary
parameters. Every Trial Design domain (TE, TA, TV, TS, TI, TD, TM) is
derived from it, so TAETORD ordering, element/epoch duplication across
arms, and cross-domain FK consistency fall out mechanically instead of being
hand-maintained per row.
Usage::
import fleet
design = fleet.StudyDesign(
study_id="CDISCPILOT01",
elements=[
{"etcd": "SCRN", "element": "Screening", "tedur": "P14D",
"epoch": "SCREENING"},
{"etcd": "TRT", "element": "Treatment", "tedur": "P84D",
"epoch": "TREATMENT"},
{"etcd": "FU", "element": "Follow-up", "tedur": "P28D",
"epoch": "FOLLOW-UP"},
],
arms={"PBO": ["SCRN", "TRT", "FU"], "XAN_LO": ["SCRN", "TRT", "FU"]},
arm_names={"PBO": "Placebo", "XAN_LO": "Xanomeline Low Dose"},
)
ta = design.to_ta()
frames = design.domains() # {"TE": df, "TA": df, ...}
findings = design.audit() # P21-style conformance pre-check
ArmStep
¶
Bases: BaseModel
One position of an arm path, with the TA values of that position.
A plain ETCD string in a path is the short form of a step with no
override. epoch replaces the element's epoch at this position (a
crossover, an element that repeats). tabranch replaces the default
Randomized to <arm> text, and tatrans gives the TATRANS rule.
Source code in src/fleet/sdtm/design.py
StudyDesign
¶
Bases: BaseModel
Typed aggregate of a study's trial design.
arms maps each ARMCD to its ordered path of element codes — the
per-arm element name/epoch/TAETORD repetition of raw TA rows is derived,
never written by hand. A path entry is an ETCD string or an
:class:ArmStep ({"etcd": ..., "epoch": ..., "tabranch": ...,
"tatrans": ...}) for the TA values of one position. All fields accept
plain dicts (Pydantic coerces), so a trial_design.yaml deserialises
directly via :meth:from_yaml. An unknown key raises.
TABRANCH defaults to Randomized to <arm> on the last element that
every arm shares, or on the randomized_at element when it is given.
A step's tabranch replaces that text: state the real rule when the
branch is not a randomization.
Source code in src/fleet/sdtm/design.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
arm_collection
¶
Derive the validated TrialArms collection from the arm paths.
Returns:
| Name | Type | Description |
|---|---|---|
TrialArms |
TrialArms
|
One row per arm/element with TAETORD, ELEMENT, EPOCH looked up from the element definitions (or the step's epoch) and TABRANCH rendered at the branch point (or the step's tabranch). |
References
SDTMIG 3.4 TA: EPOCH is the epoch of this element of the arm,
TABRANCH the condition met at the end of the element; see
docs/adr/0036-an-arm-path-entry-is-an-element-or-a-step.md.
Examples:
Derive TA rows from a design::
design = fleet.StudyDesign(study_id="S1", elements=[...],
arms={"PBO": ["SCRN", "TRT"]})
ta_rows = design.arm_collection()
Source code in src/fleet/sdtm/design.py
to_te
¶
Derive the TE (Trial Elements) domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TE with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TE from a design::
te = design.to_te()
Source code in src/fleet/sdtm/design.py
to_ta
¶
Derive the TA (Trial Arms) domain from the arm paths.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TA with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TA from a design::
ta = design.to_ta()
Source code in src/fleet/sdtm/design.py
to_tv
¶
Derive the TV (Trial Visits) domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TV with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TV from a design::
tv = design.to_tv()
Source code in src/fleet/sdtm/design.py
to_ts
¶
Derive the TS (Trial Summary) domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TS with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TS from a design::
ts = design.to_ts()
Source code in src/fleet/sdtm/design.py
to_ti
¶
Derive the TI (Trial Inclusion/Exclusion) domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TI with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TI from a design::
ti = design.to_ti()
Source code in src/fleet/sdtm/design.py
to_td
¶
Derive the TD (Trial Disease Assessments) domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TD with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TD from a design::
td = design.to_td()
Source code in src/fleet/sdtm/design.py
to_tm
¶
Derive the TM (Trial Disease Milestones) domain.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: TM with STUDYID/DOMAIN and SDTM column names. |
Examples:
Derive TM from a design::
tm = design.to_tm()
Source code in src/fleet/sdtm/design.py
domains
¶
Derive every populated Trial Design domain.
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
dict[str, pl.DataFrame]: Domain code → DataFrame, skipping domains whose design section is empty. |
Examples:
Build all domains and write them out::
for domain, df in design.domains().items():
df.write_parquet(f"data/sdtm/{domain.lower()}.parquet")
Source code in src/fleet/sdtm/design.py
audit
¶
Run the P21-style conformance pre-check over the derived domains.
Two design checks come first: arms with the same path
(FLEETTD04), and an element that repeats in one arm with no
per-position epoch (FLEETTD05).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm
|
DataFrame | None
|
Optional DM domain for cross-checking ARMCD assignments. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: One row per finding ( |
Examples:
Audit a design before export::
findings = design.audit()
errors = findings.filter(pl.col("severity") == "error")
Source code in src/fleet/sdtm/design.py
from_yaml
classmethod
¶
Load a design from a trial_design.yaml spec.
The YAML mirrors the model schema; a top-level trial_design:
wrapper key is accepted so the section can live inside a larger
study file. A repeated key or a key the model does not read
raises, so a typo cannot drop a rule, a visit or an arm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the YAML file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StudyDesign |
StudyDesign
|
The validated design. |
Raises:
| Type | Description |
|---|---|
ConstructorError
|
When a mapping repeats a key. |
ValidationError
|
When a key is unknown or a value is not valid. |
Examples:
Load and build every domain::
design = fleet.StudyDesign.from_yaml("metadata/trial_design.yaml")
frames = design.domains()
Source code in src/fleet/sdtm/design.py
to_yaml
¶
Serialise the design to YAML (the from_yaml round-trip).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | None
|
Optional file path to write to. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The YAML document. |
Examples:
Persist a design next to the study metadata::
design.to_yaml("metadata/trial_design.yaml")
Source code in src/fleet/sdtm/design.py
from_mermaid
classmethod
¶
Build a design from a Mermaid flowchart.
The diagram gives the elements and the arm paths. ARM comes from arm_names when given, else from the ARMCD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mermaid_text
|
str
|
A Mermaid |
required |
study_id
|
str
|
The study identifier. |
required |
**sections
|
Any
|
Extra design sections ( |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
StudyDesign |
StudyDesign
|
Design with elements and arm paths from the diagram. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the diagram cannot give a design (see
:func: |
Examples:
Diagram in, datasets out::
design = fleet.StudyDesign.from_mermaid(diagram_text,
study_id="CDISCPILOT01")
ta = design.to_ta()
Source code in src/fleet/sdtm/design.py
to_mermaid
¶
Render the design as a Mermaid flowchart for a review document.
Elements are grouped into epoch subgraphs; edges follow the arm
paths, labelled with the ARMCD where the design branches (on the
first edge for a single arm). The diagram is a review view: it
carries ETCD, ELEMENT, TEDUR, the element epochs and the arm paths,
but not ARM, TESTRL, TEENRL, TABRANCH, TATRANS or a per-position
epoch. When :meth:from_mermaid cannot read the paths back (arms
with the same path, a repeated element, a crossover), a warning says
so. YAML (:meth:to_yaml) is the lossless round trip.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A Mermaid |
Examples:
Render for a design-review doc::
print(design.to_mermaid())
Source code in src/fleet/sdtm/design.py
from_usdm
classmethod
¶
Build a design from a CDISC USDM (DDF) study definition.
Maps the structural subset of USDM v3/v4 JSON: arms + epochs +
elements + studyCells become the arm paths (with the epoch of each
cell), encounters become visits, and eligibility criteria become TI
rows. TI text comes from the v4 criterion item (or the v3
population criteria), with usdm:tag resolved through the syntax
dictionary and XHTML removed. An identifier that starts with a
digit takes an IN or EX prefix (SDTMIG 3.4 section 4.5.3).
ponytail: schedule timelines, objectives/endpoints, and biomedical concepts are intentionally not mapped — extend when a consumer needs them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Parsed USDM JSON (the |
required |
study_id
|
str | None
|
Override for STUDYID; defaults to the first study identifier found in the USDM document. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
StudyDesign |
StudyDesign
|
Design with the mapped structural subset. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When a criterion has no text or no inclusion or exclusion category, a tag cannot be resolved, or two criteria give the same IETESTCD. |
Examples:
Import an OpenStudyBuilder / DDF export::
import json
design = fleet.StudyDesign.from_usdm(
json.loads(Path("usdm.json").read_text()),
study_id="CDISCPILOT01",
)
Source code in src/fleet/sdtm/design.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
load_strict_yaml
¶
Parse YAML like yaml.safe_load, but raise on a repeated key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The YAML document. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The parsed document. |
Raises:
| Type | Description |
|---|---|
ConstructorError
|
When a mapping repeats a key. |
Examples:
Load a trial design spec::
data = load_strict_yaml(Path("trial_design.yaml").read_text())
Source code in src/fleet/sdtm/design.py
options: show_source: false heading_level: 2 members_order: source show_root_heading: true
fleet.sdtm.tdd_audit
¶
Trial Design conformance pre-check — a P21-style dry run, offline.
Encodes the published, machine-checkable conformance rules that hit Trial Design domains hardest: the SD-series cross-domain structural checks and the FDA Technical Conformance Guide TS parameter profile (TS is the only rejection-level dataset — eCTD Technical Rejection Criterion 1734).
Rule IDs reference the public Pinnacle 21 Community / FDA business rule identifiers so findings can be cross-checked against a real P21 report. Sources: FDA TCG TS parameter list (fda.gov/media/153632), PHUSE US Connect 2026 paper DS22, PharmaSUG 2023 DS-149.
ponytail: a curated high-signal subset, not the full 100+ TDM rule catalog —
fleet validate runs the CDISC Rules Engine for exhaustive coverage.
audit
¶
Cross-check Trial Design domains against published conformance rules.
Every argument is optional — checks run only when the domains they need
are present. Inputs may be DataFrames, LazyFrames, or the TDD
collection models (TrialElements, TrialArms, ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
te
|
Any
|
Trial Elements domain. |
None
|
ta
|
Any
|
Trial Arms domain. |
None
|
tv
|
Any
|
Trial Visits domain. |
None
|
ts
|
Any
|
Trial Summary domain. |
None
|
ti
|
Any
|
Trial Inclusion/Exclusion domain. |
None
|
dm
|
Any
|
Demographics domain, for ARMCD cross-checks. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: One row per finding with |
Examples:
Pre-validate before shipping to P21::
findings = fleet.sdtm.tdd_audit.audit(te=te, ta=ta, ts=ts)
assert findings.filter(pl.col("severity") == "error").is_empty()
Source code in src/fleet/sdtm/tdd_audit.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
options: show_source: false heading_level: 2 members_order: source show_root_heading: true
fleet.sdtm.tdd
¶
Trial Design Domain (TDD) Pydantic models.
Provides row models, collection models, constrained types, and an Epoch
enum for the CDISC Trial Design domains: TE, TA, TV, TS, TI, TD, TM
(protocol-reference) and SV, SE (subject-level).
Each row model maps one record in the target SDTM domain and carries a
_SDTM_MAP that translates Python-friendly field names to official CDISC
variable names.
Each collection model wraps a list of row models and enforces integrity
constraints (uniqueness, ordering, FK references) at construction time via
Pydantic @model_validator. The to_polars() method converts the
validated collection into a pl.DataFrame with CDISC column names.
Usage::
from fleet.sdtm.tdd import TrialElement, TrialElements, Epoch
te = TrialElements(elements=[
TrialElement(etcd="SCRN", element="Screening",
tedur="P14D", epoch=Epoch.SCREENING),
TrialElement(etcd="TRT", element="Treatment",
tedur="P84D", epoch=Epoch.TREATMENT),
])
df = te.to_polars()
Epoch
¶
Bases: StrEnum
EPOCH (C99079) — all 14 CDISC-standard trial epoch values.
Source code in src/fleet/sdtm/tdd.py
TrialElement
¶
Bases: BaseModel
One row in the TE (Trial Elements) domain.
epoch is a design-time attribute: SDTMIG 3.4 has no EPOCH variable
in TE, so it is excluded from to_polars() output — but it drives the
element→epoch mapping used when deriving TA and SE.
Source code in src/fleet/sdtm/tdd.py
TrialArm
¶
Bases: BaseModel
One row-per-element in the TA (Trial Arms) domain.
Source code in src/fleet/sdtm/tdd.py
TrialVisit
¶
Bases: BaseModel
One row in the TV (Trial Visits) domain.
Source code in src/fleet/sdtm/tdd.py
TrialParameter
¶
Bases: BaseModel
One row in the TS (Trial Summary) domain.
Source code in src/fleet/sdtm/tdd.py
TrialCriterion
¶
Bases: BaseModel
One row in the TI (Trial Inclusion/Exclusion) domain.
Source code in src/fleet/sdtm/tdd.py
TrialDiseaseAssessment
¶
Bases: BaseModel
One row in the TD (Trial Disease Assessments) domain.
Source code in src/fleet/sdtm/tdd.py
TrialMilestone
¶
Bases: BaseModel
One row in the TM (Trial Disease Milestones) domain.
Source code in src/fleet/sdtm/tdd.py
TrialElements
¶
Bases: BaseModel
Typed collection of TE rows with TDD-specific integrity validation.
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated elements to a Polars DataFrame with SDTM names.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial elements::
te = TrialElements(elements=[...])
df = te.to_polars()
Source code in src/fleet/sdtm/tdd.py
TrialArms
¶
Bases: BaseModel
Typed collection of TA rows with TDD integrity validation.
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated arms to a Polars DataFrame with SDTM names.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial arms::
ta = TrialArms(arms=[...])
df = ta.to_polars()
Source code in src/fleet/sdtm/tdd.py
TrialVisits
¶
Bases: BaseModel
Typed collection of TV rows with TDD integrity validation.
Source code in src/fleet/sdtm/tdd.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
from_schedule
classmethod
¶
Build a visit schedule from day offsets relative to an anchor event.
Visits are sorted by offset; VISITNUM is assigned 1..N in that
order and VISITDY follows the CDISC no-day-zero convention
(offset 0 → day 1, negative offsets stay negative). TVSTRL is
rendered deterministically from the offset, anchor, and window, so
rule text stays consistent across visits and study amendments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule
|
list[tuple[str, int]]
|
|
required |
anchor
|
str
|
Name of the anchoring milestone (e.g. |
'RANDOMIZATION'
|
window
|
int | tuple[int, int] | None
|
Allowed deviation in study days (no Day 0, as
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TrialVisits |
TrialVisits
|
A validated collection ready for |
Examples:
Build a 12-week schedule anchored on randomization::
tv_rows = TrialVisits.from_schedule(
[("Screening", -14), ("Baseline", 0), ("Week 4", 28),
("Week 8", 56), ("Week 12", 84)],
anchor="RANDOMIZATION",
window=3,
)
tv = (
fleet.frame(pl.DataFrame()).sdtm
.fetch_structure("TV")
.study_header("CDISCPILOT01", "TV")
.add_visits(tv_rows)
.to_frame()
)
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated visits to a Polars DataFrame with SDTM names.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial visits::
tv = TrialVisits(visits=[...])
df = tv.to_polars()
Source code in src/fleet/sdtm/tdd.py
TrialParameters
¶
Bases: BaseModel
Typed collection of TS rows.
Source code in src/fleet/sdtm/tdd.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
from_ctgov
classmethod
¶
Seed TS parameters from a ClinicalTrials.gov registration.
Fetches the study record from the ClinicalTrials.gov v2 JSON API and maps the cleanly-derivable fields to TS parameters. The result is a starting point, not a submission-ready TS: dictionary-bound parameters (INDIC/SNOMED, TRT/UNII, PCLAS/MED-RT) are deliberately not guessed and must be added by the study team.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nct_id
|
str
|
ClinicalTrials.gov identifier (e.g. |
required |
timeout
|
float
|
HTTP timeout in seconds. |
30.0
|
Returns:
| Name | Type | Description |
|---|---|---|
TrialParameters |
TrialParameters
|
Collection with one row per derivable parameter (repeating parameters such as FCNTRY get incrementing TSSEQ). |
Raises:
| Type | Description |
|---|---|
HTTPError
|
When the NCT ID is unknown to the registry. |
Examples:
Seed TS from the registry, then extend and build::
ts_rows = TrialParameters.from_ctgov("NCT00048217")
ts = (
fleet.frame(pl.DataFrame()).sdtm
.fetch_structure("TS")
.study_header("CDISCPILOT01", "TS")
.add_parameters(ts_rows)
.to_frame()
)
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated parameters to a Polars DataFrame with SDTM names.
A TSVAL over 200 characters is split at a word boundary into TSVAL, TSVAL1, ..., TSVALn (SDTMIG 3.4 TS assumption 8). The space goes to the start of the next piece, so the pieces joined give the source text. A word over 200 characters is cut at 200.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial summary parameters::
ts = TrialParameters(parameters=[...])
df = ts.to_polars()
Source code in src/fleet/sdtm/tdd.py
TrialCriteria
¶
Bases: BaseModel
Typed collection of TI rows.
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated criteria to a Polars DataFrame with SDTM names.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial criteria::
ti = TrialCriteria(criteria=[...])
df = ti.to_polars()
Source code in src/fleet/sdtm/tdd.py
TrialDiseaseAssessments
¶
Bases: BaseModel
Typed collection of TD rows.
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated assessments to a Polars DataFrame with SDTM names.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial disease assessments::
td = TrialDiseaseAssessments(assessments=[...])
df = td.to_polars()
Source code in src/fleet/sdtm/tdd.py
TrialMilestones
¶
Bases: BaseModel
Typed collection of TM rows.
Source code in src/fleet/sdtm/tdd.py
to_polars
¶
Convert validated milestones to a Polars DataFrame with SDTM names.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: DataFrame with columns named per CDISC SDTM (e.g.
|
Examples:
Materialise trial disease milestones::
tm = TrialMilestones(milestones=[...])
df = tm.to_polars()
Source code in src/fleet/sdtm/tdd.py
parse_trial_design
¶
Parse a Mermaid flowchart into TE and TA collections.
Each subgraph ID[TITLE] is an epoch; each node inside it is an
element (ETCD["Element name<br/>P14D"]); each path from the start
node to an end node is an arm, named by the last |ARMCD| label on
its edges. A title that is not a C99079 term is kept, upper case, as a
sponsor epoch, with a warning. %% comment lines are skipped.
The diagram carries ETCD, ELEMENT, TEDUR, EPOCH and the arm paths. It does not carry ARM, TESTRL, TEENRL, TABRANCH or TATRANS, and it cannot carry a crossover or an element that repeats in one arm: YAML is the lossless round trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mermaid_text
|
str
|
A Mermaid |
required |
Returns:
| Type | Description |
|---|---|
tuple[TrialElements, TrialArms]
|
tuple[TrialElements, TrialArms]: Validated collections ready for
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On an empty diagram, a line of an unknown form, a node outside a subgraph, an unlabelled fork, a cycle, a node with no edge, more than one start node, or two nodes or two arms that give the same code. |
Examples:
Parse a simple 3-element design::
te, ta = parse_trial_design('''
flowchart TD
subgraph SCR[SCREENING]
SCRN["Screening<br/>P14D"]
end
subgraph TRT[TREATMENT]
TREAT["Treatment<br/>P84D"]
end
subgraph FU[FOLLOW-UP]
FOLL["Follow-up<br/>P28D"]
end
SCRN --> TREAT
TREAT --> FOLL
''')
Source code in src/fleet/sdtm/tdd.py
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
options: show_source: false heading_level: 2 members_order: source show_root_heading: true
fleet.sdtm._tdd_mixin
¶
Trial Design Domain mixin — adds TDD verbs to SDTMNamespace.
Provides two families of verbs:
Protocol-reference verbs
fetch_structure(), study_header(), add_elements(),
add_arms(), add_visits(), add_parameters(),
add_criteria(), add_disease_assessments(),
add_milestones() — follow a fixed stage sequence.
Subject-level verbs
visit_map(), element_boundaries(), epoch_assign(),
study_day() — freely mixable with any existing SDTM verb.
TrialDesignMixin
¶
Mixin that adds Trial Design Domain verbs to the SDTM namespace.
Stage tracking (_tdd_stage) ensures protocol-reference verbs are
called in the correct order. Subject-level verbs ignore the stage.
Source code in src/fleet/sdtm/_tdd_mixin.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 | |
fetch_structure
¶
Query the CDISC Library for domain's IG structure.
When define_path is given the domain variables (including core)
are read from the define.yaml first; if the domain is not found the
method falls back to the online CDISC Library.
When save_to is given the fetched metadata is cached as YAML; on subsequent calls the cache is read instead of hitting the API.
SDTMIG 3.4 structures for the nine TDD domains (TE, TA, TV, TS, TI, TD, TM, SV, SE) ship with Fleet, so the default flow needs no network access and no API key; the CDISC Library is only queried for other domains or IG versions.
Sets _domain_meta on the namespace for downstream validation
and performs schema reconciliation against the static Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
SDTM domain code (e.g. |
required |
ig_version
|
str
|
SDTM IG version slug (default |
'3-4'
|
save_to
|
str | Path | None
|
Optional path to cache the fetched YAML. |
None
|
define_path
|
str | Path | None
|
Optional path to a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 1; call |
Examples:
Fetch the TE structure from the CDISC Library::
te = (
pl.DataFrame().sdtm
.fetch_structure("TE", ig_version="3-4",
save_to="metadata/te_structure.yaml")
.study_header("CDISCPILOT01", "TE")
.add_elements(te_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
study_header
¶
Hardcode STUDYID and DOMAIN columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_id
|
str
|
The study identifier value. |
required |
domain
|
str
|
The SDTM domain code. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 2; call an |
Examples:
Set the study header for a TE domain::
te = (
pl.DataFrame().sdtm
.fetch_structure("TE")
.study_header("CDISCPILOT01", "TE")
.add_elements(te_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_elements
¶
Materialise a validated TrialElements collection into the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
TrialElements
|
A |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TE rows loaded. |
Examples:
Add trial elements to a TE pipeline::
te = (
pl.DataFrame().sdtm
.fetch_structure("TE")
.study_header("CDISCPILOT01", "TE")
.add_elements(te_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_arms
¶
Materialise a validated TrialArms collection into the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arms
|
TrialArms
|
A |
required |
te
|
TrialElements | None
|
Optional |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TA rows loaded. |
Examples:
Add trial arms with FK validation::
ta = (
pl.DataFrame().sdtm
.fetch_structure("TA")
.study_header("CDISCPILOT01", "TA")
.add_arms(ta_rows, te=te_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_visits
¶
Materialise a validated TrialVisits collection into the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visits
|
TrialVisits
|
A |
required |
ta
|
TrialArms | None
|
Optional |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TV rows loaded. |
Examples:
Add trial visits with FK validation::
tv = (
pl.DataFrame().sdtm
.fetch_structure("TV")
.study_header("CDISCPILOT01", "TV")
.add_visits(tv_rows, ta=ta_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_parameters
¶
Materialise a validated TrialParameters collection into the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
TrialParameters
|
A |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TS rows loaded. |
Examples:
Add trial summary parameters::
ts = (
pl.DataFrame().sdtm
.fetch_structure("TS")
.study_header("CDISCPILOT01", "TS")
.add_parameters(ts_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_criteria
¶
Materialise a validated TrialCriteria collection into the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
criteria
|
TrialCriteria
|
A |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TI rows loaded. |
Examples:
Add inclusion/exclusion criteria::
ti = (
pl.DataFrame().sdtm
.fetch_structure("TI")
.study_header("CDISCPILOT01", "TI")
.add_criteria(ti_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_disease_assessments
¶
Materialise a validated TrialDiseaseAssessments collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assessments
|
TrialDiseaseAssessments
|
A |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TD rows loaded. |
Examples:
Add trial disease assessments::
td = (
pl.DataFrame().sdtm
.fetch_structure("TD")
.study_header("CDISCPILOT01", "TD")
.add_disease_assessments(td_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
add_milestones
¶
Materialise a validated TrialMilestones collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
milestones
|
TrialMilestones
|
A |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace at stage 3 with TM rows loaded. |
Examples:
Add trial disease milestones::
tm = (
pl.DataFrame().sdtm
.fetch_structure("TM")
.study_header("CDISCPILOT01", "TM")
.add_milestones(tm_rows)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
visit_map
¶
Map raw visit dates to planned visits from TV, by nearest study day.
Use it only when the CRF does not collect the visit: it never
replaces a collected VISITNUM. For each row, the verb takes the
planned visit whose VISITDY is nearest to the actual study day
(from date_col and ref_date), within the optional tolerance
window. The distance is the difference of the study-day numbers,
as abs(SVSTDY - VISITDY) in a SAS program: across the missing
Day 0, Day -1 is 2 days from VISITDY 1. Ties resolve to the
earlier VISITNUM. When TV has ARMCD values, a row only
takes a visit of its own arm or a visit with a blank ARMCD.
A dated row outside every window is an unscheduled visit. It gets
the VISITNUM of the last planned visit on or before its study
day plus .1, .2, ... in date order within the subject, and the
VISIT UNSCHEDULED <VISITNUM>. A row with no study day gets
a null. One warning gives both counts. With DOMAIN SV, one
warning gives the USUBJID + VISITNUM keys that repeat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_num
|
str
|
Name of the output |
required |
target_name
|
str
|
Name of the output |
required |
date_col
|
str
|
Column containing the actual visit date (ISO 8601 string). |
required |
planned_visits
|
TrialVisits | DataFrame
|
A |
required |
ref_date
|
str | None
|
Column with the reference date for the study day.
When it is not a column of the frame, it is read from the
pinned DM, as |
None
|
tolerance
|
dict[str, int] | None
|
Optional |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target_num and target_name appended. |
Raises:
| Type | Description |
|---|---|
DerivationError
|
When date_col or ref_date cannot be found,
when TV has arm-specific visits and the frame has no
|
References
SDTMIG 3.4 SV and TV: USUBJID + VISITNUM is the SV key,
VISITNUM is Req, a null TV ARMCD means all arms. The
decimal number of an unscheduled visit is a sponsor convention
(the CDISC pilot uses UNSCHEDULED 5.1); see
docs/adr/0035-visit-map-numbers-an-unscheduled-visit.md.
Examples:
Map subject visits to planned visits::
sv = (
raw_visits.sdtm
.assign("DOMAIN", value="SV")
.assign("USUBJID", source="subject_id")
.date("SVSTDTC", source="visit_date")
.pin("DM", dm)
.visit_map("VISITNUM", "VISIT",
date_col="SVSTDTC",
planned_visits=tv_rows,
ref_date="RFSTDTC",
tolerance={"before": 3, "after": 3})
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
element_boundaries
¶
element_boundaries(
target_start,
target_end,
*,
milestones,
element_col="ETCD",
subject_col="USUBJID"
)
Derive element start/end dates from milestone columns.
For each element_col value, maps the corresponding column from milestones to produce target_start. The end date is the start of the next element by start date within the subject: the verb sorts on the ISO 8601 start text (a null start last, then the row order), so the input row order does not matter. The output keeps the input row order. The last element gets a null end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_start
|
str
|
Name of the output start-date column (e.g. |
required |
target_end
|
str
|
Name of the output end-date column (e.g. |
required |
milestones
|
dict[str, str]
|
|
required |
element_col
|
str
|
Column identifying the element (default |
'ETCD'
|
subject_col
|
str
|
Column identifying the subject (default |
'USUBJID'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target_start and target_end appended. |
Examples:
Derive SE element boundaries::
se = (
disposition_df.sdtm
.element_boundaries("SESTDTC", "SEENDTC",
milestones={"SCRN": "screening_date",
"TRT": "first_dose_date"})
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
epoch_assign
¶
epoch_assign(
target,
*,
date_col,
epoch_ranges=None,
se=None,
subject_col="USUBJID",
same_day="by_class"
)
Assign EPOCH based on date ranges or per-subject SE intervals.
With epoch_ranges, each entry maps a study-level date interval to
an Epoch value; the first matching range wins. With se, the
subject's own element intervals drive the assignment: for each row,
the epoch of the SE record whose [SESTDTC, SEENDTC] interval
contains the date (SDTMIG 3.4: EPOCH of the start or collection
date/time). A blank or null SEENDTC is open-ended; an element
whose dates are partial is skipped, with a warning.
On a transition date, where one element ends and the next starts, the time decides when the record and the boundary both have one. When one of them has no time, same_day decides, and one warning gives the count and the rule:
"by_class"(default): a Findings date (--DTC) takes the earlier element, an Events or Interventions date (--STDTC) the later one. Any other date_col name raises."earlier": the element that ends on that date."later": the element that starts on that date.
No guidance fixes this case, so state the rule in the SDRG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Name of the output |
required |
date_col
|
str
|
Column containing the date to classify. |
required |
epoch_ranges
|
list[dict[str, str]] | DataFrame | None
|
A list of |
None
|
se
|
DataFrame | LazyFrame | None
|
An SE domain frame with |
None
|
subject_col
|
str
|
Subject key used to join se (default
|
'USUBJID'
|
same_day
|
Literal['by_class', 'earlier', 'later']
|
The rule for a record with no time on a transition date (with se only). |
'by_class'
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The namespace with target appended. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither or both of epoch_ranges and se are provided. |
DerivationError
|
When |
Examples:
Stamp EPOCH onto any domain from the subject's SE intervals::
ae = (
ae_raw.sdtm
.assign("USUBJID", source="subject_id")
.date("AESTDTC", source="ae_start_date")
.epoch_assign("EPOCH", date_col="AESTDTC", se=se)
.to_frame()
)
Source code in src/fleet/sdtm/_tdd_mixin.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
packaged_structure
¶
Return the packaged SDTMIG 3.4 label and variables of a trial design domain.
options: show_source: false heading_level: 2 members_order: source show_root_heading: true members: - TrialDesignMixin