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.4.0.tar.gz (211.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.4.0-py3-none-any.whl (154.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psdl_lang-0.4.0.tar.gz
  • Upload date:
  • Size: 211.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.4.0.tar.gz
Algorithm Hash digest
SHA256 6b108b02867220629bc0da8edc4f1b7d2830fa6291cd7c076af0ba818ad36300
MD5 f63b406a0910f3a1edec665179d7bff5
BLAKE2b-256 85a0dc02aaa86a16ad9d93e91abde0f1725b96f4f541c3f7b412f12b5d28cf04

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: psdl_lang-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 154.0 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f722b33e05e52c5199a0b7ac27d543bf7ba9036856912189ad7f27706a4cfc
MD5 6fb56070392acbc183c1a977799ffbdf
BLAKE2b-256 f8a6d2532eb8ed85347c11864a30a915fec691dc0fdcfcf0687a20511725b2cd

See more details on using hashes here.

Provenance

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