- Migration: columna 'origen' (manual|rips|whatsapp) en lab_pacientes - ingest_paciente.php: guarda origen='rips' en cada paciente importado - Paciente::listar(): filtro por origen + orden por created_at DESC - Paciente::stats(): conteo total/importados/con_wa/manuales - get_pacientes.php: expone ?origen= y ?stats=1 - lab_pacientes.php: cards de stats clicables, badge origen por fila, columna ciudad, columna fecha registro, dropdown filtro por origen Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
1002 B
PHP
30 lines
1002 B
PHP
<?php
|
|
/** GET /api/lab/get_pacientes.php — Lista paginada de pacientes o detalle por ID */
|
|
require_once __DIR__ . '/_helpers.php';
|
|
requireMethod('GET');
|
|
|
|
try {
|
|
$pac = new Paciente();
|
|
|
|
// Detalle de un paciente específico
|
|
if (!empty($_GET['id']) && ctype_digit($_GET['id'])) {
|
|
$row = $pac->obtener((int)$_GET['id']);
|
|
if (!$row) jsonError('Paciente no encontrado', 404);
|
|
jsonOk(['data' => [$row]]);
|
|
}
|
|
|
|
if (isset($_GET['stats'])) {
|
|
jsonOk(['stats' => $pac->stats()]);
|
|
}
|
|
|
|
$busqueda = trim($_GET['busqueda'] ?? $_GET['search'] ?? '');
|
|
$pagina = max(1, (int)($_GET['page'] ?? $_GET['pagina'] ?? 1));
|
|
$por = max(1, min(100, (int)($_GET['limit'] ?? $_GET['por_pagina'] ?? 30)));
|
|
$origen = in_array($_GET['origen'] ?? '', ['manual', 'rips', 'whatsapp'], true)
|
|
? $_GET['origen'] : '';
|
|
|
|
jsonOk($pac->listar($busqueda, $pagina, $por, $origen));
|
|
} catch (Exception $e) {
|
|
jsonError($e->getMessage(), 500);
|
|
}
|