diff --git a/modules/medicos/api/list.php b/modules/medicos/api/list.php index ae24fe0..c3b5c5c 100644 --- a/modules/medicos/api/list.php +++ b/modules/medicos/api/list.php @@ -6,21 +6,35 @@ header('Content-Type: application/json'); $pdo = Database::getInstance()->getConnection(); $buscar = trim($_GET['q'] ?? ''); +$page = max(1, (int)($_GET['page'] ?? 1)); +$limit = max(1, min(200, (int)($_GET['limit'] ?? 25))); +$offset = ($page - 1) * $limit; + +$where = ''; +$params = []; if ($buscar !== '') { - $like = '%' . $buscar . '%'; - $stmt = $pdo->prepare( - "SELECT id, codigo, nombres, apellidos, telefonos, email, cod_especialidad, docidmedico, activo - FROM medicos - WHERE nombres LIKE ? OR apellidos LIKE ? OR codigo LIKE ? OR docidmedico LIKE ? - ORDER BY apellidos, nombres" - ); - $stmt->execute([$like, $like, $like, $like]); -} else { - $stmt = $pdo->query( - "SELECT id, codigo, nombres, apellidos, telefonos, email, cod_especialidad, docidmedico, activo - FROM medicos ORDER BY apellidos, nombres" - ); + $like = '%' . $buscar . '%'; + $where = "WHERE nombres LIKE ? OR apellidos LIKE ? OR codigo LIKE ? OR docidmedico LIKE ?"; + $params = [$like, $like, $like, $like]; } -echo json_encode(['ok' => true, 'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)]); +$countStmt = $pdo->prepare("SELECT COUNT(*) FROM medicos $where"); +$countStmt->execute($params); +$total = (int)$countStmt->fetchColumn(); + +$dataStmt = $pdo->prepare( + "SELECT id, codigo, nombres, apellidos, telefonos, email, cod_especialidad, docidmedico, activo + FROM medicos $where + ORDER BY apellidos, nombres + LIMIT $limit OFFSET $offset" +); +$dataStmt->execute($params); + +echo json_encode([ + 'ok' => true, + 'data' => $dataStmt->fetchAll(PDO::FETCH_ASSOC), + 'total' => $total, + 'page' => $page, + 'limit' => $limit, +]); diff --git a/modules/medicos/views/index.php b/modules/medicos/views/index.php index 2b02dd9..eba91d9 100644 --- a/modules/medicos/views/index.php +++ b/modules/medicos/views/index.php @@ -29,6 +29,23 @@ $API = BASE_URL . 'modules/medicos/api/'; font-size: .75rem; font-weight: 600; } .acciones { display: flex; gap: 6px; } #tbl-empty { text-align: center; padding: 3rem; color: #94a3b8; } + .pag-bar { + display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; + padding: 10px 16px; border-top: 1px solid #e2e8f0; background: #f8fafc; + } + .pag-bar .pag-info { font-size: .8rem; color: #64748b; } + .pag-controls { display: flex; gap: 4px; align-items: center; } + .pag-btn { + min-width: 32px; height: 32px; padding: 0 8px; + border: 1px solid #e2e8f0; border-radius: 7px; background: #fff; + font-size: .82rem; color: #374151; cursor: pointer; font-weight: 500; + display: flex; align-items: center; justify-content: center; + transition: background .12s, border-color .12s; + } + .pag-btn:hover:not(:disabled) { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; } + .pag-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; } + .pag-btn:disabled { opacity: .4; cursor: not-allowed; } + .pag-ellipsis { font-size: .82rem; color: #94a3b8; padding: 0 4px; line-height: 32px; }