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.0.tar.gz (139.2 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.0-py3-none-any.whl (105.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psdl_lang-0.3.0.tar.gz
  • Upload date:
  • Size: 139.2 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.0.tar.gz
Algorithm Hash digest
SHA256 47e74dc0cdbe6c8c78879e31eea377049a1c5194e00457d9f407bb10c7d88a12
MD5 e65eb2c564cfdd49113d6ad1c41c4b99
BLAKE2b-256 3b188c447ace64d3fdfa096c8ece3cfc2ff0b2f226de98c6bbe2f27c94cb4814

See more details on using hashes here.

Provenance

The following attestation bundles were made for psdl_lang-0.3.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: psdl_lang-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 105.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db928d5c7268b8bde66021e84ebee23557132d2c0a0dc2056e7a5efe51196ece
MD5 1c513e14ec96a709e4e62bd88ca44476
BLAKE2b-256 27dd4cd94264196329c5fd7e85c2d98065786f5122c6d35f39b2b9f542ff88f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for psdl_lang-0.3.0-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