Download src/core/workspaces/case_set.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 3.81 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/workspaces/case_set.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/core/workspaces/case_set.py
-
curl -L -o case_set.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/workspaces/case_set.py
3.81 kB
| """ | |
| Case Set — Work on multiple cases together. | |
| A CaseSet groups cases for cohort analysis, comparison, shared protocols, | |
| or team review sessions. Cases can belong to multiple sets. | |
| Use cases: | |
| - "All VBL cases this month" | |
| - "Hernia programme — scheduled for next week" | |
| - "High-risk cases requiring review" | |
| - "Complication follow-up cohort" | |
| - "Teaching set for residents" | |
| Security: tenant_id MANDATORY. PHI never logged. | |
| Performance: <200ms for set operations. | |
| """ | |
| from __future__ import annotations | |
| import enum | |
| import uuid | |
| from datetime import datetime, timezone | |
| from typing import Any, Dict, List, Optional | |
| from sqlalchemy import Column, DateTime, Index, Text | |
| from sqlalchemy.dialects.postgresql import JSON, UUID as PG_UUID | |
| from sqlmodel import Field, SQLModel | |
| from core.database.mixins import SoftDeleteMixin, TenantMixin, TimestampMixin | |
| UTC = timezone.utc | |
| class SetType(str, enum.Enum): | |
| COHORT = "cohort" | |
| PROGRAMME = "programme" | |
| REVIEW = "review" | |
| TEACHING = "teaching" | |
| RESEARCH = "research" | |
| AUDIT = "audit" | |
| CUSTOM = "custom" | |
| class CaseSet(TenantMixin, TimestampMixin, SoftDeleteMixin, SQLModel, table=True): | |
| """ | |
| A named group of cases for ensemble work. | |
| """ | |
| __tablename__ = "case_sets" | |
| __table_args__ = ( | |
| Index("ix_cs_tenant_slug", "tenant_id", "slug", unique=True), | |
| {"extend_existing": True}, | |
| ) | |
| id: uuid.UUID = Field( | |
| default_factory=uuid.uuid4, | |
| sa_column=Column(PG_UUID(as_uuid=True), primary_key=True, nullable=False), | |
| ) | |
| tenant_id: uuid.UUID = Field( | |
| sa_column=Column(PG_UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| slug: str = Field(max_length=100, nullable=False) | |
| name: str = Field(max_length=300, nullable=False) | |
| description: Optional[str] = Field(default=None, sa_column=Column(Text)) | |
| set_type: SetType = Field(default=SetType.CUSTOM) | |
| engine_slug: Optional[str] = Field(default=None, max_length=50) | |
| workspace_id: Optional[uuid.UUID] = Field( | |
| default=None, sa_column=Column(PG_UUID(as_uuid=True), index=True) | |
| ) | |
| owner_id: uuid.UUID = Field( | |
| sa_column=Column(PG_UUID(as_uuid=True), nullable=False), | |
| ) | |
| # Filters (saved query definition) | |
| filter_criteria: Optional[Dict[str, Any]] = Field( | |
| default=None, sa_column=Column(JSON) | |
| ) | |
| # Stats (denormalized for fast display) | |
| case_count: int = Field(default=0) | |
| icon: Optional[str] = Field(default=None, max_length=10) | |
| color: Optional[str] = Field(default=None, max_length=20) | |
| class CaseSetMember(TenantMixin, TimestampMixin, SQLModel, table=True): | |
| """ | |
| Links a case to a set. Cases can belong to multiple sets. | |
| """ | |
| __tablename__ = "case_set_members" | |
| __table_args__ = ( | |
| Index("ix_csm_set_case", "case_set_id", "case_id", unique=True), | |
| Index("ix_csm_tenant", "tenant_id"), | |
| {"extend_existing": True}, | |
| ) | |
| id: uuid.UUID = Field( | |
| default_factory=uuid.uuid4, | |
| sa_column=Column(PG_UUID(as_uuid=True), primary_key=True, nullable=False), | |
| ) | |
| tenant_id: uuid.UUID = Field( | |
| sa_column=Column(PG_UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| case_set_id: uuid.UUID = Field( | |
| sa_column=Column(PG_UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| case_id: uuid.UUID = Field( | |
| sa_column=Column(PG_UUID(as_uuid=True), nullable=False, index=True), | |
| ) | |
| added_by: uuid.UUID = Field( | |
| sa_column=Column(PG_UUID(as_uuid=True), nullable=False), | |
| ) | |
| added_at: datetime = Field( | |
| default_factory=lambda: datetime.now(UTC), | |
| sa_column=Column(DateTime(timezone=True), nullable=False), | |
| ) | |
| notes: Optional[str] = Field(default=None, max_length=500) | |
| sort_order: int = Field(default=0) | |