"""Added initial table

Revision ID: 6fb445db4fde
Revises: 
Create Date: 2020-12-23 15:50:53.675726

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '6fb445db4fde'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('patient',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('source_id', sa.String(length=255), nullable=False),
    sa.Column('birth_date', sa.Date(), nullable=True),
    sa.Column('gender', sa.String(length=255), nullable=True),
    sa.Column('race_code', sa.String(length=255), nullable=True),
    sa.Column('race_code_system', sa.String(length=255), nullable=True),
    sa.Column('ethnicity_code', sa.String(length=255), nullable=True),
    sa.Column('ethnicity_code_system', sa.String(length=255), nullable=True),
    sa.Column('country', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('encounter',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('source_id', sa.String(length=255), nullable=False),
    sa.Column('patient_id', sa.Integer(), nullable=False),
    sa.Column('start_date', sa.DateTime(), nullable=False),
    sa.Column('end_date', sa.DateTime(), nullable=False),
    sa.Column('type_code', sa.String(length=255), nullable=True),
    sa.Column('type_code_system', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['patient_id'], ['patient.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('observation',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('source_id', sa.String(length=255), nullable=False),
    sa.Column('patient_id', sa.Integer(), nullable=False),
    sa.Column('encounter_id', sa.Integer(), nullable=True),
    sa.Column('observation_date', sa.Date(), nullable=True),
    sa.Column('type_code', sa.String(length=255), nullable=False),
    sa.Column('type_code_system', sa.String(length=255), nullable=False),
    sa.Column('value', sa.Float(), nullable=False),
    sa.Column('unit_code', sa.String(length=255), nullable=True),
    sa.Column('unit_code_system', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['encounter_id'], ['encounter.id'], ),
    sa.ForeignKeyConstraint(['patient_id'], ['patient.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('procedure',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('source_id', sa.String(length=255), nullable=False),
    sa.Column('patient_id', sa.Integer(), nullable=False),
    sa.Column('encounter_id', sa.Integer(), nullable=True),
    sa.Column('procedure_date', sa.DateTime(), nullable=False),
    sa.Column('type_code', sa.String(length=255), nullable=False),
    sa.Column('type_code_system', sa.String(length=255), nullable=False),
    sa.ForeignKeyConstraint(['encounter_id'], ['encounter.id'], ),
    sa.ForeignKeyConstraint(['patient_id'], ['patient.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('procedure')
    op.drop_table('observation')
    op.drop_table('encounter')
    op.drop_table('patient')
    # ### end Alembic commands ###
