From 26bb9e1844e9d653c677a214adeca956bcc2b71e Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 21 Jul 2026 16:39:22 -0500 Subject: [PATCH] rips: prevent reuse of already-consumed exam records - Add turno_id column to rips_examenes_pendientes (already migrated) - Filter turno_id IS NULL in get_examenes_rips.php query - New marcar_rips_usado.php marks record as consumed when loaded - cargarExamenesRips() calls marker after loading exams into the turn Co-Authored-By: Claude Sonnet 4.6 --- api/lab/get_examenes_rips.php | 1 + api/lab/marcar_rips_usado.php | 26 ++++++++++++++++++++++++++ modules/turnero/views/recepcion.php | 10 ++++++++++ 3 files changed, 37 insertions(+) create mode 100644 api/lab/marcar_rips_usado.php diff --git a/api/lab/get_examenes_rips.php b/api/lab/get_examenes_rips.php index 16e464a..fdc3c37 100644 --- a/api/lab/get_examenes_rips.php +++ b/api/lab/get_examenes_rips.php @@ -20,6 +20,7 @@ $cacheRow = db()->prepare( WHERE numero_documento = ? AND DATE(created_at) = CURDATE() AND created_at >= NOW() - INTERVAL 30 MINUTE + AND turno_id IS NULL ORDER BY created_at DESC LIMIT 1" ); diff --git a/api/lab/marcar_rips_usado.php b/api/lab/marcar_rips_usado.php new file mode 100644 index 0000000..10b3137 --- /dev/null +++ b/api/lab/marcar_rips_usado.php @@ -0,0 +1,26 @@ +prepare( + "UPDATE rips_examenes_pendientes + SET turno_id = ? + WHERE numero_documento = ? + AND DATE(created_at) = CURDATE() + AND turno_id IS NULL + ORDER BY created_at DESC + LIMIT 1" +)->execute([$turnoId, $cedula]); + +jsonOk(['marcado' => true]); diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index fc1cbdf..54d15cf 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -1707,6 +1707,16 @@ async function cargarExamenesRips() { if (_ripsData.valor_total > 0) { document.getElementById('inp-total').value = Math.round(_ripsData.valor_total); } + // Marcar registro RIPS como consumido para no reutilizarlo en otro turno + const cedula = pacienteActivo?.numero_documento || pacienteActivo?.documento + || turnoActivo?.paciente_nombre || ''; + if (cedula && turnoActivo?.id) { + fetch(`${BASE_WA}api/lab/marcar_rips_usado.php`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ cedula, turno_id: turnoActivo.id }), + }).catch(() => {}); + } descartarRips(); }