feat(turnero): mostrar tomas prolongadas pendientes de visita anterior
Cuando el paciente regresa con un turno nuevo, toma de muestras muestra las tomas en_progreso de visitas anteriores con botón Continuar o Cancelar. Cancelar marca estado='rechazado' (campo ya existía en el enum). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
8bc9cbdd35
commit
814bd2ce5c
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* GET /modules/turnero/api/get_tomas_pendientes_paciente.php?turno_id=X
|
||||
* Devuelve tomas progresivas en_progreso del mismo paciente en turnos anteriores.
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireMethod('GET');
|
||||
requireTurnero();
|
||||
|
||||
$turnoId = (int)($_GET['turno_id'] ?? 0);
|
||||
if (!$turnoId) jsonError('turno_id requerido.');
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Obtener paciente_id del turno actual
|
||||
$row = $pdo->prepare("SELECT paciente_id FROM turnero_turnos WHERE id = ? LIMIT 1");
|
||||
$row->execute([$turnoId]);
|
||||
$t = $row->fetchColumn();
|
||||
|
||||
if (!$t) jsonOk(['tomas' => []]);
|
||||
|
||||
$pacienteId = (int)$t;
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT tc.id, tc.turno_id, tc.token, tc.siguiente_toma_at, tc.toma_inicio_at,
|
||||
tc.datos_respuestas, f.nombre AS formulario_nombre, f.esquema,
|
||||
tt.codigo AS turno_codigo, tt.creado_at AS turno_fecha
|
||||
FROM turnero_consentimientos tc
|
||||
JOIN lab_formularios f ON f.id = tc.formulario_id AND f.es_toma_progresiva = 1
|
||||
JOIN turnero_turnos tt ON tt.id = tc.turno_id
|
||||
WHERE tt.paciente_id = ?
|
||||
AND tc.turno_id != ?
|
||||
AND tc.estado = 'en_progreso'
|
||||
ORDER BY tc.id DESC
|
||||
LIMIT 10"
|
||||
);
|
||||
$stmt->execute([$pacienteId, $turnoId]);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$tomas = [];
|
||||
foreach ($rows as $r) {
|
||||
$esquema = json_decode($r['esquema'] ?? '[]', true) ?: [];
|
||||
$datos = json_decode($r['datos_respuestas'] ?? '[]', true) ?: [];
|
||||
|
||||
// Contar firmas totales y hechas
|
||||
$totalFirmas = 0;
|
||||
$firmasHechas = 0;
|
||||
foreach ($esquema as $c) {
|
||||
if (($c['tipo'] ?? '') === 'firma_profesional') {
|
||||
$totalFirmas++;
|
||||
if (!empty($datos[$c['id']]) && strlen($datos[$c['id']]) > 10) $firmasHechas++;
|
||||
}
|
||||
}
|
||||
|
||||
$tomas[] = [
|
||||
'id' => (int)$r['id'],
|
||||
'turno_id' => (int)$r['turno_id'],
|
||||
'token' => $r['token'],
|
||||
'formulario_nombre' => $r['formulario_nombre'],
|
||||
'siguiente_toma_at' => $r['siguiente_toma_at'],
|
||||
'toma_inicio_at' => $r['toma_inicio_at'],
|
||||
'turno_codigo' => $r['turno_codigo'],
|
||||
'turno_fecha' => $r['turno_fecha'],
|
||||
'tomas_firmadas' => $firmasHechas,
|
||||
'tomas_total' => $totalFirmas,
|
||||
];
|
||||
}
|
||||
|
||||
jsonOk(['tomas' => $tomas]);
|
||||
Reference in New Issue
Block a user