Commit Graph
65 Commits
Author SHA1 Message Date
Lizandro GuarnizoandClaude Sonnet 4.6 bdc0e244fc Fix NameError: mover autorizacion después de definir es_particular
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:28:57 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 5c03e58639 Fix contrato particular: usar "012" (como está en TNS y Firebird)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:27:01 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 be272296af Fix particular: numeroContrato siempre "12" y sin numeroAutorizacion
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:26:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 69372a5673 Agrega filtro convenio en automation/transaccion/test-rda y fix particular (contrato 12)
- automation: filtro contrato en SQL pacientes+RDA, numero LHXC en run()
- transaccion: filtro contrato en preview/send-one/send
- test-rda: filtro tipo_usuario (11/07/12), default contrato "12", acepta "12"/"012"
- json_generator: detecta particular por CODCONTRATO "12"/"012" además de NIT_EMPRESA PART; fuerza tipousuario="12", codFormaPago="CLIP", plazoDias="0"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:23:00 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 d7afbe9b7d Numero TNS = formato RIPS limpio: LHXC03990 sin sufijo idrecepcion
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:07:05 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 88f684a006 Usa formato RIPS completo para numero TNS: LHXC03990-314522
El numero del kardex en TNS ahora incluye el PREFIJO de Firebird y el
NUM_FACTURA zero-padded a 5 dígitos, igual al numFactura del RIPS
(ej: LHXC03404). Se agrega -{idrecepcion} al final para garantizar
unicidad ya que múltiples IDRECEPCION comparten el mismo NUM_FACTURA.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:03:03 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 6905a4132e Simplifica numero único en TNS: siempre usar {factura}-{idrecepcion}
Elimina la lógica condicional que dependía de rda_test_log para detectar
colisiones. Ahora cada IDRECEPCION siempre genera un numero único y
reproducible en TNS sin consultar historial previo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:59:31 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 d9d3deef6c Fix colisión de numero de factura en TNS cuando varios IDRECEPCION comparten NUM_FACTURA
- json_generator: agrega parámetro numero_override para usar un número alternativo
- test_rda: detecta si el NUM_FACTURA ya fue enviado exitosamente (sesión o rda_test_log) y usa "{factura}-{idrecepcion}" como numero único en TNS
- transaccion: misma lógica en envío masivo, evita que el segundo IDRECEPCION de la misma factura falle con 409

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:50:30 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 7e0c6039b8 Fix profesionalRemisionante con slash y mejora display resultado test-rda
- json_generator: limpia DOCIDMEDICO a solo dígitos (eg "9410/86" → "941086") para que TNS acepte el código
- test_rda.html: resultado con syntax highlight en JSON enviado y respuesta TNS, mejor legibilidad del error TNS, botones Resp.TNS y JSON env. con íconos

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:44:46 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 7699303a53 Mejora Transacción y Historial: estado por fila, envío individual y filtros avanzados
- 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>
2026-06-26 19:40:11 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ef71a1db56 test-rda: add preview, ver más pagination, sent tracking, default contrato=011
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:32:53 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 e477aa2bea Fix error display: show TNS response separately, default filter contrato=011
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:25:33 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 da99a446f1 Filter candidatos: only records where ALL exams are in configured TNS list (NOT EXISTS)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:21:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b5e56f2238 Fix error display in test-rda, remove PO from default article filter
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:19:06 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c1cbe54105 Fix candidatos: uppercase column keys, filter by TNS-configured articles, show last 10
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:15:26 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c2977011ee Fix get_firebird_from_config call in test_rda (returns tuple fb, ok, msg)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 19:06:32 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c64a68ec6f Add test-rda page, fix prefijo/remisionante/especialidad for TNS RDA sends
- New /test-rda route: list Firebird candidates with valid contract/factura,
  send individual RDA with auto tercero creation and full result display
- json_generator: use prefijo_tns_default config instead of Firebird PREFIJO,
  add profesionalRemisionante from DOCIDMEDICO or remisionante_default config
- All queries: add DOCIDMEDICO column from MEDICO JOIN
- automation/transaccion: add remisionante_default and prefijo_tns_default params
- config: add remisionante_default (00) and prefijo_tns_default (00) keys
- automation SQL: filter NUM_FACTURA > 0 to skip unbilled records
- config.html: add UI fields for new config keys

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 18:57:54 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 3017c7956e Fix numeroContrato: use EMPRESA.CODCONTRATO from Firebird, sucursal default 00
- Join EMPRESA table in all RDA queries to get CODCONTRATO (TNS contract code)
- Use EMPRESA.CODCONTRATO as numeroContrato instead of raw NIT_EMPRESA
- Especialidad always uses default_especialidad (ignore Firebird COD_ESPECIALIDAD)
- sucursal defaults to '00' (not empty) in config and endpoints
- Fix config template label: especialidad default is TNS code not Firebird code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 18:01:32 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 f0514641b3 Add profesional_default and especialidad_default fields to config page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 17:19:37 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 1f49f5bff5 Fix time format: clean spaces before truncating to avoid cutting seconds
Previous order: [:19] then replace(": ", ":") would truncate "06: 59: 28"
to "06: 59: " before cleaning, losing the seconds entirely.
Correct order: clean spaces first, then [:19].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 17:08:29 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 4e85dff07d profesional always uses TNS default (02=Lab); Firebird MEDICO codes don't match TNS catalog
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 17:05:06 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 83ce80a74b Send profesional/especialidad as null instead of empty string when no value
TNS schema marks both as optional — null may bypass company-level validation
that rejects empty string "". Falls back to config default if set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 16:43:31 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c70f0f1062 Fix profesional/especialidad: use MEDICO.CODIGO first, add config defaults
- SQL query now prioritizes MEDICO.CODIGO over RECEPCION.USUARIO as profesional
  (USUARIO is the billing clerk; MEDICO is the medical professional)
- Add profesional_default and especialidad_default config keys for when
  Firebird data is empty or contains invalid values (e.g. especialidad = ".")
- generar_rda_paciente accepts default_profesional and default_especialidad params
- ensure_defaults in queries.py now updates existing query records on startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 16:12:16 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 fbdce1c790 Add error message to send resultados so TNS errors are visible in response
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 15:59:21 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 63fcbe3611 Fix factura input parsing: extract numeric part from "LHXC 3918" format
NUM_FACTURA is numeric in Firebird — strip prefix and spaces before querying.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 20:53:16 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 0ec4ae3e66 Fix JSON generation: numero factura, forma pago, tipousuario, hora format
- numero: usar NUM_FACTURA en lugar de cadena vacía
- codFormaPago: CLIP (particular) / INST (EPS) según TNS real
- tipousuario: fallback desde TIPOUSU cuando TIPOUSUSISPRO es NULL
- fechaHoraEgreso: última FECHA_REPORTADO en lugar de FECHA_RECEPCION
- _fmt_datetime: eliminar espacios en tiempo ("06: 08: 29" → "06:08:29")
- especialidad: limpiar valores basura (., -, 0, 00)
- telefono: fallback "0000000" cuando vacío (campo requerido TNS)
- profesional: COALESCE(USUARIO, MEDICO.CODIGO) en queries SQL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 20:48:22 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 f5cd5a233f Automation: replace confirm() with validation modal before sending
Show a modal with full summary (pacientes, recepciones, examenes,
patient list with RDA count) and a warning before the actual API
call. Requires explicit "Confirmar y enviar" click.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:50:51 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 dbaf49b30e Automation preview: show RDA per patient on click
Preview now returns all patients with their grouped receptions.
Clicking a patient row expands/collapses their RDA list showing
factura, fecha, exam count, diagnosis, and total value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:49:21 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 7dc8f37c36 Fix fdb named parameter support: convert :name to positional ?
fdb does not support named parameters (:name + dict). Convert all
:name placeholders to ? and build a positional list from the param
dict in the same order they appear in the query.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:40:57 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c920b45640 Audit fixes: date format, prefijo query, and UI labels
- transaccion: append " 00:00:00" / " 23:59:59" to date params so Firebird BETWEEN works correctly with TIMESTAMP columns
- queries.py QUERY_DEFAULTS: remove :prefijo from RDA por factura (matches DB state)
- terceros.html: mark doc_num as required with visual indicator

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:31:53 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b4a7271d8d Fix param validation errors and add TNS config section
- terceros/transaccion: return clear error when required params (doc_num, num_factura) are missing instead of passing empty dict to Firebird causing Column unknown error
- transaccion: remove prefijo from 'por factura' query; parse num_factura as int when digit
- automation: add /preview endpoint to show patient/reception counts before sending; update UI with preview step and disabled run button until preview loads
- config: add TNS credentials section (tns_empresa, tns_usuario, tns_password, api_sucursal) with test-connection button
- config: add POST /config/test-tns endpoint

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:29:32 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 3755a51562 feat: envío masivo por fecha — Terceros + RDA en un solo paso
- automation: reescrito para filtrar por fecha (default hoy), obtener
  pacientes únicos del día vía JOIN RECEPCION+PACIENTE+CIUDAD, luego
  agrupar recepciones por IDRECEPCION y enviar Tercero/Crear + RdaPaciente/Insertar a TNS v2
- template: UI simplificada con datepicker (default hoy), tabla de
  resultados por paciente/factura con estado OK/error por ítem

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 19:08:01 -05:00
Lizandro Guarnizo 531389bc24 config: sucursal TNS = 81080 2026-06-25 18:59:22 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 6d5a85c55f feat: integración completa con API TNS v2
- api_client: agrega get_tns_token() — login en /v2/Acceso/Login y retorna JWT
- json_generator: campos en camelCase según swagger v2; agrega nomRegTri y
  email placeholder cuando el paciente no tiene correo
- terceros/transaccion routes: obtienen token TNS antes de cada envío,
  usan endpoints /v2/tablas/Tercero/Crear y /v2/rda/RdaPaciente/Insertar
- config: agrega tns_empresa, tns_usuario, tns_password

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 18:56:31 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 774ce7d728 feat: queries reales Firebird y generadores JSON para API ERP
- json_generator: nuevas funciones generar_tercero_api y generar_rda_paciente
  mapeando PACIENTE/RECEPCION/RELACION al formato de los endpoints
  Tercero/Crear y RdaPaciente/Insertar
- queries: reemplaza placeholders por consultas reales sobre PACIENTE,
  RECEPCION, RELACION, MEDICO y CIUDAD
- config: agrega api_version y api_sucursal; actualiza url y credenciales Firebird
- terceros/transaccion routes: usan nuevos generadores y endpoints correctos

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 17:27:00 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 26243aa2bc docs: agregar documentación endpoints API y actualizar BD
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 16:34:12 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 1111da578f Fix: botón descargar JSON no aparecía — classList.replace por remove/add + style.display
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 15:27:19 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 e41382db4e feat: botón descargar JSON en panel de resultados
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 15:25:09 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 a212578b37 Fix: esquema no expandía tablas — JSON.stringify con comillas rompía el onclick
Reemplazado innerHTML con template literals por createElement + addEventListener.
Eliminado JSON embebido en atributos HTML. selectAll ahora busca en el array global.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 14:31:04 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 122d21df09 Fix: editar consulta no hacía nada — comillas dobles en onclick rompían el HTML
Cambio tojson en atributos onclick por data-* con |e.
dataset decodifica automáticamente &quot; → " sin riesgo de romper el atributo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 13:16:48 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 eb6bcebff8 feat: autocomplete SQL al escribir en vez de Ctrl+Space
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 13:05:07 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 569bb43a62 Fix: errores 500 silenciosos en run-sql y esquema
- _safe() maneja bytes/BLOB, memoryview y cualquier tipo desconocido
- _port() evita ValueError/TypeError si el puerto está vacío o es None
- get_firebird_from_config usa _port() en todos los endpoints
- run-sql y esquema wrapped en try/except → devuelven JSON de error en vez de 500 HTML

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 12:57:22 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c663df006b Fix: serializar tipos Firebird no-JSON (date, datetime, Decimal) en execute_query
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 12:30:13 -05:00
Lizandro Guarnizo 408ea50d21 hola 2026-06-18 12:25:44 -05:00
Lizandro Guarnizo 65ff7995e8 Update DOCUMENTACION.md with complete project documentation 2026-06-18 11:36:20 -05:00
Lizandro Guarnizo 1e4b895913 Reorganize queries page: Probador, Constructor with results, Editor tab 2026-06-18 11:02:56 -05:00
Lizandro Guarnizo 25e90e7e28 Fix: auto-trigger hints while typing 2026-06-18 10:54:19 -05:00
Lizandro Guarnizo 181943bf00 Add CodeMirror SQL editor with autocomplete for tables and columns 2026-06-18 10:43:09 -05:00
Lizandro Guarnizo b57d1ba817 Fix: use f-string for table name in column query 2026-06-18 10:41:04 -05:00
Lizandro Guarnizo b3a0717287 Add visual query builder with table/column picker and SQL generator 2026-06-18 09:34:55 -05:00