feat(contratos): tabla de contratos con tipo_usuario por contrato

Agrega tabla `contratos` en SQLite sembrada con los 17 contratos del
laboratorio. `generar_rda_paciente` consulta el mapa contrato→tipoUsuario
como primera prioridad antes de derivar de TIPOUSU/TIPOUSUSISPRO.
Incluye CRUD en /contratos con UI en sidebar.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-09 15:00:21 -05:00
co-authored by Claude Sonnet 4.6
parent 7d2a9df447
commit 0f3a760de4
8 changed files with 337 additions and 12 deletions
+13
View File
@@ -21,6 +21,19 @@ def _migrate(conn):
conn.execute("ALTER TABLE envios ADD COLUMN contrato TEXT")
if "mensaje_tns" not in cols:
conn.execute("ALTER TABLE envios ADD COLUMN mensaje_tns TEXT")
tables = {r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
if "contratos" not in tables:
conn.execute("""
CREATE TABLE contratos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
numero_contrato TEXT UNIQUE NOT NULL,
nit_empresa TEXT NOT NULL DEFAULT '',
tipo_usuario TEXT NOT NULL,
descripcion TEXT NOT NULL DEFAULT '',
created_at TEXT NOT NULL DEFAULT (datetime('now'))
)
""")
conn.commit()