diff --git a/modules/turnero/api/cancelar_toma_pendiente.php b/modules/turnero/api/cancelar_toma_pendiente.php new file mode 100644 index 0000000..4d66b58 --- /dev/null +++ b/modules/turnero/api/cancelar_toma_pendiente.php @@ -0,0 +1,25 @@ +prepare( + "UPDATE turnero_consentimientos + SET estado = 'rechazado' + WHERE id = ? AND estado = 'en_progreso'" +); +$stmt->execute([$consentId]); + +if ($stmt->rowCount() === 0) jsonError('No se encontró toma en progreso con ese id.', 404); + +jsonOk(['cancelado' => true]); diff --git a/modules/turnero/api/get_tomas_pendientes_paciente.php b/modules/turnero/api/get_tomas_pendientes_paciente.php new file mode 100644 index 0000000..fd97f7f --- /dev/null +++ b/modules/turnero/api/get_tomas_pendientes_paciente.php @@ -0,0 +1,69 @@ +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]); diff --git a/modules/turnero/views/lugar.php b/modules/turnero/views/lugar.php index 5f2dccd..1bb6472 100644 --- a/modules/turnero/views/lugar.php +++ b/modules/turnero/views/lugar.php @@ -324,6 +324,22 @@ try { .consent-row .acciones-consent { display: flex; gap: .3rem; flex-shrink: 0; } .consent-row .acciones-consent .btn { font-size: .72rem; padding: 2px 9px; border-radius: 7px; } + /* ── Tomas pendientes de visita anterior ── */ + #sec-tomas-prev { display:none; } + .tomas-prev-hdr { font-size:.78rem; font-weight:700; color:#92400e; + background:#fff7ed; border:1px solid #fed7aa; + border-radius:8px 8px 0 0; padding:6px 12px; + display:flex; align-items:center; gap:6px; } + .tomas-prev-list { border:1px solid #fed7aa; border-top:none; + border-radius:0 0 8px 8px; overflow:hidden; } + .toma-prev-row { display:flex; align-items:center; gap:.6rem; + padding:.45rem .7rem; background:#fffbeb; + font-size:.83rem; color:#78350f; } + .toma-prev-row + .toma-prev-row { border-top:1px solid #fde68a; } + .toma-prev-row .nom-form { flex:1; font-weight:500; } + .toma-prev-row .acciones-consent { display:flex; gap:.3rem; flex-shrink:0; } + .toma-prev-row .acciones-consent .btn { font-size:.72rem; padding:2px 9px; border-radius:7px; } + /* ── Barra de acciones ── */ .ficha-acciones { position: sticky; bottom: 0; @@ -699,6 +715,15 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php'; + +
+
+ + Tomas pendientes de visita anterior +
+
+
+