Skip to content

Canonical ClinicalPrediction model + Delta outbox schema #20

Description

@slusset

Parent Epic

Part of #16 — [Epic] Databricks EHR Writeback — Delta Outbox + Canonical Prediction Model

Summary

Define the canonical ClinicalPrediction domain model and the Delta outbox table that stores it with processing semantics.

Tasks

  • Define ClinicalPrediction Pydantic model with fields: prediction_id, patient_id, encounter_id, prediction_code, values[] (label, value, unit), effective_datetime, model_id, model_version, metadata
  • Define PredictionValue Pydantic model for the values array (supports scalar and vector)
  • Define Delta outbox table schema — adds processing columns: status (pending/processing/completed/failed/dead_letter), locked_by, locked_at, retry_count, last_error, created_at, updated_at
  • Implement lease-based MERGE semantics: claim (pending → processing with lock), release (processing → completed/failed), expire stale locks
  • New module: src/ehr_writeback/outbox/ with models.py, outbox_store.py
  • Unit tests for model validation and outbox CRUD operations

Acceptance Criteria

  • ClinicalPrediction model validates scalar (single value) and vector (multi-value) predictions
  • Outbox store can claim a batch of N pending records atomically via MERGE
  • Stale locks (older than configurable timeout) are automatically reclaimable
  • Unit tests pass with mocked Spark session

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions