"""Initial schema with all tables

Revision ID: 8ea1f9d0a13b
Revises: 
Create Date: 2026-02-10 16:47:05.255764

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '8ea1f9d0a13b'
down_revision: Union[str, None] = None
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('referentiel_versions',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('type', sa.String(length=20), nullable=False),
    sa.Column('version', sa.String(length=50), nullable=False),
    sa.Column('import_date', sa.DateTime(), nullable=False),
    sa.Column('file_hash', sa.String(length=64), nullable=False),
    sa.Column('chunk_count', sa.Integer(), nullable=False),
    sa.Column('index_hash', sa.String(length=64), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('file_hash'),
    sa.UniqueConstraint('type', 'version', name='uq_referentiel_type_version')
    )
    op.create_index('idx_referentiel_active', 'referentiel_versions', ['active'], unique=False)
    op.create_index('idx_referentiel_type', 'referentiel_versions', ['type'], unique=False)
    op.create_index('idx_referentiel_version', 'referentiel_versions', ['version'], unique=False)
    op.create_index(op.f('ix_referentiel_versions_active'), 'referentiel_versions', ['active'], unique=False)
    op.create_index(op.f('ix_referentiel_versions_type'), 'referentiel_versions', ['type'], unique=False)
    op.create_index(op.f('ix_referentiel_versions_version'), 'referentiel_versions', ['version'], unique=False)
    op.create_table('stays',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('stay_id', sa.String(length=100), nullable=False),
    sa.Column('admission_date', sa.DateTime(), nullable=False),
    sa.Column('discharge_date', sa.DateTime(), nullable=False),
    sa.Column('specialty', sa.String(length=100), nullable=False),
    sa.Column('unit', sa.String(length=100), nullable=True),
    sa.Column('age', sa.Integer(), nullable=True),
    sa.Column('sex', sa.String(length=1), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_stays_admission_date', 'stays', ['admission_date'], unique=False)
    op.create_index('idx_stays_specialty', 'stays', ['specialty'], unique=False)
    op.create_index(op.f('ix_stays_specialty'), 'stays', ['specialty'], unique=False)
    op.create_index(op.f('ix_stays_stay_id'), 'stays', ['stay_id'], unique=True)
    op.create_table('audit_records',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('record_id', sa.String(length=100), nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('event_type', sa.String(length=50), nullable=False),
    sa.Column('actor', sa.String(length=100), nullable=False),
    sa.Column('data', sa.JSON(), nullable=False),
    sa.Column('model_name', sa.String(length=100), nullable=False),
    sa.Column('model_digest', sa.String(length=64), nullable=False),
    sa.Column('prompt_version', sa.String(length=50), nullable=False),
    sa.Column('prompt_hash', sa.String(length=64), nullable=False),
    sa.Column('rules_version', sa.String(length=50), nullable=False),
    sa.Column('rules_hash', sa.String(length=64), nullable=False),
    sa.Column('groupage_version', sa.String(length=50), nullable=True),
    sa.Column('referentiels_versions', sa.JSON(), nullable=False),
    sa.Column('inference_params', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_audit_actor', 'audit_records', ['actor'], unique=False)
    op.create_index('idx_audit_event_type', 'audit_records', ['event_type'], unique=False)
    op.create_index('idx_audit_stay_id', 'audit_records', ['stay_id'], unique=False)
    op.create_index('idx_audit_timestamp', 'audit_records', ['timestamp'], unique=False)
    op.create_index(op.f('ix_audit_records_actor'), 'audit_records', ['actor'], unique=False)
    op.create_index(op.f('ix_audit_records_event_type'), 'audit_records', ['event_type'], unique=False)
    op.create_index(op.f('ix_audit_records_record_id'), 'audit_records', ['record_id'], unique=True)
    op.create_index(op.f('ix_audit_records_stay_id'), 'audit_records', ['stay_id'], unique=False)
    op.create_index(op.f('ix_audit_records_timestamp'), 'audit_records', ['timestamp'], unique=False)
    op.create_table('clinical_documents',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('document_id', sa.String(length=100), nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('document_type', sa.String(length=50), nullable=False),
    sa.Column('content', sa.Text(), nullable=False),
    sa.Column('creation_date', sa.DateTime(), nullable=False),
    sa.Column('author', sa.String(length=200), nullable=True),
    sa.Column('priority', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_documents_stay_id', 'clinical_documents', ['stay_id'], unique=False)
    op.create_index('idx_documents_type', 'clinical_documents', ['document_type'], unique=False)
    op.create_index(op.f('ix_clinical_documents_document_id'), 'clinical_documents', ['document_id'], unique=True)
    op.create_index(op.f('ix_clinical_documents_document_type'), 'clinical_documents', ['document_type'], unique=False)
    op.create_index(op.f('ix_clinical_documents_stay_id'), 'clinical_documents', ['stay_id'], unique=False)
    op.create_table('clinical_facts',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('fact_id', sa.String(length=100), nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('type', sa.String(length=50), nullable=False),
    sa.Column('text', sa.Text(), nullable=False),
    sa.Column('qualifier_certainty', sa.String(length=20), nullable=False),
    sa.Column('qualifier_markers', sa.JSON(), nullable=False),
    sa.Column('qualifier_confidence', sa.Float(), nullable=False),
    sa.Column('temporality', sa.String(length=20), nullable=False),
    sa.Column('confidence', sa.Float(), nullable=False),
    sa.Column('evidence_document_id', sa.String(length=100), nullable=False),
    sa.Column('evidence_span_start', sa.Integer(), nullable=False),
    sa.Column('evidence_span_end', sa.Integer(), nullable=False),
    sa.Column('evidence_text', sa.Text(), nullable=False),
    sa.Column('evidence_context', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_facts_certainty', 'clinical_facts', ['qualifier_certainty'], unique=False)
    op.create_index('idx_facts_stay_id', 'clinical_facts', ['stay_id'], unique=False)
    op.create_index('idx_facts_temporality', 'clinical_facts', ['temporality'], unique=False)
    op.create_index('idx_facts_type', 'clinical_facts', ['type'], unique=False)
    op.create_index(op.f('ix_clinical_facts_fact_id'), 'clinical_facts', ['fact_id'], unique=True)
    op.create_index(op.f('ix_clinical_facts_qualifier_certainty'), 'clinical_facts', ['qualifier_certainty'], unique=False)
    op.create_index(op.f('ix_clinical_facts_stay_id'), 'clinical_facts', ['stay_id'], unique=False)
    op.create_index(op.f('ix_clinical_facts_temporality'), 'clinical_facts', ['temporality'], unique=False)
    op.create_index(op.f('ix_clinical_facts_type'), 'clinical_facts', ['type'], unique=False)
    op.create_table('codes',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('code', sa.String(length=50), nullable=False),
    sa.Column('label', sa.String(length=500), nullable=False),
    sa.Column('type', sa.String(length=10), nullable=False),
    sa.Column('confidence', sa.Float(), nullable=False),
    sa.Column('reasoning', sa.Text(), nullable=False),
    sa.Column('referentiel_version', sa.String(length=50), nullable=False),
    sa.Column('status', sa.String(length=20), nullable=False),
    sa.Column('model_name', sa.String(length=100), nullable=False),
    sa.Column('model_digest', sa.String(length=64), nullable=False),
    sa.Column('prompt_version', sa.String(length=50), nullable=False),
    sa.Column('ccam_realization_date', sa.DateTime(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_codes_code', 'codes', ['code'], unique=False)
    op.create_index('idx_codes_referentiel_version', 'codes', ['referentiel_version'], unique=False)
    op.create_index('idx_codes_status', 'codes', ['status'], unique=False)
    op.create_index('idx_codes_stay_id', 'codes', ['stay_id'], unique=False)
    op.create_index('idx_codes_type', 'codes', ['type'], unique=False)
    op.create_index(op.f('ix_codes_code'), 'codes', ['code'], unique=False)
    op.create_index(op.f('ix_codes_referentiel_version'), 'codes', ['referentiel_version'], unique=False)
    op.create_index(op.f('ix_codes_status'), 'codes', ['status'], unique=False)
    op.create_index(op.f('ix_codes_stay_id'), 'codes', ['stay_id'], unique=False)
    op.create_index(op.f('ix_codes_type'), 'codes', ['type'], unique=False)
    op.create_table('groupage_results',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('ghm', sa.String(length=20), nullable=True),
    sa.Column('ghs', sa.String(length=20), nullable=True),
    sa.Column('groupage_errors', sa.JSON(), nullable=False),
    sa.Column('ccam_date_errors', sa.JSON(), nullable=False),
    sa.Column('groupage_version', sa.String(length=50), nullable=False),
    sa.Column('groupage_date', sa.DateTime(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_groupage_ghm', 'groupage_results', ['ghm'], unique=False)
    op.create_index('idx_groupage_stay_id', 'groupage_results', ['stay_id'], unique=False)
    op.create_index('idx_groupage_version', 'groupage_results', ['groupage_version'], unique=False)
    op.create_index(op.f('ix_groupage_results_ghm'), 'groupage_results', ['ghm'], unique=False)
    op.create_index(op.f('ix_groupage_results_ghs'), 'groupage_results', ['ghs'], unique=False)
    op.create_index(op.f('ix_groupage_results_groupage_version'), 'groupage_results', ['groupage_version'], unique=False)
    op.create_index(op.f('ix_groupage_results_stay_id'), 'groupage_results', ['stay_id'], unique=False)
    op.create_table('questions',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('question_id', sa.String(length=100), nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('text', sa.Text(), nullable=False),
    sa.Column('priority', sa.Integer(), nullable=False),
    sa.Column('category', sa.String(length=50), nullable=False),
    sa.Column('context', sa.Text(), nullable=False),
    sa.Column('suggested_answers', sa.JSON(), nullable=False),
    sa.Column('answered', sa.Boolean(), nullable=False),
    sa.Column('answer', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_questions_answered', 'questions', ['answered'], unique=False)
    op.create_index('idx_questions_priority', 'questions', ['priority'], unique=False)
    op.create_index('idx_questions_stay_id', 'questions', ['stay_id'], unique=False)
    op.create_index(op.f('ix_questions_answered'), 'questions', ['answered'], unique=False)
    op.create_index(op.f('ix_questions_category'), 'questions', ['category'], unique=False)
    op.create_index(op.f('ix_questions_priority'), 'questions', ['priority'], unique=False)
    op.create_index(op.f('ix_questions_question_id'), 'questions', ['question_id'], unique=True)
    op.create_index(op.f('ix_questions_stay_id'), 'questions', ['stay_id'], unique=False)
    op.create_table('validation_issues',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('issue_id', sa.String(length=100), nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('severity', sa.String(length=20), nullable=False),
    sa.Column('category', sa.String(length=50), nullable=False),
    sa.Column('message', sa.Text(), nullable=False),
    sa.Column('affected_codes', sa.JSON(), nullable=False),
    sa.Column('suggested_action', sa.Text(), nullable=False),
    sa.Column('resolved', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_issues_category', 'validation_issues', ['category'], unique=False)
    op.create_index('idx_issues_resolved', 'validation_issues', ['resolved'], unique=False)
    op.create_index('idx_issues_severity', 'validation_issues', ['severity'], unique=False)
    op.create_index('idx_issues_stay_id', 'validation_issues', ['stay_id'], unique=False)
    op.create_index(op.f('ix_validation_issues_category'), 'validation_issues', ['category'], unique=False)
    op.create_index(op.f('ix_validation_issues_issue_id'), 'validation_issues', ['issue_id'], unique=True)
    op.create_index(op.f('ix_validation_issues_resolved'), 'validation_issues', ['resolved'], unique=False)
    op.create_index(op.f('ix_validation_issues_severity'), 'validation_issues', ['severity'], unique=False)
    op.create_index(op.f('ix_validation_issues_stay_id'), 'validation_issues', ['stay_id'], unique=False)
    op.create_table('verification_results',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('stay_id', sa.Integer(), nullable=False),
    sa.Column('decision', sa.String(length=20), nullable=False),
    sa.Column('dim_errors', sa.JSON(), nullable=False),
    sa.Column('contradictions', sa.JSON(), nullable=False),
    sa.Column('alternatives', sa.JSON(), nullable=False),
    sa.Column('reasoning', sa.Text(), nullable=False),
    sa.Column('model_name', sa.String(length=100), nullable=False),
    sa.Column('model_digest', sa.String(length=64), nullable=False),
    sa.Column('prompt_version', sa.String(length=50), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['stay_id'], ['stays.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_verification_decision', 'verification_results', ['decision'], unique=False)
    op.create_index('idx_verification_stay_id', 'verification_results', ['stay_id'], unique=False)
    op.create_index(op.f('ix_verification_results_decision'), 'verification_results', ['decision'], unique=False)
    op.create_index(op.f('ix_verification_results_stay_id'), 'verification_results', ['stay_id'], unique=False)
    op.create_table('evidences',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('code_id', sa.Integer(), nullable=False),
    sa.Column('document_id', sa.Integer(), nullable=False),
    sa.Column('span_start', sa.Integer(), nullable=False),
    sa.Column('span_end', sa.Integer(), nullable=False),
    sa.Column('text', sa.Text(), nullable=False),
    sa.Column('context', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['code_id'], ['codes.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['document_id'], ['clinical_documents.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_evidences_code_id', 'evidences', ['code_id'], unique=False)
    op.create_index(op.f('ix_evidences_code_id'), 'evidences', ['code_id'], unique=False)
    op.create_table('tim_corrections',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('original_code_id', sa.Integer(), nullable=False),
    sa.Column('corrected_code', sa.String(length=50), nullable=False),
    sa.Column('corrected_label', sa.String(length=500), nullable=False),
    sa.Column('corrected_type', sa.String(length=10), nullable=False),
    sa.Column('user_id', sa.String(length=100), nullable=False),
    sa.Column('comment', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['original_code_id'], ['codes.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_corrections_original_code_id', 'tim_corrections', ['original_code_id'], unique=False)
    op.create_index('idx_corrections_timestamp', 'tim_corrections', ['timestamp'], unique=False)
    op.create_index('idx_corrections_user_id', 'tim_corrections', ['user_id'], unique=False)
    op.create_index(op.f('ix_tim_corrections_original_code_id'), 'tim_corrections', ['original_code_id'], unique=False)
    op.create_index(op.f('ix_tim_corrections_timestamp'), 'tim_corrections', ['timestamp'], unique=False)
    op.create_index(op.f('ix_tim_corrections_user_id'), 'tim_corrections', ['user_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_tim_corrections_user_id'), table_name='tim_corrections')
    op.drop_index(op.f('ix_tim_corrections_timestamp'), table_name='tim_corrections')
    op.drop_index(op.f('ix_tim_corrections_original_code_id'), table_name='tim_corrections')
    op.drop_index('idx_corrections_user_id', table_name='tim_corrections')
    op.drop_index('idx_corrections_timestamp', table_name='tim_corrections')
    op.drop_index('idx_corrections_original_code_id', table_name='tim_corrections')
    op.drop_table('tim_corrections')
    op.drop_index(op.f('ix_evidences_code_id'), table_name='evidences')
    op.drop_index('idx_evidences_code_id', table_name='evidences')
    op.drop_table('evidences')
    op.drop_index(op.f('ix_verification_results_stay_id'), table_name='verification_results')
    op.drop_index(op.f('ix_verification_results_decision'), table_name='verification_results')
    op.drop_index('idx_verification_stay_id', table_name='verification_results')
    op.drop_index('idx_verification_decision', table_name='verification_results')
    op.drop_table('verification_results')
    op.drop_index(op.f('ix_validation_issues_stay_id'), table_name='validation_issues')
    op.drop_index(op.f('ix_validation_issues_severity'), table_name='validation_issues')
    op.drop_index(op.f('ix_validation_issues_resolved'), table_name='validation_issues')
    op.drop_index(op.f('ix_validation_issues_issue_id'), table_name='validation_issues')
    op.drop_index(op.f('ix_validation_issues_category'), table_name='validation_issues')
    op.drop_index('idx_issues_stay_id', table_name='validation_issues')
    op.drop_index('idx_issues_severity', table_name='validation_issues')
    op.drop_index('idx_issues_resolved', table_name='validation_issues')
    op.drop_index('idx_issues_category', table_name='validation_issues')
    op.drop_table('validation_issues')
    op.drop_index(op.f('ix_questions_stay_id'), table_name='questions')
    op.drop_index(op.f('ix_questions_question_id'), table_name='questions')
    op.drop_index(op.f('ix_questions_priority'), table_name='questions')
    op.drop_index(op.f('ix_questions_category'), table_name='questions')
    op.drop_index(op.f('ix_questions_answered'), table_name='questions')
    op.drop_index('idx_questions_stay_id', table_name='questions')
    op.drop_index('idx_questions_priority', table_name='questions')
    op.drop_index('idx_questions_answered', table_name='questions')
    op.drop_table('questions')
    op.drop_index(op.f('ix_groupage_results_stay_id'), table_name='groupage_results')
    op.drop_index(op.f('ix_groupage_results_groupage_version'), table_name='groupage_results')
    op.drop_index(op.f('ix_groupage_results_ghs'), table_name='groupage_results')
    op.drop_index(op.f('ix_groupage_results_ghm'), table_name='groupage_results')
    op.drop_index('idx_groupage_version', table_name='groupage_results')
    op.drop_index('idx_groupage_stay_id', table_name='groupage_results')
    op.drop_index('idx_groupage_ghm', table_name='groupage_results')
    op.drop_table('groupage_results')
    op.drop_index(op.f('ix_codes_type'), table_name='codes')
    op.drop_index(op.f('ix_codes_stay_id'), table_name='codes')
    op.drop_index(op.f('ix_codes_status'), table_name='codes')
    op.drop_index(op.f('ix_codes_referentiel_version'), table_name='codes')
    op.drop_index(op.f('ix_codes_code'), table_name='codes')
    op.drop_index('idx_codes_type', table_name='codes')
    op.drop_index('idx_codes_stay_id', table_name='codes')
    op.drop_index('idx_codes_status', table_name='codes')
    op.drop_index('idx_codes_referentiel_version', table_name='codes')
    op.drop_index('idx_codes_code', table_name='codes')
    op.drop_table('codes')
    op.drop_index(op.f('ix_clinical_facts_type'), table_name='clinical_facts')
    op.drop_index(op.f('ix_clinical_facts_temporality'), table_name='clinical_facts')
    op.drop_index(op.f('ix_clinical_facts_stay_id'), table_name='clinical_facts')
    op.drop_index(op.f('ix_clinical_facts_qualifier_certainty'), table_name='clinical_facts')
    op.drop_index(op.f('ix_clinical_facts_fact_id'), table_name='clinical_facts')
    op.drop_index('idx_facts_type', table_name='clinical_facts')
    op.drop_index('idx_facts_temporality', table_name='clinical_facts')
    op.drop_index('idx_facts_stay_id', table_name='clinical_facts')
    op.drop_index('idx_facts_certainty', table_name='clinical_facts')
    op.drop_table('clinical_facts')
    op.drop_index(op.f('ix_clinical_documents_stay_id'), table_name='clinical_documents')
    op.drop_index(op.f('ix_clinical_documents_document_type'), table_name='clinical_documents')
    op.drop_index(op.f('ix_clinical_documents_document_id'), table_name='clinical_documents')
    op.drop_index('idx_documents_type', table_name='clinical_documents')
    op.drop_index('idx_documents_stay_id', table_name='clinical_documents')
    op.drop_table('clinical_documents')
    op.drop_index(op.f('ix_audit_records_timestamp'), table_name='audit_records')
    op.drop_index(op.f('ix_audit_records_stay_id'), table_name='audit_records')
    op.drop_index(op.f('ix_audit_records_record_id'), table_name='audit_records')
    op.drop_index(op.f('ix_audit_records_event_type'), table_name='audit_records')
    op.drop_index(op.f('ix_audit_records_actor'), table_name='audit_records')
    op.drop_index('idx_audit_timestamp', table_name='audit_records')
    op.drop_index('idx_audit_stay_id', table_name='audit_records')
    op.drop_index('idx_audit_event_type', table_name='audit_records')
    op.drop_index('idx_audit_actor', table_name='audit_records')
    op.drop_table('audit_records')
    op.drop_index(op.f('ix_stays_stay_id'), table_name='stays')
    op.drop_index(op.f('ix_stays_specialty'), table_name='stays')
    op.drop_index('idx_stays_specialty', table_name='stays')
    op.drop_index('idx_stays_admission_date', table_name='stays')
    op.drop_table('stays')
    op.drop_index(op.f('ix_referentiel_versions_version'), table_name='referentiel_versions')
    op.drop_index(op.f('ix_referentiel_versions_type'), table_name='referentiel_versions')
    op.drop_index(op.f('ix_referentiel_versions_active'), table_name='referentiel_versions')
    op.drop_index('idx_referentiel_version', table_name='referentiel_versions')
    op.drop_index('idx_referentiel_type', table_name='referentiel_versions')
    op.drop_index('idx_referentiel_active', table_name='referentiel_versions')
    op.drop_table('referentiel_versions')
    # ### end Alembic commands ###
