Skip to main content

Overview

The RAADS-R application uses strongly-typed TypeScript interfaces defined in src/data/dataset.schema.ts. These types ensure type safety across the scoring engine, UI components, and state management.

Core Data Types

Item

Represents a single question in the assessment.
dataset.schema.ts:9
export interface Item {
  id: number;
  text: string;
  isNormative: boolean;
  domain: string;
}
id
number
required
Unique identifier (1-80). Item IDs are sequential with no gaps.
text
string
required
The question text displayed to the user.
isNormative
boolean
required
Determines scoring direction:
  • true: Normative item (reversed scoring)
  • false: Symptom item (standard scoring)
domain
string
required
Domain key this item belongs to: "social", "interests", "language", or "sensory"

Domain

Defines a scoring domain with its items and thresholds.
dataset.schema.ts:1
export interface Domain {
  key: string;
  label: string;
  itemIds: number[];
  maxScore: number;
  cutoff: number;
}
key
string
required
Domain identifier: social, interests, language, sensory
label
string
required
Human-readable domain name for display.
itemIds
number[]
required
Array of item IDs belonging to this domain. No item appears in multiple domains.
maxScore
number
required
Maximum possible score for this domain (number of items × 3).
cutoff
number
required
Clinical threshold for this domain. Scores strictly greater than this value indicate above-cutoff.

DatasetMeta

Container for assessment metadata and configuration.
dataset.schema.ts:16
export interface DatasetMeta {
  totalItems: number;
  responseOptions: string[];
  domains: Domain[];
  totalCutoff: number;
}
totalItems
number
required
Total number of items in the assessment (80).
responseOptions
string[]
required
Array of exactly 4 response option labels:
  1. “True now and when I was young”
  2. “True only now”
  3. “True only when I was younger than 16”
  4. “Never true”
domains
Domain[]
required
Array of all domain configurations.
totalCutoff
number
required
Overall clinical threshold (65). Total scores > 65 indicate above-cutoff.

Dataset

Root data structure containing all assessment data.
dataset.schema.ts:23
export interface Dataset {
  meta: DatasetMeta;
  items: Item[];
}

Response Types

Response

A single user response to a question.
dataset.schema.ts:28
export type Response = 0 | 1 | 2 | 3;
Response values are literal types (0-3) corresponding to the four response options. This provides compile-time safety against invalid response values.

Responses

Collection of all user responses, keyed by item ID.
dataset.schema.ts:29
export type Responses = Record<number, Response>;
Example:
const responses: Responses = {
  1: 2,  // Item 1: "True only when I was younger than 16"
  2: 0,  // Item 2: "True now and when I was young"
  3: 3,  // Item 3: "Never true"
  // ...
};

Results Types

DomainResult

Scoring results for a single domain.
dataset.schema.ts:31
export interface DomainResult {
  key: string;
  label: string;
  score: number;
  maxScore: number;
  cutoff: number;
  aboveCutoff: boolean;
}
key
string
Domain identifier (matches Domain.key)
label
string
Human-readable domain name
score
number
Computed score for this domain (sum of all item scores)
maxScore
number
Maximum possible score (copied from domain definition)
cutoff
number
Clinical threshold (copied from domain definition)
aboveCutoff
boolean
true if score > cutoff (strict comparison)

Results

Complete scoring results including total and per-domain scores.
dataset.schema.ts:40
export interface Results {
  total: number;
  totalMax: number;
  totalCutoff: number;
  aboveTotalCutoff: boolean;
  domains: DomainResult[];
}
total
number
Sum of all domain scores (0-240)
totalMax
number
Maximum possible total score (always 240)
totalCutoff
number
Overall clinical threshold (65)
aboveTotalCutoff
boolean
true if total > totalCutoff
domains
DomainResult[]
Array of per-domain scoring results

Data Validation

The dataset structure is validated through comprehensive tests in src/__tests__/dataset.test.ts:
  • Exactly 80 items with IDs 1-80 (no gaps)
  • All required fields present and correctly typed
  • 4 response options in correct order
  • Domain item counts: Social (39), Interests (14), Language (7), Sensory (20)

Type Safety Examples

import type { Dataset, Responses, Response } from './data/dataset.schema';
import dataset from './data/dataset.json';

const typedDataset = dataset as Dataset;

// ✅ Type-safe response creation
const responses: Responses = {};
responses[1] = 2;  // Valid
// responses[1] = 4;  // ❌ Type error: 4 is not assignable to type Response

// ✅ Type-safe domain access
const socialDomain = typedDataset.meta.domains.find(d => d.key === 'social');
if (socialDomain) {
  console.log(`Social domain has ${socialDomain.itemIds.length} items`);
}

// ✅ Type-safe iteration
for (const item of typedDataset.items) {
  console.log(`${item.id}: ${item.text} [${item.domain}]`);
}

Implementation Files

  • Schema Definition: src/data/dataset.schema.ts
  • Dataset JSON: src/data/dataset.json
  • Validation Tests: src/__tests__/dataset.test.ts

Build docs developers (and LLMs) love