"""add_mdt_tables

Revision ID: e786650ede6f
Revises: f80dca5baa02
Create Date: 2026-07-08 16:38:12.221098
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa


revision: str = 'e786650ede6f'
down_revision: Union[str, None] = 'f80dca5baa02'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('mdt_cases',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('tenant_id', sa.Uuid(), nullable=False),
    sa.Column('title', sa.String(length=300), nullable=False),
    sa.Column('patient_summary', sa.Text(), nullable=False),
    sa.Column('cancer_type', sa.String(length=100), nullable=True),
    sa.Column('status', sa.String(length=20), nullable=False),
    sa.Column('created_by', sa.Uuid(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['created_by'], ['users.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('mdt_decisions',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('case_id', sa.Uuid(), nullable=False),
    sa.Column('conclusion', sa.Text(), nullable=False),
    sa.Column('meeting_date', sa.DateTime(timezone=True), nullable=True),
    sa.Column('participants', sa.JSON(), nullable=False),
    sa.Column('decided_by', sa.Uuid(), nullable=True),
    sa.Column('decided_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['case_id'], ['mdt_cases.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['decided_by'], ['users.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('mdt_evidence',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('case_id', sa.Uuid(), nullable=False),
    sa.Column('decision_id', sa.Uuid(), nullable=True),
    sa.Column('literature_id', sa.Uuid(), nullable=True),
    sa.Column('pmid', sa.Integer(), nullable=True),
    sa.Column('citation', sa.Text(), nullable=True),
    sa.Column('relevance_note', sa.Text(), nullable=True),
    sa.Column('added_by', sa.Uuid(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['added_by'], ['users.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['case_id'], ['mdt_cases.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['decision_id'], ['mdt_decisions.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['literature_id'], ['global_literature.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('mdt_evidence')
    op.drop_table('mdt_decisions')
    op.drop_table('mdt_cases')
    # ### end Alembic commands ###
