Download src/core/tools/privatepractice/models.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 8.71 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/tools/privatepractice/models.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/core/tools/privatepractice/models.py
-
curl -L -o models.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/tools/privatepractice/models.py
8.71 kB
| """ | |
| Private Practice Tool - Domain Models | |
| ========================================== | |
| Structured private surgery cashflow management: elective pipeline, | |
| auto follow-up scheduling, CR tracking, and revenue analytics. | |
| Entities: | |
| ElectiveCase - Planned private surgery pipeline entry | |
| FollowUpTask - Auto-generated post-op follow-up | |
| CRTracker - Compte-rendu (operative report) tracker | |
| CashflowEntry - Revenue/cost per procedure | |
| PracticeEvent - Hash-chained audit trail | |
| Enums: | |
| PipelineStage, FollowUpDay, CRStatus, PracticeEventType | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass, field | |
| from datetime import datetime, timezone | |
| from enum import Enum | |
| from typing import Any, Dict, List, Optional | |
| from uuid import UUID, uuid4 | |
| from pydantic import BaseModel, Field | |
| # ============================================================================ | |
| # ENUMS | |
| # ============================================================================ | |
| class PipelineStage(str, Enum): | |
| CONSULTATION = "consultation" | |
| BILAN_COMPLETE = "bilan_complete" | |
| SCHEDULED = "scheduled" | |
| OPERATED = "operated" | |
| FOLLOW_UP = "follow_up" | |
| COMPLETED = "completed" | |
| CANCELLED = "cancelled" | |
| class FollowUpDay(str, Enum): | |
| J1 = "J1" | |
| J3 = "J3" | |
| J7 = "J7" | |
| J14 = "J14" | |
| J30 = "J30" | |
| J90 = "J90" | |
| CUSTOM = "custom" | |
| class FollowUpStatus(str, Enum): | |
| PENDING = "pending" | |
| COMPLETED = "completed" | |
| RED_FLAG = "red_flag" | |
| MISSED = "missed" | |
| class CRStatus(str, Enum): | |
| NOT_STARTED = "not_started" | |
| DRAFT = "draft" | |
| SENT = "sent" | |
| OVERDUE = "overdue" | |
| class RedFlagType(str, Enum): | |
| FEVER = "fever" | |
| WOUND_INFECTION = "wound_infection" | |
| BLEEDING = "bleeding" | |
| PAIN_UNCONTROLLED = "pain_uncontrolled" | |
| NAUSEA_VOMITING = "nausea_vomiting" | |
| INABILITY_TO_EAT = "inability_to_eat" | |
| URINARY_RETENTION = "urinary_retention" | |
| OTHER = "other" | |
| class PracticeEventType(str, Enum): | |
| CASE_ADDED = "case_added" | |
| STAGE_CHANGED = "stage_changed" | |
| FOLLOWUP_CREATED = "followup_created" | |
| FOLLOWUP_COMPLETED = "followup_completed" | |
| RED_FLAG_RAISED = "red_flag_raised" | |
| CR_TRACKED = "cr_tracked" | |
| CR_SENT = "cr_sent" | |
| REVENUE_LOGGED = "revenue_logged" | |
| # ============================================================================ | |
| # ENTITIES | |
| # ============================================================================ | |
| class ElectiveCase: | |
| """Private surgery pipeline entry.""" | |
| id: UUID = field(default_factory=uuid4) | |
| tenant_id: UUID = field(default_factory=uuid4) | |
| created_by: UUID = field(default_factory=uuid4) | |
| patient_id: Optional[UUID] = None | |
| procedure_name: str = "" | |
| procedure_category: str = "" # hernia, cholecystectomy, eventration | |
| stage: PipelineStage = PipelineStage.CONSULTATION | |
| priority: str = "routine" # routine, semi-urgent | |
| # Dates | |
| consultation_date: Optional[datetime] = None | |
| bilan_complete_date: Optional[datetime] = None | |
| scheduled_date: Optional[datetime] = None | |
| operated_date: Optional[datetime] = None | |
| completed_date: Optional[datetime] = None | |
| # Clinical | |
| asa_class: str = "II" | |
| referring_physician: str = "" | |
| notes: str = "" | |
| estimated_revenue: float = 0.0 | |
| created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| class FollowUpTask: | |
| """Auto-generated post-operative follow-up task.""" | |
| id: UUID = field(default_factory=uuid4) | |
| tenant_id: UUID = field(default_factory=uuid4) | |
| created_by: UUID = field(default_factory=uuid4) | |
| case_id: Optional[UUID] = None | |
| patient_id: Optional[UUID] = None | |
| follow_up_day: FollowUpDay = FollowUpDay.J1 | |
| status: FollowUpStatus = FollowUpStatus.PENDING | |
| due_date: Optional[datetime] = None | |
| # Checklist items | |
| wound_ok: bool = True | |
| pain_controlled: bool = True | |
| eating_normally: bool = True | |
| no_fever: bool = True | |
| no_bleeding: bool = True | |
| drain_output_ok: bool = True | |
| # Red flags | |
| red_flags: List[RedFlagType] = field(default_factory=list) | |
| red_flag_notes: str = "" | |
| urgent_consult_needed: bool = False | |
| completed_at: Optional[datetime] = None | |
| created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| class CRTracker: | |
| """Compte-rendu (operative report) tracker with 24h deadline.""" | |
| id: UUID = field(default_factory=uuid4) | |
| tenant_id: UUID = field(default_factory=uuid4) | |
| created_by: UUID = field(default_factory=uuid4) | |
| case_id: Optional[UUID] = None | |
| procedure_name: str = "" | |
| referring_physician: str = "" | |
| status: CRStatus = CRStatus.NOT_STARTED | |
| deadline_hours: int = 24 | |
| operated_at: Optional[datetime] = None | |
| sent_at: Optional[datetime] = None | |
| delay_hours: Optional[float] = None | |
| is_overdue: bool = False | |
| created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| class CashflowEntry: | |
| """Revenue/cost per procedure for financial analytics.""" | |
| id: UUID = field(default_factory=uuid4) | |
| tenant_id: UUID = field(default_factory=uuid4) | |
| created_by: UUID = field(default_factory=uuid4) | |
| case_id: Optional[UUID] = None | |
| procedure_name: str = "" | |
| procedure_category: str = "" | |
| revenue: float = 0.0 | |
| costs: float = 0.0 | |
| net_income: float = 0.0 | |
| payment_received: bool = False | |
| complications: List[str] = field(default_factory=list) | |
| scheduling_delay_days: int = 0 | |
| created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| class PracticeEvent: | |
| """Hash-chained private practice audit event.""" | |
| id: UUID = field(default_factory=uuid4) | |
| tenant_id: UUID = field(default_factory=uuid4) | |
| event_type: PracticeEventType = PracticeEventType.CASE_ADDED | |
| entity_id: UUID = field(default_factory=uuid4) | |
| user_id: UUID = field(default_factory=uuid4) | |
| data: Dict[str, Any] = field(default_factory=dict) | |
| occurred_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| hash: str = "" | |
| prev_hash: str = "" | |
| # ============================================================================ | |
| # PYDANTIC SCHEMAS | |
| # ============================================================================ | |
| class ElectiveCaseCreate(BaseModel): | |
| procedure_name: str = Field(..., min_length=1, max_length=300) | |
| procedure_category: str = "" | |
| priority: str = "routine" | |
| asa_class: str = "II" | |
| referring_physician: str = "" | |
| notes: str = "" | |
| estimated_revenue: float = 0.0 | |
| patient_id: Optional[str] = None | |
| class ElectiveCaseStageUpdate(BaseModel): | |
| stage: str | |
| class FollowUpTaskCreate(BaseModel): | |
| case_id: Optional[str] = None | |
| patient_id: Optional[str] = None | |
| follow_up_day: str = "J1" | |
| class FollowUpTaskComplete(BaseModel): | |
| wound_ok: bool = True | |
| pain_controlled: bool = True | |
| eating_normally: bool = True | |
| no_fever: bool = True | |
| no_bleeding: bool = True | |
| drain_output_ok: bool = True | |
| red_flags: List[str] = [] | |
| red_flag_notes: str = "" | |
| class CRTrackerCreate(BaseModel): | |
| procedure_name: str = "" | |
| referring_physician: str = "" | |
| case_id: Optional[str] = None | |
| class CRTrackerSend(BaseModel): | |
| pass | |
| class CashflowEntryCreate(BaseModel): | |
| procedure_name: str = "" | |
| procedure_category: str = "" | |
| revenue: float = 0.0 | |
| costs: float = 0.0 | |
| complications: List[str] = [] | |
| scheduling_delay_days: int = 0 | |
| case_id: Optional[str] = None | |
| class ElectiveCaseResponse(BaseModel): | |
| id: str | |
| procedure_name: str | |
| procedure_category: str | |
| stage: str | |
| asa_class: str | |
| referring_physician: str | |
| estimated_revenue: float | |
| created_at: str | |
| class FollowUpTaskResponse(BaseModel): | |
| id: str | |
| follow_up_day: str | |
| status: str | |
| red_flags: List[str] | |
| urgent_consult_needed: bool | |
| created_at: str | |
| class CRTrackerResponse(BaseModel): | |
| id: str | |
| procedure_name: str | |
| status: str | |
| is_overdue: bool | |
| delay_hours: Optional[float] | |
| created_at: str | |
| class CashflowEntryResponse(BaseModel): | |
| id: str | |
| procedure_name: str | |
| procedure_category: str | |
| revenue: float | |
| costs: float | |
| net_income: float | |
| payment_received: bool | |
| created_at: str | |
| class PracticeStatsResponse(BaseModel): | |
| pipeline_total: int | |
| pipeline_by_stage: Dict[str, int] | |
| followups_pending: int | |
| followups_red_flags: int | |
| cr_overdue: int | |
| total_revenue: float | |
| total_costs: float | |
| net_income: float | |
| avg_scheduling_delay_days: float | |
| events: int | |