From d38b5936caa99fef7fe67cb2e57e12ebc9b26a29 Mon Sep 17 00:00:00 2001
From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com>
Date: Wed, 8 Apr 2026 09:02:32 -0500
Subject: [PATCH] actividades
---
api/lab/get_actividad.php | 29 +--
classes/lab/ActividadAdmin.php | 71 +++++++
lab_actividad.php | 329 +++++++++++++++++++++++++++++++++
lab_configuracion.php | 1 +
lab_dashboard.php | 1 +
lab_domicilios.php | 1 +
lab_enfermeras.php | 1 +
lab_formularios.php | 1 +
lab_ordenes.php | 1 +
lab_pacientes.php | 1 +
lab_reportes.php | 1 +
lab_usuarios.php | 1 +
12 files changed, 427 insertions(+), 11 deletions(-)
create mode 100644 lab_actividad.php
diff --git a/api/lab/get_actividad.php b/api/lab/get_actividad.php
index 014e0bd..7f5aab5 100644
--- a/api/lab/get_actividad.php
+++ b/api/lab/get_actividad.php
@@ -6,20 +6,27 @@ requireMethod('GET');
try {
$log = new ActividadAdmin();
- $modulo = $_GET['modulo'] ?? '';
- $adminFilt = (int)($_GET['admin_id'] ?? 0);
- $entidad = (int)($_GET['entidad_id'] ?? 0);
- $limit = max(1, min(200, (int)($_GET['limit'] ?? 50)));
-
- if ($adminFilt) {
- $data = $log->porAdmin($adminFilt, $limit);
- } elseif ($entidad && $modulo) {
+ // Caso especial: historial de una entidad concreta
+ $entidad = (int)($_GET['entidad_id'] ?? 0);
+ $modulo = $_GET['modulo'] ?? '';
+ if ($entidad && $modulo) {
$data = $log->porEntidad($modulo, $entidad);
- } else {
- $data = $log->reciente($limit, $modulo);
+ jsonOk(['data' => $data, 'total' => count($data), 'paginas' => 1, 'pagina' => 1]);
+ exit;
}
- jsonOk(['data' => $data, 'total' => count($data)]);
+ $result = $log->filtrar([
+ 'desde' => $_GET['desde'] ?? '',
+ 'hasta' => $_GET['hasta'] ?? '',
+ 'modulo' => $modulo,
+ 'accion' => $_GET['accion'] ?? '',
+ 'admin_id' => (int)($_GET['admin_id'] ?? 0) ?: null,
+ 'buscar' => $_GET['buscar'] ?? '',
+ 'page' => max(1, (int)($_GET['page'] ?? 1)),
+ 'per_page' => max(1, min(200, (int)($_GET['limit'] ?? 50))),
+ ]);
+
+ jsonOk($result);
} catch (Exception $e) {
jsonError($e->getMessage(), 500);
}
diff --git a/classes/lab/ActividadAdmin.php b/classes/lab/ActividadAdmin.php
index e18f737..4b51032 100644
--- a/classes/lab/ActividadAdmin.php
+++ b/classes/lab/ActividadAdmin.php
@@ -129,4 +129,75 @@ class ActividadAdmin {
ORDER BY modulo, total DESC
", [$desde, $hasta]);
}
+
+ /**
+ * Filtrado avanzado con paginación.
+ *
+ * @param array $opts {desde, hasta, modulo, accion, admin_id, buscar, page, per_page}
+ * @return array {data, total, paginas, pagina}
+ */
+ public function filtrar(array $opts = []): array {
+ $where = [];
+ $params = [];
+
+ if (!empty($opts['desde'])) {
+ $where[] = 'DATE(a.created_at) >= ?';
+ $params[] = $opts['desde'];
+ }
+ if (!empty($opts['hasta'])) {
+ $where[] = 'DATE(a.created_at) <= ?';
+ $params[] = $opts['hasta'];
+ }
+ if (!empty($opts['modulo'])) {
+ $where[] = 'a.modulo = ?';
+ $params[] = $opts['modulo'];
+ }
+ if (!empty($opts['accion'])) {
+ $where[] = 'a.accion = ?';
+ $params[] = $opts['accion'];
+ }
+ if (!empty($opts['admin_id'])) {
+ $where[] = 'a.admin_id = ?';
+ $params[] = (int)$opts['admin_id'];
+ }
+ if (!empty($opts['buscar'])) {
+ $where[] = '(a.admin_nombre LIKE ? OR a.detalle LIKE ?)';
+ $like = '%' . $opts['buscar'] . '%';
+ $params[] = $like;
+ $params[] = $like;
+ }
+
+ $whereStr = $where ? 'WHERE ' . implode(' AND ', $where) : '';
+
+ $total = (int)($this->db->fetch(
+ "SELECT COUNT(*) AS n FROM lab_actividad_admin a $whereStr",
+ $params
+ )['n'] ?? 0);
+
+ $pp = max(1, (int)($opts['per_page'] ?? 50));
+ $pag = max(1, (int)($opts['page'] ?? 1));
+ $off = ($pag - 1) * $pp;
+
+ $pParams = $params;
+ $pParams[] = $pp;
+ $pParams[] = $off;
+
+ $data = $this->db->fetchAll("
+ SELECT
+ a.*,
+ u.username AS admin_username
+ FROM lab_actividad_admin a
+ LEFT JOIN admin_users u ON u.id = a.admin_id
+ $whereStr
+ ORDER BY a.created_at DESC
+ LIMIT ? OFFSET ?
+ ", $pParams);
+
+ return [
+ 'data' => $data,
+ 'total' => $total,
+ 'paginas' => (int)ceil($total / $pp),
+ 'pagina' => $pag,
+ ];
+ }
}
diff --git a/lab_actividad.php b/lab_actividad.php
new file mode 100644
index 0000000..bf10cb4
--- /dev/null
+++ b/lab_actividad.php
@@ -0,0 +1,329 @@
+
+
+
+
+
+
+ Log de Actividad — Módulo Lab
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Fecha / Hora |
+ Usuario |
+ Módulo |
+ Acción |
+ Entidad |
+ Detalle |
+ IP |
+
+
+
+
+
+
+
+ Sin actividad para los filtros seleccionados
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lab_configuracion.php b/lab_configuracion.php
index ab4e0b4..3b9cc32 100644
--- a/lab_configuracion.php
+++ b/lab_configuracion.php
@@ -51,6 +51,7 @@ foreach ($rows as $r) { $cfg[$r['clave']] = $r['valor']; }
Enfermeras
Formularios
Reportes
+ Actividad
Configuración
Volver al Bot
diff --git a/lab_dashboard.php b/lab_dashboard.php
index 796d895..c36352b 100644
--- a/lab_dashboard.php
+++ b/lab_dashboard.php
@@ -59,6 +59,7 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['
Enfermeras
Formularios
Reportes
+ Actividad
Configuración
Usuarios
diff --git a/lab_domicilios.php b/lab_domicilios.php
index f21c8b2..095a968 100644
--- a/lab_domicilios.php
+++ b/lab_domicilios.php
@@ -59,6 +59,7 @@ $domIdParam = (int)($_GET['id'] ?? 0);
Reportes
+ Actividad
Configuración
diff --git a/lab_enfermeras.php b/lab_enfermeras.php
index 3b9713e..5a31daf 100644
--- a/lab_enfermeras.php
+++ b/lab_enfermeras.php
@@ -42,6 +42,7 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['
Enfermeras
Formularios
Reportes
+ Actividad
Configuración
Usuarios
diff --git a/lab_formularios.php b/lab_formularios.php
index aaca33d..62bae95 100644
--- a/lab_formularios.php
+++ b/lab_formularios.php
@@ -71,6 +71,7 @@ $puedeEscribir = $esAdmin && hasModuleWrite('lab_formularios');
Reportes
+ Actividad
Configuración
diff --git a/lab_ordenes.php b/lab_ordenes.php
index f578f82..d6214d9 100644
--- a/lab_ordenes.php
+++ b/lab_ordenes.php
@@ -58,6 +58,7 @@ $estadoParam = $_GET['estado'] ?? '';
Reportes
+ Actividad
Configuración
diff --git a/lab_pacientes.php b/lab_pacientes.php
index ff1a08b..b086c00 100644
--- a/lab_pacientes.php
+++ b/lab_pacientes.php
@@ -38,6 +38,7 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['
Enfermeras
Formularios
Reportes
+ Actividad
Configuración
Usuarios
diff --git a/lab_reportes.php b/lab_reportes.php
index ab31e2d..ddacea2 100644
--- a/lab_reportes.php
+++ b/lab_reportes.php
@@ -197,6 +197,7 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['
Enfermeras
Formularios
Reportes
+ Actividad
Configuración
Usuarios
diff --git a/lab_usuarios.php b/lab_usuarios.php
index 8b49a13..82a1116 100644
--- a/lab_usuarios.php
+++ b/lab_usuarios.php
@@ -47,6 +47,7 @@ $systemModules = SYSTEM_MODULES;
Enfermeras
Formularios
Reportes
+ Actividad
Configuración
Usuarios