debug: agregar diagnóstico tabla consentimientos y turnos del día
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
434df7b741
commit
1bb520ef3f
@@ -100,6 +100,72 @@ if ($rows) {
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
// ── 4b. Diagnóstico tabla turnero_consentimientos ─────────────
|
||||
echo "4b. DIAGNÓSTICO TABLA Y TURNOS RECIENTES\n";
|
||||
echo "──────────────────────────────────────────\n";
|
||||
|
||||
// Verificar que la tabla existe y tiene las columnas esperadas
|
||||
try {
|
||||
$cols = $pdo->query("DESCRIBE turnero_consentimientos")->fetchAll(PDO::FETCH_COLUMN);
|
||||
echo "Columnas: " . implode(', ', $cols) . "\n";
|
||||
} catch (\Throwable $e) {
|
||||
echo "❌ Error al leer tabla: " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
// Últimos turnos de hoy (con o sin consentimiento)
|
||||
$hoyTurnos = $pdo->query(
|
||||
"SELECT tt.id, tt.codigo, tt.paciente_nombre, tt.paciente_cel, tt.creado_at,
|
||||
(SELECT COUNT(*) FROM turnero_consentimientos tc WHERE tc.turno_id = tt.id) AS tiene_consent
|
||||
FROM turnero_turnos tt
|
||||
WHERE DATE(tt.creado_at) = CURDATE()
|
||||
ORDER BY tt.id DESC
|
||||
LIMIT 10"
|
||||
)->fetchAll(PDO::FETCH_ASSOC);
|
||||
echo "\nÚltimos 10 turnos de hoy:\n";
|
||||
if ($hoyTurnos) {
|
||||
foreach ($hoyTurnos as $t) {
|
||||
$cel = $t['paciente_cel'] ?: '(sin cel)';
|
||||
$con = $t['tiene_consent'] ? '✅ consent' : '❌ sin consent';
|
||||
echo " [{$t['id']}] {$t['codigo']} | {$t['paciente_nombre']} | cel={$cel} | {$con} | {$t['creado_at']}\n";
|
||||
}
|
||||
} else {
|
||||
echo " Sin turnos hoy\n";
|
||||
}
|
||||
|
||||
// Test de inserción directa
|
||||
echo "\nTest inserción en turnero_consentimientos:\n";
|
||||
if ($hoyTurnos) {
|
||||
$turnoTest = $hoyTurnos[0];
|
||||
$formTest = $forms[0] ?? null;
|
||||
if ($formTest) {
|
||||
try {
|
||||
$testToken = 'DEBUG-TEST-' . time();
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT IGNORE INTO turnero_consentimientos
|
||||
(turno_id, formulario_id, token, estado, creado_at)
|
||||
VALUES (?, ?, ?, 'pendiente', NOW())"
|
||||
);
|
||||
$ins->execute([$turnoTest['id'], $formTest['id'], $testToken]);
|
||||
if ($ins->rowCount()) {
|
||||
$pdo->prepare("DELETE FROM turnero_consentimientos WHERE token = ?")->execute([$testToken]);
|
||||
echo " ✅ Inserción OK (se insertó y eliminó el registro de prueba)\n";
|
||||
} else {
|
||||
echo " ⚠️ INSERT IGNORE no insertó (¿registro duplicado para turno {$turnoTest['id']}?)\n";
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
echo " ❌ Error al insertar: " . $e->getMessage() . "\n";
|
||||
}
|
||||
} else {
|
||||
echo " ⚠️ No hay formularios de recepción configurados (sección 3)\n";
|
||||
}
|
||||
} else {
|
||||
echo " ⚠️ Sin turnos hoy para probar\n";
|
||||
}
|
||||
|
||||
// Versión del archivo create_turno.php
|
||||
echo "\nVersión create_turno.php: " . date('Y-m-d H:i:s', filemtime(__DIR__ . '/modules/turnero/api/create_turno.php')) . "\n";
|
||||
echo "\n";
|
||||
|
||||
// ── 5. Test de envío ──────────────────────────────────────────
|
||||
if (isset($_GET['test_cel'])) {
|
||||
echo "5. TEST DE ENVÍO\n";
|
||||
|
||||
Reference in New Issue
Block a user