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 import PSDLParser, PSDLEvaluator, InMemoryBackend, DataPoint
from psdl.examples import get_scenario, list_scenarios
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_data(
patient_id="patient_123",
signal_name="Cr",
data=[
DataPoint(now - timedelta(hours=6), 1.0),
DataPoint(now - timedelta(hours=3), 1.3),
DataPoint(now, 1.8),
]
)
# Evaluate
evaluator = PSDLEvaluator(scenario, backend)
result = evaluator.evaluate_patient(patient_id="patient_123", reference_time=now)
if result.is_triggered:
print(f"Alert: {result.triggered_logic}")
Define Your Own Scenario
scenario: AKI_Early_Detection
version: "0.1.0"
signals:
Cr:
source: creatinine
concept_id: 3016723 # OMOP concept
unit: mg/dL
trends:
cr_rising:
expr: delta(Cr, 6h) > 0.3
description: "Creatinine rise > 0.3 mg/dL in 6 hours"
cr_high:
expr: last(Cr) > 1.5
description: "Current creatinine elevated"
logic:
aki_risk:
expr: cr_rising AND cr_high
severity: high
description: "Early AKI - rising and elevated creatinine"
from psdl import PSDLParser
parser = PSDLParser()
scenario = parser.parse_file("my_scenario.yaml")
# or parse from string
scenario = parser.parse(yaml_content)
Temporal Operators
| Operator | Example | Description |
|---|---|---|
delta |
delta(Cr, 6h) > 0.3 |
Change over time window |
slope |
slope(HR, 1h) > 5 |
Linear trend (regression) |
last |
last(Cr) > 1.5 |
Most recent value |
min/max |
max(Temp, 24h) > 38.5 |
Min/max in window |
sma/ema |
ema(BP, 2h) < 90 |
Moving averages |
count |
count(Cr, 24h) >= 2 |
Observation count |
Window formats: 30s, 5m, 6h, 1d, 7d
Data Adapters
OMOP CDM
from psdl import get_omop_adapter
OMOPAdapter = get_omop_adapter()
adapter = OMOPAdapter(connection_string="postgresql://...")
FHIR R4
from psdl import get_fhir_adapter
FHIRAdapter = get_fhir_adapter()
adapter = FHIRAdapter(base_url="https://hapi.fhir.org/baseR4")
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.3.1.tar.gz.
File metadata
- Download URL: psdl_lang-0.3.1.tar.gz
- Upload date:
- Size: 188.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
493b62b9e068e5c0e488144d3653f15afd44db35573ef02380185e1467f8df99
|
|
| MD5 |
099458ec45f6d084a3b977a420829942
|
|
| BLAKE2b-256 |
fd9887619a3419ebc0aeefc3459da7489118cf084a72b571186278775550c170
|
Provenance
The following attestation bundles were made for psdl_lang-0.3.1.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.3.1.tar.gz -
Subject digest:
493b62b9e068e5c0e488144d3653f15afd44db35573ef02380185e1467f8df99 - Sigstore transparency entry: 765416534
- Sigstore integration time:
-
Permalink:
Chesterguan/PSDL@5640a6f60dc63f29c7bc66f945787b53f8786e7a -
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@5640a6f60dc63f29c7bc66f945787b53f8786e7a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file psdl_lang-0.3.1-py3-none-any.whl.
File metadata
- Download URL: psdl_lang-0.3.1-py3-none-any.whl
- Upload date:
- Size: 141.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52893a45ee81486a2fc817450ae7791851111319215b001818bcab876876034e
|
|
| MD5 |
e7e2117e5ea50732bb7907942b772afd
|
|
| BLAKE2b-256 |
8f36202a5695c3f5631302844b9a8928d4fe1162ffcf9f5b22f81e7828df9301
|
Provenance
The following attestation bundles were made for psdl_lang-0.3.1-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.3.1-py3-none-any.whl -
Subject digest:
52893a45ee81486a2fc817450ae7791851111319215b001818bcab876876034e - Sigstore transparency entry: 765416557
- Sigstore integration time:
-
Permalink:
Chesterguan/PSDL@5640a6f60dc63f29c7bc66f945787b53f8786e7a -
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@5640a6f60dc63f29c7bc66f945787b53f8786e7a -
Trigger Event:
workflow_dispatch
-
Statement type: