119 lines
4.7 KiB
Python
119 lines
4.7 KiB
Python
"""
|
|
QDRO models based on legacy QDRO.SC analysis
|
|
"""
|
|
from sqlalchemy import Column, Integer, String, Date, Text, ForeignKey, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.models.base import BaseModel
|
|
|
|
|
|
class QDRO(BaseModel):
|
|
"""
|
|
Legal documents (QDROs - Qualified Domestic Relations Orders)
|
|
Corresponds to QDROS table in legacy system
|
|
"""
|
|
__tablename__ = "qdros"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
file_no = Column(String(45), ForeignKey("files.file_no"), nullable=False)
|
|
version = Column(String(10), default="01") # Version of QDRO (current working version)
|
|
plan_id = Column(String(45)) # Plan identifier (links to PlanInfo.plan_id)
|
|
|
|
# Timestamps (explicit created_at for sort consistency across APIs)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# CSV fields from legacy system
|
|
field1 = Column(String(100)) # ^1 field
|
|
field2 = Column(String(100)) # ^2 field
|
|
part = Column(String(100)) # ^Part field
|
|
altp = Column(String(100)) # ^AltP field
|
|
pet = Column(String(100)) # ^Pet field (Petitioner)
|
|
res = Column(String(100)) # ^Res field (Respondent)
|
|
|
|
# Case information
|
|
case_type = Column(String(45)) # Case type
|
|
case_code = Column(String(45)) # Case code
|
|
section = Column(String(45)) # Court section
|
|
case_number = Column(String(100)) # Case number
|
|
|
|
# Dates
|
|
judgment_date = Column(Date) # Judgment date
|
|
valuation_date = Column(Date) # Valuation date
|
|
married_on = Column(Date) # Marriage date
|
|
|
|
# Award information
|
|
percent_awarded = Column(String(100)) # Percent awarded (can be formula)
|
|
|
|
# Venue information
|
|
ven_city = Column(String(50)) # Venue city
|
|
ven_cnty = Column(String(50)) # Venue county
|
|
ven_st = Column(String(2)) # Venue state
|
|
|
|
# Document status dates
|
|
draft_out = Column(Date) # Draft sent out date
|
|
draft_apr = Column(Date) # Draft approved date
|
|
final_out = Column(Date) # Final sent out date
|
|
|
|
# Court information
|
|
judge = Column(String(100)) # Judge name
|
|
form_name = Column(String(200)) # Form/template name
|
|
|
|
# Additional fields
|
|
status = Column(String(45), default="DRAFT") # DRAFT, APPROVAL_PENDING, APPROVED, FILED, etc.
|
|
content = Column(Text) # Document content/template
|
|
notes = Column(Text) # Additional notes
|
|
|
|
# Court/cycle tracking (idempotent schema updater will add when missing)
|
|
approval_status = Column(String(45)) # Workflow status if different granularity is needed
|
|
approved_date = Column(Date)
|
|
filed_date = Column(Date)
|
|
|
|
# Relationships
|
|
file = relationship("File", back_populates="qdros")
|
|
versions = relationship("QDROVersion", back_populates="qdro", cascade="all, delete-orphan")
|
|
communications = relationship("QDROCommunication", back_populates="qdro", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<QDRO(file_no='{self.file_no}', version='{self.version}', case_number='{self.case_number}')>"
|
|
|
|
|
|
class QDROVersion(BaseModel):
|
|
"""
|
|
Immutable snapshot of a QDRO at a point in time for version tracking.
|
|
"""
|
|
__tablename__ = "qdro_versions"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
qdro_id = Column(Integer, ForeignKey("qdros.id"), nullable=False, index=True)
|
|
version_label = Column(String(20), nullable=False, default="01")
|
|
status = Column(String(45), default="DRAFT")
|
|
content = Column(Text)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
qdro = relationship("QDRO", back_populates="versions")
|
|
|
|
def __repr__(self):
|
|
return f"<QDROVersion(qdro_id={self.qdro_id}, version='{self.version_label}', status='{self.status}')>"
|
|
|
|
|
|
class QDROCommunication(BaseModel):
|
|
"""
|
|
Track communications with plan administrators or other parties regarding a QDRO.
|
|
"""
|
|
__tablename__ = "qdro_communications"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
qdro_id = Column(Integer, ForeignKey("qdros.id"), nullable=False, index=True)
|
|
channel = Column(String(20)) # email | phone | letter | fax | portal
|
|
subject = Column(String(200))
|
|
message = Column(Text)
|
|
contact_name = Column(String(100))
|
|
contact_email = Column(String(200))
|
|
contact_phone = Column(String(50))
|
|
status = Column(String(45)) # sent | received | pending | escalated
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
qdro = relationship("QDRO", back_populates="communications")
|
|
|
|
def __repr__(self):
|
|
return f"<QDROCommunication(qdro_id={self.qdro_id}, channel='{self.channel}', subject='{self.subject}')>" |