- Transacción: tabla con estado Enviado/Pendiente/Error por IDRECEPCION, botón enviar fila a fila o masivo, modal con JSON + respuesta TNS por registro
- Historial: filtros por fecha, tipo, IDRECEPCION/contrato; paginación 50 por página; modal con 3 tabs (JSON enviado / Respuesta TNS / Mensaje)
- DB: migración automática para agregar columnas idrecepcion, contrato, mensaje_tns a tabla envios
- Logs route: nuevo endpoint /logs/detalle/{id} para cargar detalle completo vía JS
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
import sqlite3
|
|
import os
|
|
from datetime import datetime
|
|
|
|
DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "rips_manager.db")
|
|
|
|
|
|
def get_connection():
|
|
conn = sqlite3.connect(DB_PATH)
|
|
conn.row_factory = sqlite3.Row
|
|
conn.execute("PRAGMA journal_mode=WAL")
|
|
conn.execute("PRAGMA foreign_keys=ON")
|
|
return conn
|
|
|
|
|
|
def _migrate(conn):
|
|
cols = {r[1] for r in conn.execute("PRAGMA table_info(envios)")}
|
|
if "idrecepcion" not in cols:
|
|
conn.execute("ALTER TABLE envios ADD COLUMN idrecepcion INTEGER")
|
|
if "contrato" not in cols:
|
|
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")
|
|
conn.commit()
|
|
|
|
|
|
def init_db():
|
|
conn = get_connection()
|
|
conn.executescript("""
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
username TEXT UNIQUE NOT NULL,
|
|
email TEXT UNIQUE NOT NULL,
|
|
password_hash TEXT NOT NULL,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS config (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
key TEXT UNIQUE NOT NULL,
|
|
value TEXT
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS queries (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
query_type TEXT NOT NULL CHECK(query_type IN ('terceros','transaccion')),
|
|
query_text TEXT NOT NULL,
|
|
description TEXT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS rda_test_log (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
idrecepcion INTEGER NOT NULL,
|
|
factura TEXT,
|
|
contrato TEXT,
|
|
ok INTEGER NOT NULL DEFAULT 0,
|
|
mensaje TEXT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS envios (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
user_id INTEGER,
|
|
tipo TEXT NOT NULL CHECK(tipo IN ('terceros','transaccion')),
|
|
factura TEXT,
|
|
fecha_inicio TEXT,
|
|
fecha_fin TEXT,
|
|
pacientes_count INTEGER DEFAULT 0,
|
|
servicios_count INTEGER DEFAULT 0,
|
|
status TEXT NOT NULL DEFAULT 'pendiente',
|
|
json_enviado TEXT,
|
|
respuesta_api TEXT,
|
|
codigo_cuv TEXT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
);
|
|
""")
|
|
conn.commit()
|
|
_migrate(conn)
|
|
conn.close()
|