- 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>
- 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>
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>
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>
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>
La documentacion marca CodFormaPago como Requerido=Si. Su ausencia
causaba 'Datos incorrectos' en TNS.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- 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>
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>
- 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>
- 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>
- 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>
- 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>
- 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>
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>
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>
- 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>
- 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>
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>
- 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>
- 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>
- _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>