Skip to main content

Patient Scenario Definition Language - Reference Implementation

Project description

PSDL - Patient Scenario Definition Language

Tests PyPI version Python 3.8-3.12 License: Apache 2.0

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

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

psdl_lang-0.3.2.tar.gz (199.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psdl_lang-0.3.2-py3-none-any.whl (148.7 kB view details)

Uploaded Python 3

File details

Details for the file psdl_lang-0.3.2.tar.gz.

File metadata

  • Download URL: psdl_lang-0.3.2.tar.gz
  • Upload date:
  • Size: 199.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for psdl_lang-0.3.2.tar.gz
Algorithm Hash digest
SHA256 0ee884b72cfda36d88225cf3d349e20b9acfcf8261a8d0c264203891803f52a7
MD5 f9a26ce81c389c6afa1724bad157824a
BLAKE2b-256 c1d65a7db02990640385ac642a73cba0d75dd55221227929d551ca013c1a46de

See more details on using hashes here.

Provenance

The following attestation bundles were made for psdl_lang-0.3.2.tar.gz:

Publisher: publish.yml on Chesterguan/PSDL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file psdl_lang-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: psdl_lang-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 148.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for psdl_lang-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 deb1deab2282ebd642370f889b38d946a85ee21125c5aa949723dbf53a4e82ad
MD5 8595f1203beff45e8bc544eafd969dee
BLAKE2b-256 1b16b7cb7a911b052a3dd0977c40cd1ed713c24c50c69d975082749dbd6a4aa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for psdl_lang-0.3.2-py3-none-any.whl:

Publisher: publish.yml on Chesterguan/PSDL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page