252 Commits
Author SHA1 Message Date
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
Lizandro Guarnizo 71c94375b3 Add 'Ver tablas' button to list Firebird tables 2026-06-18 09:30:27 -05:00
Lizandro Guarnizo c589090110 Add Test button for queries with result viewer 2026-06-18 09:25:38 -05:00
Lizandro Guarnizo 9a369a070a Change to start /min instead of pythonw 2026-06-17 18:37:37 -05:00
Lizandro Guarnizo dc593a223e Fix run.bat: cd to script dir, use full python path 2026-06-17 18:34:10 -05:00
Lizandro Guarnizo 6a064c2ed5 Add run.bat (background with pythonw), stop.bat, run.vbs 2026-06-17 18:26:42 -05:00
Lizandro Guarnizo 25ca4a504c Add console credits, README with documentation and U-SITE credits 2026-06-17 18:13:14 -05:00
Lizandro Guarnizo 5fb3e32d2f Session sin expiracion, mostrar IP de red 2026-06-17 18:10:06 -05:00
Lizandro Guarnizo f040a01853 Simplify: remove auto-update, run.ps1 just starts the server 2026-06-17 15:17:43 -05:00
Lizandro Guarnizo 307f089d4f Fix: add __name__ guard for Windows multiprocessing 2026-06-17 15:05:57 -05:00
Lizandro Guarnizo a49a6626d3 Add PowerShell scripts for Windows auto-update 2026-06-17 13:41:04 -05:00
Lizandro Guarnizo f2564db6ee Fix CRLF line endings for Windows batch files 2026-06-17 13:40:14 -05:00
Lizandro Guarnizo 397a88e5a4 Use full Python installer instead of embeddable 2026-06-17 13:37:37 -05:00
Lizandro Guarnizo 423460c0cd Fix: use auto_update.py instead of inline Python in batch 2026-06-17 13:36:24 -05:00