feat: write to rips_examenes_pendientes on solicitud creation

Al guardar una solicitud en recepción, escribe los exámenes en la bandeja
temporal WhatsApp (rips_examenes_pendientes) con DELETE+INSERT del día.
Al volver a seleccionar el mismo paciente, get_examenes_rips los detecta
como fuente=cache y los auto-carga sin confirmación.

También fix en get_examenes_rips: exámenes con codigo_legacy=NULL ahora
se buscan por codigo como fallback (COALESCE).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-17 15:56:24 -05:00
co-authored by Claude Sonnet 4.6
parent f70b29abf8
commit e950e2c146
2 changed files with 48 additions and 4 deletions
+6 -4
View File
@@ -71,14 +71,16 @@ $no_mapeados = [];
if ($codigos) {
$ph = implode(',', array_fill(0, count($codigos), '?'));
$stmt = db()->prepare(
"SELECT id AS exam_tipo_id, codigo, nombre, codigo_legacy
"SELECT id AS exam_tipo_id, codigo, nombre,
COALESCE(codigo_legacy, codigo) AS match_key
FROM exam_tipos
WHERE codigo_legacy IN ($ph) AND activo = 1"
WHERE (codigo_legacy IN ($ph) OR (codigo_legacy IS NULL AND codigo IN ($ph)))
AND activo = 1"
);
$stmt->execute($codigos);
$stmt->execute(array_merge($codigos, $codigos));
$mapa = [];
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) {
$mapa[trim($r['codigo_legacy'])] = $r;
$mapa[trim($r['match_key'])] = $r;
}
foreach ($codigos as $cod) {
if (isset($mapa[$cod])) {