Patient Scenario Definition Language - Reference Implementation
Project description
PSDL - Patient Scenario Definition Language
An open, vendor-neutral standard for expressing clinical scenarios in healthcare AI.
What SQL became for data queries, ONNX for ML models, and GraphQL for APIs — PSDL is becoming the semantic layer for clinical AI.
Installation
pip install psdl-lang
# With OMOP adapter
pip install psdl-lang[omop]
# With FHIR adapter
pip install psdl-lang[fhir]
# Full installation
pip install psdl-lang[full]
Quick Start
from psdl.examples import get_scenario, list_scenarios
from psdl.runtimes.single import SinglePatientEvaluator, InMemoryBackend
from datetime import datetime, timedelta
# List available built-in scenarios
print(list_scenarios())
# ['aki_detection', 'hyperkalemia_detection', 'lactic_acidosis', 'sepsis_screening']
# Load a built-in scenario
scenario = get_scenario("aki_detection")
print(f"Loaded: {scenario.name}")
# Set up data backend and add patient data
backend = InMemoryBackend()
now = datetime.now()
backend.add_observation(123, "Cr", 1.0, now - timedelta(hours=6))
backend.add_observation(123, "Cr", 1.3, now - timedelta(hours=3))
backend.add_observation(123, "Cr", 1.8, now)
# Evaluate
evaluator = SinglePatientEvaluator(scenario, backend)
result = evaluator.evaluate(patient_id=123, reference_time=now)
if result.is_triggered:
print(f"Alert: {result.triggered_logic}")
Define Your Own Scenario
scenario: AKI_Early_Detection
version: "0.3.0"
audit:
intent: "Detect early acute kidney injury using creatinine trends"
rationale: "Early AKI detection enables timely intervention"
provenance: "KDIGO Clinical Practice Guideline for AKI (2012)"
signals:
Cr:
ref: creatinine # Semantic reference (resolved via Dataset Spec)
unit: mg/dL
trends:
# v0.3: Trends produce numeric values only
cr_delta:
expr: delta(Cr, 6h)
description: "Creatinine change over 6 hours"
cr_current:
expr: last(Cr)
description: "Current creatinine value"
logic:
# v0.3: Comparisons belong in logic layer
cr_rising:
when: cr_delta > 0.3
description: "Rising creatinine"
cr_high:
when: cr_current > 1.5
description: "Elevated creatinine"
aki_risk:
when: cr_rising AND cr_high
severity: high
description: "Early AKI - rising and elevated creatinine"
from psdl.core import parse_scenario
scenario = parse_scenario("my_scenario.yaml")
# or parse from string
scenario = parse_scenario(yaml_content)
Temporal Operators
| Operator | Example | Description |
|---|---|---|
delta |
delta(Cr, 6h) |
Change over time window |
slope |
slope(HR, 1h) |
Linear trend (regression) |
last |
last(Cr) |
Most recent value |
min/max |
max(Temp, 24h) |
Min/max in window |
sma/ema |
ema(BP, 2h) |
Moving averages |
count |
count(Cr, 24h) |
Observation count |
Window formats: 30s, 5m, 6h, 1d, 7d
Why PSDL?
| Challenge | Without PSDL | With PSDL |
|---|---|---|
| Portability | Logic tied to hospital systems | Same scenario runs anywhere |
| Auditability | Scattered across code/configs | Single version-controlled file |
| Reproducibility | Hidden state, implicit deps | Deterministic execution |
| Compliance | Manual documentation | Built-in audit primitives |
Links
- GitHub: github.com/Chesterguan/PSDL
- Documentation: Whitepaper
- Examples: Example Scenarios
- Try in Colab: Interactive Notebook
License
Apache 2.0 - See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file psdl_lang-0.5.0.tar.gz.
File metadata
- Download URL: psdl_lang-0.5.0.tar.gz
- Upload date:
- Size: 214.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a7215fd232b984ee56666537f43ca86e79e30e44f6e3dbe85f2ab7871bd8882
|
|
| MD5 |
3a9a2b1ac9c711a130e7e748bc60780d
|
|
| BLAKE2b-256 |
dab7e5b03a14f5e7c0bef432c663ebe63f019a4ff7606689986e926c47b757d2
|
Provenance
The following attestation bundles were made for psdl_lang-0.5.0.tar.gz:
Publisher:
publish.yml on Chesterguan/PSDL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psdl_lang-0.5.0.tar.gz -
Subject digest:
7a7215fd232b984ee56666537f43ca86e79e30e44f6e3dbe85f2ab7871bd8882 - Sigstore transparency entry: 1286118413
- Sigstore integration time:
-
Permalink:
Chesterguan/PSDL@375b84f8638f2641ec193fe959a574f57e14323d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Chesterguan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@375b84f8638f2641ec193fe959a574f57e14323d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file psdl_lang-0.5.0-py3-none-any.whl.
File metadata
- Download URL: psdl_lang-0.5.0-py3-none-any.whl
- Upload date:
- Size: 154.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12ed63ecc22bd6bf11a7df32d1f746f06b38286f7362d249e0d3610750162307
|
|
| MD5 |
9d8414bd12f3e4c3ef1aed9b2da07d28
|
|
| BLAKE2b-256 |
7b839247f08f4a4bba665797dfd864baacb58974f92b8ab8e9fd403fb4e17a09
|
Provenance
The following attestation bundles were made for psdl_lang-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on Chesterguan/PSDL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psdl_lang-0.5.0-py3-none-any.whl -
Subject digest:
12ed63ecc22bd6bf11a7df32d1f746f06b38286f7362d249e0d3610750162307 - Sigstore transparency entry: 1286118489
- Sigstore integration time:
-
Permalink:
Chesterguan/PSDL@375b84f8638f2641ec193fe959a574f57e14323d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Chesterguan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@375b84f8638f2641ec193fe959a574f57e14323d -
Trigger Event:
workflow_dispatch
-
Statement type: