3f1925b775
evaluacion_riesgo.fecha_indice: the decision point the model scored the patient from, which the horizons count from (the model defines it, not the cohort member). Migrations for CaCu, CaMa and TEA add it, fill existing risks with their member's index date in the batch's build, and make it required. save_batch takes (pac_id, fecha_indice, horizonte, probabilidad, ic_bajo, ic_alto) and refuses a risk with no date or two dates for one patient; change_state keeps it; current_risk returns it and the batch's outcome. The risk-band measure dates each row by the estimate's index date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
"""risk index date
|
|
|
|
Each risk keeps the index date the model scored the patient from (`evaluacion_riesgo.fecha_indice`): the model
|
|
defines its decision point, which needn't be the cohort member's. Existing risks take their member's index date in
|
|
the batch's build, the one their horizons were counted from; then the column is required.
|
|
|
|
Revision ID: c3f6a9e42d53
|
|
Revises: c4306f438b3a
|
|
Create Date: 2026-11-20 21:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'c3f6a9e42d53'
|
|
down_revision = 'c4306f438b3a'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
with op.batch_alter_table('evaluacion_riesgo', schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column('fecha_indice', sa.Date(), nullable=True))
|
|
op.execute(
|
|
"UPDATE evaluacion_riesgo SET fecha_indice = (SELECT m.fecha_indice FROM cohorte_miembro m "
|
|
"JOIN evaluacion_riesgo_lote l ON l.armado_id = m.armado_id "
|
|
"WHERE l.lote_id = evaluacion_riesgo.lote_id AND m.pac_id = evaluacion_riesgo.pac_id)"
|
|
)
|
|
with op.batch_alter_table('evaluacion_riesgo', schema=None) as batch_op:
|
|
batch_op.alter_column('fecha_indice', existing_type=sa.Date(), nullable=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table('evaluacion_riesgo', schema=None) as batch_op:
|
|
batch_op.drop_column('fecha_indice')
|
|
|