Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

tss-validate

CDISC conformance validation crate.

Overview

tss-validate checks data against SDTM implementation guide rules and controlled terminology.

Responsibilities

  • Structural validation (required variables, types)
  • Content validation (controlled terminology, formats)
  • Cross-record validation (relationships, duplicates)
  • Generate validation reports

Dependencies

[dependencies]
tss-standards = { path = "../tss-standards" }
tss-model = { path = "../tss-model" }
regex = "1"
chrono = "0.4"

Architecture

Module Structure

tss-validate/
├── src/
│   ├── lib.rs
│   ├── engine.rs        # Validation orchestration
│   ├── rules/
│   │   ├── mod.rs
│   │   ├── structural.rs   # Structure rules
│   │   ├── content.rs      # Value rules
│   │   ├── terminology.rs  # CT validation
│   │   └── cross_record.rs # Relationship rules
│   ├── result.rs        # Validation results
│   └── report.rs        # Report generation

Validation Engine

Rule Interface

#![allow(unused)]
fn main() {
pub trait ValidationRule {
    fn id(&self) -> &str;
    fn severity(&self) -> Severity;
    fn validate(&self, context: &ValidationContext) -> Vec<ValidationResult>;
}
}

Severity Levels

#![allow(unused)]
fn main() {
pub enum Severity {
    Error,    // Blocks export
    Warning,  // Should review
    Info,     // Informational
}
}

Validation Context

#![allow(unused)]
fn main() {
pub struct ValidationContext<'a> {
    pub domain: &'a str,
    pub data: &'a DataFrame,
    pub mappings: &'a [Mapping],
    pub standards: &'a Standards,
}
}

Built-in Rules

Structural Rules (SD*)

RuleDescription
SD0001Required variable missing
SD0002Invalid variable name
SD0003Variable length exceeded
SD0004Invalid data type

Terminology Rules (CT*)

RuleDescription
CT0001Value not in codelist
CT0002Invalid date format
CT0003Date out of range

Cross-Record Rules (XR*)

RuleDescription
XR0001USUBJID not in DM
XR0002Duplicate key values

API

Running Validation

#![allow(unused)]
fn main() {
use tss_validate::{Validator, ValidationContext};

let validator = Validator::new( & standards);
let results = validator.validate( & context) ?;

for result in results.errors() {
println ! ("{}: {}", result.rule_id, result.message);
}
}

Custom Rules

#![allow(unused)]
fn main() {
struct MyCustomRule;

impl ValidationRule for MyCustomRule {
    fn id(&self) -> &str { "CUSTOM001" }
    fn severity(&self) -> Severity { Severity::Warning }
    fn validate(&self, ctx: &ValidationContext) -> Vec<ValidationResult> {
        // Custom logic
    }
}
}

Testing

cargo test --package tss-validate

Test Strategy

  • Unit tests for each rule
  • Integration tests with sample data
  • Property tests for edge cases

See Also