Commit Graph
110 Commits
Author SHA1 Message Date
Lizandro GuarnizoandClaude Sonnet 4.6 b88d727623 feat: add 5 minutes to fechaHoraEgreso in RDA
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-06 19:44:06 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 235e20e38d feat: remove unused fields from RDA JSON output
Remove codFormaPago, codBanco, descuento from header.
Remove tipoUnidad, descuento, porcentajeIva, impConsumo from detallePedido.
Remove detalleFormaPago entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-02 21:59:02 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 3aa0e09aa6 chore: bump version marker in json_generator
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-02 09:31:24 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b3b283a7d0 fix: syntaxHighlight regex adding spaces inside time values
The number regex /:(\s*)(\d+)/ was matching colons inside time strings
like "14:51:26" turning them into "14: 51: 26". Changed to require the
space that JSON.stringify always adds after key-value colons (": \d+")
so colons inside string values are not affected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 17:41:37 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 07038ac431 fix: clean time spaces in logs view without modifying stored data
Applies _clean_times when serving json_enviado in /logs/detalle
so old records with "12: 47: 37" display correctly as "12:47:37".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 17:36:45 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 72973973d4 feat: calculate real discount % from TARIFA vs RELACION.PRECIO
Joins TARIFA using EMPRESA.TARIFA to get the base price per exam,
then calculates descuento = round((sum(TARIFA) - sum(PRECIO)) / sum(TARIFA) * 100)
and sends it as integer percentage in the RDA header encabezado.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 17:26:49 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 15f6ca65db feat: add descuento from RECEPCION.VALORDESC to RDA header
Pulls r.VALORDESC in all SQL queries (automation, test_rda, queries
defaults) and maps it to the top-level descuento field in the
RdaPaciente JSON encabezado.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 17:13:46 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 f35a39bc9b fix: add EXAMEN join to QUERY_DEFAULTS so CUPs codes survive restarts
ensure_defaults() runs on every startup and was overwriting the db
queries with the old versions from QUERY_DEFAULTS — wiping any manual
fixes. Now the source-of-truth in code has the EXAMEN join and CUPS
column, so transaccion page always shows CUPs after any restart.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 14:38:30 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 e32214fef7 tmp: add fix_queries.py to update transaccion SQL with EXAMEN join
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 13:11:25 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 eba512720f fix: remove duplicate EXAMEN JOIN in saved transaccion queries
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 13:03:48 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b12e8fcf88 feat: use EXAMEN.NUM_ISS as codigoMaterial (CUPs) via LEFT JOIN EXAMEN
CH4=902210, PO=907106, GRAM=901107, etc. Falls back to COD_EXAMEN if empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:53:16 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b22b47a1e1 debug: search 903967 across all candidate tables
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:34:50 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 fb81ddf263 debug: search PROTOCOLO table and all CUP fields system-wide
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:32:27 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 942d68b75d debug: catch all exceptions and return traceback as JSON
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:31:24 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 bc5fc36a5d debug: explore RELACION_HIMS table for CUPS_REF field
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:30:12 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 68aa5e0355 feat: join ITEM on COD_PROTOCOLO to get CUPS_DETALLE as codigoMaterial
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:29:33 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 d95e2b67ff debug: probe possible ITEM join fields, show first row without join
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:27:44 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 41ee88c1b4 fix: remove rel.DESCUENTO (column does not exist in RELACION table)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:26:09 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b4748e34d8 debug: minimal endpoint - only ITEM columns and sample row
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:25:20 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 d1c1d3205f revert: remove broken ITEM join until correct field name is known
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:24:01 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 e6d0b74992 debug: show ITEM columns and first row to find join key
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:22:35 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ff08c1b3a8 feat: use ITEM.CUPS_DETALLE as codigoMaterial in RDA
LEFT JOIN ITEM on COD_EXAMEN to get CUPS_DETALLE. Falls back to
COD_EXAMEN if CUPS is empty. Applied to automation, test_rda, and
saved queries in SQLite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:20:22 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ebd45446a4 tmp: add check_cups.py script to query Firebird schema
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:16:15 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 9aa04307c6 debug: query ITEM table columns and CUPS_DETALLE samples
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:15:33 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 44af9680f2 fix: add LIKE %CUP% search across all tables in debug endpoint
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:14:21 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 0896e14e62 fix: simplify debug cups endpoint to avoid Firebird CONTAINING error
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:13:30 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 8b2f8eb3be fix: add rel.DESCUENTO to all SQL queries; update debug endpoint with discount check
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:11:00 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 8732db9c1f fix: use Firebird PREFIJO as codigoPrefijo; add debug endpoint to find CUPs field
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:07:43 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ed9fead353 fix: remove valor field from detallePedido; filter by PREFIJO in transaccion
- json_generator: remove valor entirely from detalle items (not even 0)
- transaccion: after fetching rows, filter by prefix if user typed full
  factura like "LHXC03726" and query returns PREFIJO column

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 12:00:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 1548aadf3c fix: set valor=0 in detallePedido; parse full factura (prefix+number) in search
- json_generator: send valor:0 per item instead of PRECIO from Firebird
- test_rda + transaccion: accept "LHXC03726" format — extracts numeric part
  for NUM_FACTURA and letter prefix for PREFIJO filter when prefix present

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 11:54:08 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 4b77f0a0ac fix: quitar rel.DESCUENTO — columna no existe en tabla RELACION de Firebird
json_generator ya usa row.get('DESCUENTO') or 0 como fallback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 21:15:10 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 02c2f7a17b fix: combinar fecha+hora separados de Firebird en fechaHoraIngreso
HORAINICIORECEPCION es campo TIME en Firebird — fdb lo devuelve como
datetime.time sin fecha. _fmt_datetime recibía '06:08:29' y lo pasaba
tal cual al JSON. TNS rechazaba por formato inválido.

- _fmt_datetime ahora maneja entrada solo-fecha → agrega 00:00:00
- generar_rda_paciente combina HORAINICIORECEPCION + FECHA_RECEPCION
  antes de llamar _fmt_datetime cuando detecta hora sin fecha

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 20:50:01 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 9d80279114 fix: strip spaces around colons in entire RDA JSON before returning
Adds _clean_times() that recursively walks every string in the result
dict and applies re.sub(r'\s*:\s*', ':'), guaranteeing no "12: 47: 37"
spaces survive to the TNS API regardless of Firebird driver behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 20:16:23 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 9d87c3fa1c fix: usar regex en _fmt_datetime para eliminar espacios en horas de Firebird
re.sub('\s*:\s*', ':') captura cualquier tipo de espacio alrededor
de los dos puntos, incluyendo tipos no-ASCII que .replace() no atrapa.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 20:01:28 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 4aa30c74c1 fix: restaurar codFormaPago en header RDA (campo requerido segun docs)
La documentacion marca CodFormaPago como Requerido=Si. Su ausencia
causaba 'Datos incorrectos' en TNS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 19:23:08 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c7428a196b fix: quitar codFormaPago header, fechaAutorizacion=hoy, descuento de Firebird
- Elimina codFormaPago del header RDA (no va segun JSON de referencia)
- fechaAutorizacion usa fecha de hoy, no la de recepcion
- descuento toma rel.DESCUENTO de Firebird en vez de hardcodeado 0
- Agrega rel.DESCUENTO al SELECT en test_rda y automation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 16:12:48 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 543af23779 fix: restaurar codFormaPago en header RDA (requerido por TNS)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 15:26:35 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 20a22e8e5b fix: limpiar espacios en horas desde la fuente en _safe de Firebird
Usa strftime en vez de isoformat y aplica re.sub para eliminar
espacios alrededor de los dos puntos en strings de tiempo de fdb.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 15:20:57 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c5d6b9857e fix: eliminar espacios en horas de Firebird en fechaHoraIngreso/Egreso/Realizacion
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 15:16:58 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 dd4d012a4b fix: fechaHoraEgreso = fechaHoraRealizacion del ultimo examen
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 15:12:59 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 00bfbaee51 fix: vigenciaAutorizacion siempre 30
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 15:09:43 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 2321771c3e fix: quitar codFormaPago del header RDA, añadir fechaAutorizacion y vigenciaAutorizacion
- Elimina codFormaPago del header principal (queda en detalleFormaPago)
- Añade fechaAutorizacion con la fecha de recepcion (dd/MM/yyyy)
- Añade vigenciaAutorizacion: 0 para particular, 30 para EPS/convenio

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 15:00:17 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 be1910b5d8 fix: send numero sin prefijo LHXC en RDA TNS
TNS espera solo el numero numerico (ej: "4001"), no el formato
combinado con prefijo (ej: "LHXC04001"). El codigoPrefijo "00"
ya referencia la serie correcta en la configuracion de TNS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 21:09:58 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 90de09b22c Fix RDA: quitar campos demograficos del RDA (solo van en Tercero); identidadGenero con ceros "01"/"02"
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:50:39 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 58bdb4ae55 Agrega campos demograficos paciente en RDA y Tercero (etnia, zona, identidadGenero, divPolitica, antecedentes, fechaNac, direccion)
- SQL RDA join PACIENTE para obtener datos demograficos
- generar_rda_paciente: incluye etnia, identidadGenero, zona, divisionPoliticaAdministrativa, antecedentes, fechaNacimiento, direccion
- generar_tercero_api: agrega identidadGenero, divisionPoliticaAdministrativa, antecedentes; default ciudad Cucuta 54001

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 20:49:12 -05:00
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