Core modules: - Laws: CRUD, search, AI-powered QA - Analysis: legal research and case management - Contracts: lifecycle management with templates - Signatures: electronic signature workflow Infrastructure: - FastAPI + SQLite + async SQLAlchemy - Docker deployment support - 54 unit tests passing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
"""Analysis model for legal research."""
|
|
import enum
|
|
from datetime import date, datetime
|
|
from typing import Optional, List
|
|
|
|
from sqlalchemy import String, Text, Date, DateTime, Enum as SQLEnum, Integer, ForeignKey, JSON
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class AnalysisStatus(str, enum.Enum):
|
|
"""Analysis status enumeration."""
|
|
DRAFT = "draft"
|
|
IN_PROGRESS = "in_progress"
|
|
COMPLETED = "completed"
|
|
|
|
|
|
class LegalAnalysis(Base):
|
|
"""Legal analysis model."""
|
|
|
|
__tablename__ = "legal_analyses"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
|
|
title: Mapped[str] = mapped_column(String(200))
|
|
case_description: Mapped[str] = mapped_column(Text)
|
|
legal_basis: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
|
|
analysis_content: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
conclusion: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
status: Mapped[AnalysisStatus] = mapped_column(
|
|
SQLEnum(AnalysisStatus),
|
|
default=AnalysisStatus.DRAFT
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
|
|
def __init__(
|
|
self,
|
|
user_id: int,
|
|
title: str,
|
|
case_description: str,
|
|
legal_basis: Optional[dict] = None,
|
|
analysis_content: Optional[str] = None,
|
|
conclusion: Optional[str] = None,
|
|
status: AnalysisStatus = AnalysisStatus.DRAFT,
|
|
**kwargs
|
|
):
|
|
self.user_id = user_id
|
|
self.title = title
|
|
self.case_description = case_description
|
|
self.legal_basis = legal_basis
|
|
self.analysis_content = analysis_content
|
|
self.conclusion = conclusion
|
|
self.status = status
|
|
self.created_at = datetime.utcnow()
|
|
self.updated_at = datetime.utcnow()
|
|
|
|
|
|
class Case(Base):
|
|
"""Case model for case database."""
|
|
|
|
__tablename__ = "cases"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
title: Mapped[str] = mapped_column(String(200), index=True)
|
|
case_number: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
|
|
court: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
|
case_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
|
judgment_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
|
facts: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
judgment: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
reasoning: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
|
|
def __init__(
|
|
self,
|
|
title: str,
|
|
case_number: Optional[str] = None,
|
|
court: Optional[str] = None,
|
|
case_type: Optional[str] = None,
|
|
judgment_date: Optional[date] = None,
|
|
facts: Optional[str] = None,
|
|
judgment: Optional[str] = None,
|
|
reasoning: Optional[str] = None,
|
|
**kwargs
|
|
):
|
|
self.title = title
|
|
self.case_number = case_number
|
|
self.court = court
|
|
self.case_type = case_type
|
|
self.judgment_date = judgment_date
|
|
self.facts = facts
|
|
self.judgment = judgment
|
|
self.reasoning = reasoning
|
|
self.created_at = datetime.utcnow()
|