"""Initial database creation

Revision ID: 5a8610010b7b
Revises:
Create Date: 2025-06-15 18:38:18.575559

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "5a8610010b7b"
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "practitioners",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("specialty", sa.String(), nullable=False),
        sa.Column("practice", sa.String(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "users",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("username", sa.String(), nullable=False),
        sa.Column("email", sa.String(), nullable=False),
        sa.Column("password_hash", sa.String(), nullable=False),
        sa.Column("full_name", sa.String(), nullable=False),
        sa.Column("role", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("email"),
        sa.UniqueConstraint("username"),
    )
    op.create_table(
        "patients",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("first_name", sa.String(), nullable=False),
        sa.Column("last_name", sa.String(), nullable=False),
        sa.Column("birthDate", sa.Date(), nullable=False),
        sa.Column("physician_id", sa.Integer(), nullable=True),
        sa.Column("bloodType", sa.String(), nullable=True),
        sa.Column("height", sa.Integer(), nullable=True),
        sa.Column("weight", sa.Integer(), nullable=True),
        sa.Column("gender", sa.String(), nullable=True),
        sa.Column("address", sa.String(), nullable=True),
        sa.ForeignKeyConstraint(
            ["physician_id"],
            ["practitioners.id"],
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "allergies",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=False),
        sa.Column("allergen", sa.String(), nullable=False),
        sa.Column("reaction", sa.String(), nullable=False),
        sa.Column("severity", sa.String(), nullable=True),
        sa.Column("onset_date", sa.Date(), nullable=True),
        sa.Column("status", sa.String(), nullable=True),
        sa.Column("notes", sa.String(), nullable=True),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "conditions",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=False),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.Column("condition_name", sa.String(), nullable=True),
        sa.Column("diagnosis", sa.String(), nullable=False),
        sa.Column("notes", sa.String(), nullable=True),
        sa.Column("onsetDate", sa.Date(), nullable=True),
        sa.Column("status", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "encounters",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=True),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.Column("reason", sa.String(), nullable=False),
        sa.Column("date", sa.Date(), nullable=False),
        sa.Column("notes", sa.String(), nullable=True),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "immunizations",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=True),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.Column("vaccine_name", sa.String(), nullable=False),
        sa.Column("date_administered", sa.Date(), nullable=False),
        sa.Column("dose_number", sa.Integer(), nullable=True),
        sa.Column("lot_number", sa.String(), nullable=True),
        sa.Column("manufacturer", sa.String(), nullable=True),
        sa.Column("site", sa.String(), nullable=True),
        sa.Column("route", sa.String(), nullable=True),
        sa.Column("expiration_date", sa.Date(), nullable=True),
        sa.Column("notes", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "lab_results",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=False),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.Column("test_name", sa.String(), nullable=False),
        sa.Column("test_code", sa.String(), nullable=True),
        sa.Column("test_category", sa.String(), nullable=True),
        sa.Column("test_type", sa.String(), nullable=True),
        sa.Column("facility", sa.String(), nullable=True),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("ordered_date", sa.DateTime(), nullable=False),
        sa.Column("completed_date", sa.DateTime(), nullable=True),
        sa.Column("notes", sa.Text(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "medications",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("medication_name", sa.String(), nullable=False),
        sa.Column("dosage", sa.String(), nullable=True),
        sa.Column("frequency", sa.String(), nullable=True),
        sa.Column("route", sa.String(), nullable=True),
        sa.Column("indication", sa.String(), nullable=True),
        sa.Column("effectivePeriod_start", sa.Date(), nullable=True),
        sa.Column("effectivePeriod_end", sa.Date(), nullable=True),
        sa.Column("status", sa.String(), nullable=True),
        sa.Column("patient_id", sa.Integer(), nullable=False),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "procedures",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=False),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.Column("procedure_name", sa.String(), nullable=False),
        sa.Column("code", sa.String(), nullable=True),
        sa.Column("date", sa.Date(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("status", sa.String(), nullable=True),
        sa.Column("notes", sa.String(), nullable=True),
        sa.Column("facility", sa.String(), nullable=True),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "lab_result_files",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("lab_result_id", sa.Integer(), nullable=True),
        sa.Column("file_name", sa.String(), nullable=False),
        sa.Column("file_path", sa.String(), nullable=False),
        sa.Column("file_type", sa.String(), nullable=False),
        sa.Column("file_size", sa.Integer(), nullable=True),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("uploaded_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["lab_result_id"],
            ["lab_results.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "treatments",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("patient_id", sa.Integer(), nullable=False),
        sa.Column("practitioner_id", sa.Integer(), nullable=True),
        sa.Column("condition_id", sa.Integer(), nullable=True),
        sa.Column("treatment_name", sa.String(), nullable=False),
        sa.Column("treatment_type", sa.String(), nullable=False),
        sa.Column("start_date", sa.Date(), nullable=False),
        sa.Column("end_date", sa.Date(), nullable=True),
        sa.Column("status", sa.String(), nullable=True),
        sa.Column("treatment_category", sa.String(), nullable=True),
        sa.Column("notes", sa.String(), nullable=True),
        sa.Column("frequency", sa.String(), nullable=True),
        sa.Column("outcome", sa.String(), nullable=True),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("location", sa.String(), nullable=True),
        sa.ForeignKeyConstraint(
            ["condition_id"],
            ["conditions.id"],
        ),
        sa.ForeignKeyConstraint(
            ["patient_id"],
            ["patients.id"],
        ),
        sa.ForeignKeyConstraint(
            ["practitioner_id"],
            ["practitioners.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("treatments")
    op.drop_table("lab_result_files")
    op.drop_table("procedures")
    op.drop_table("medications")
    op.drop_table("lab_results")
    op.drop_table("immunizations")
    op.drop_table("encounters")
    op.drop_table("conditions")
    op.drop_table("allergies")
    op.drop_table("patients")
    op.drop_table("users")
    op.drop_table("practitioners")
    # ### end Alembic commands ###
