Files
whatsapp/dbg_form.php
T

27 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/config/config.php';
header('Content-Type: application/json; charset=utf-8');
$pdo = Database::getInstance()->getConnection();
$stmt = $pdo->prepare(
"SELECT id, nombre, codigo, esquema FROM lab_formularios
WHERE LOWER(nombre) LIKE '%helicobacter%' OR codigo = 'F-LAB-28'
LIMIT 5"
);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!$rows) {
$all = $pdo->query("SELECT id, nombre, codigo FROM lab_formularios ORDER BY id LIMIT 50")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['not_found'=>true,'forms'=>$all], JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
exit;
}
foreach ($rows as &$r) {
$dec = json_decode($r['esquema'], true);
$campos = is_array($dec) ? $dec : ($dec['campos'] ?? []);
$fp = array_values(array_filter($campos, fn($f)=>($f['tipo']??'')==='firma_profesional'));
$r['count_fp'] = count($fp);
$r['firma_pro_ids'] = array_column($fp, 'id');
$r['all_tipos'] = array_count_values(array_column($campos, 'tipo'));
unset($r['esquema']);
}
echo json_encode($rows, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);