Download src/core/lifecycle/models.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 6.1 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/lifecycle/models.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/core/lifecycle/models.py
-
curl -L -o models.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/lifecycle/models.py
6.1 kB
| """ | |
| Domain-Agnostic Lifecycle Value Objects | |
| These Pydantic models are persistence-agnostic — they serialize to/from JSON | |
| and can be stored as a JSON column in any engine's case model (SQLModel, | |
| dataclass, or plain dict). | |
| Three phases: | |
| 1. ReadinessChecklist — Pre-event readiness/clearance tracking | |
| 2. TimelineEventEntry — Real-time event capture during the case | |
| 3. CompletionPlan — Post-event completion, barriers, follow-ups | |
| """ | |
| from __future__ import annotations | |
| from datetime import datetime, timezone | |
| from enum import Enum | |
| from typing import Dict, List, Optional, Set | |
| from pydantic import BaseModel, Field | |
| # ─── Phase Item Status (shared across readiness items) ─────────────────────── | |
| class PhaseItemStatus(str, Enum): | |
| """Status of a single readiness/clearance item.""" | |
| NOT_STARTED = "not_started" | |
| PENDING = "pending" | |
| REVIEWED = "reviewed" | |
| ABNORMAL = "abnormal" | |
| CLEARED = "cleared" | |
| NOT_APPLICABLE = "not_applicable" | |
| _PASS_STATES: Set[PhaseItemStatus] = { | |
| PhaseItemStatus.REVIEWED, | |
| PhaseItemStatus.CLEARED, | |
| PhaseItemStatus.NOT_APPLICABLE, | |
| } | |
| # ─── 1. Pre-Event Readiness ───────────────────────────────────────────────── | |
| class ReadinessChecklist(BaseModel): | |
| """ | |
| Domain-agnostic pre-event readiness tracker. | |
| Stores named items (key → PhaseItemStatus) plus a set of critical keys | |
| that must pass before the case can proceed. | |
| Works for: | |
| Surgio → Pre-Op Clearance (labs, anesthesia, consent …) | |
| Insura → Pre-Claim Assessment (documentation, eligibility …) | |
| Movio → Pre-Trip Checklist (vehicle, cargo, route …) | |
| Stay → Pre-Arrival Prep (room, amenities, dietary …) | |
| Educa → Pre-Session Prep (materials, objectives, equipment …) | |
| """ | |
| items: Dict[str, PhaseItemStatus] = Field(default_factory=dict) | |
| critical_items: List[str] = Field(default_factory=list) | |
| last_updated: Optional[datetime] = None | |
| updated_by: Optional[str] = None | |
| # ── queries ── | |
| def is_ready(self) -> bool: | |
| """All critical items must be in a passing state.""" | |
| for key in self.critical_items: | |
| if self.items.get(key, PhaseItemStatus.NOT_STARTED) not in _PASS_STATES: | |
| return False | |
| return True | |
| def readiness_pct(self) -> int: | |
| """Percentage of ALL items in a passing state (0-100).""" | |
| if not self.items: | |
| return 0 | |
| passed = sum(1 for v in self.items.values() if v in _PASS_STATES) | |
| return int(passed / len(self.items) * 100) | |
| def pending_items(self) -> List[str]: | |
| """Return keys of items not yet in a passing state.""" | |
| return [k for k, v in self.items.items() if v not in _PASS_STATES] | |
| # ─── 2. Event Timeline ────────────────────────────────────────────────────── | |
| class TimelineEventEntry(BaseModel): | |
| """ | |
| Single timestamped event during the active phase of a case. | |
| Works for: | |
| Surgio → Intra-op milestones (incision, closure, PACU …) | |
| Insura → Claims processing steps (review, adjudication …) | |
| Movio → Trip milestones (pickup, checkpoint, delivery …) | |
| Stay → Stay events (check-in, room service, maintenance …) | |
| Educa → Session milestones (start, break, assessment, end …) | |
| """ | |
| event_type: str # from config milestone_types | |
| timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) | |
| recorded_by: Optional[str] = None | |
| notes: Optional[str] = None | |
| numeric_value: Optional[float] = None # e.g. EBL ml, distance km | |
| numeric_label: Optional[str] = None # e.g. "EBL (ml)" | |
| # ─── 3. Post-Event Completion ──────────────────────────────────────────────── | |
| class CompletionBarrierStatus(str, Enum): | |
| """Status of a barrier to case completion.""" | |
| ACTIVE = "active" | |
| RESOLVED = "resolved" | |
| DEFERRED = "deferred" | |
| class CompletionBarrier(BaseModel): | |
| """A single barrier blocking case completion.""" | |
| barrier_type: str # from config barrier_types | |
| description: str | |
| responsible_party: Optional[str] = None | |
| status: CompletionBarrierStatus = CompletionBarrierStatus.ACTIVE | |
| created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) | |
| resolved_at: Optional[datetime] = None | |
| class FollowUpItem(BaseModel): | |
| """A scheduled follow-up action after the case.""" | |
| item_type: str # from config follow_up_types | |
| target_date: Optional[datetime] = None | |
| provider: Optional[str] = None | |
| status: str = "pending" # pending|scheduled|completed|cancelled | |
| notes: Optional[str] = None | |
| class CompletionPlan(BaseModel): | |
| """ | |
| Domain-agnostic post-event completion / discharge plan. | |
| Works for: | |
| Surgio → Discharge Plan (home, SNF, rehab …) | |
| Insura → Settlement Plan (payout, denial appeal, escalation …) | |
| Movio → Delivery Confirmation (completed, returned, rerouted …) | |
| Stay → Checkout Plan (express, late, extended …) | |
| Educa → Assessment/Completion (passed, remediation, certificate …) | |
| """ | |
| disposition: str = "" # from config disposition_options | |
| target_date: Optional[datetime] = None | |
| actual_date: Optional[datetime] = None | |
| barriers: List[CompletionBarrier] = Field(default_factory=list) | |
| follow_ups: List[FollowUpItem] = Field(default_factory=list) | |
| instructions: Optional[str] = None | |
| completed_by: Optional[str] = None | |
| def active_barriers(self) -> List[CompletionBarrier]: | |
| return [b for b in self.barriers if b.status == CompletionBarrierStatus.ACTIVE] | |
| def is_ready(self) -> bool: | |
| return len(self.active_barriers()) == 0 | |