diff --git a/api/lab/eps.php b/api/lab/eps.php new file mode 100644 index 0000000..c651e23 --- /dev/null +++ b/api/lab/eps.php @@ -0,0 +1,64 @@ +query($sql)->fetchAll(PDO::FETCH_ASSOC); + jsonOk(['eps' => $rows]); +} + +requireMethod('POST'); +requireAdmin(); + +$body = inputJson(); +$action = trim($body['action'] ?? ''); + +if ($action === 'save') { + $nombre = trim($body['nombre'] ?? ''); + $id = (int)($body['id'] ?? 0); + if (!$nombre) jsonError('nombre requerido.'); + if (strlen($nombre) > 120) jsonError('nombre demasiado largo (máx 120).'); + + if ($id) { + $pdo->prepare('UPDATE lab_eps SET nombre = ? WHERE id = ?')->execute([$nombre, $id]); + jsonOk(['id' => $id], 'EPS actualizada.'); + } else { + $st = $pdo->prepare('INSERT INTO lab_eps (nombre) VALUES (?)'); + try { + $st->execute([$nombre]); + } catch (\PDOException $e) { + if ($e->getCode() == 23000) jsonError('Ya existe una EPS con ese nombre.'); + throw $e; + } + jsonOk(['id' => (int)$pdo->lastInsertId()], 'EPS creada.'); + } +} + +if ($action === 'toggle') { + $id = (int)($body['id'] ?? 0); + if (!$id) jsonError('id requerido.'); + $pdo->prepare('UPDATE lab_eps SET activa = NOT activa WHERE id = ?')->execute([$id]); + jsonOk([], 'Estado actualizado.'); +} + +if ($action === 'delete') { + $id = (int)($body['id'] ?? 0); + if (!$id) jsonError('id requerido.'); + $uso = $pdo->prepare('SELECT COUNT(*) FROM lab_pacientes WHERE eps = (SELECT nombre FROM lab_eps WHERE id = ?)'); + $uso->execute([$id]); + if ((int)$uso->fetchColumn() > 0) jsonError('No se puede eliminar: hay pacientes con esta EPS. Desactívela en su lugar.'); + $pdo->prepare('DELETE FROM lab_eps WHERE id = ?')->execute([$id]); + jsonOk([], 'EPS eliminada.'); +} + +jsonError('action inválida.'); diff --git a/modules/lab_eps/module.php b/modules/lab_eps/module.php new file mode 100644 index 0000000..dfb80e6 --- /dev/null +++ b/modules/lab_eps/module.php @@ -0,0 +1,12 @@ + 'lab_eps', + 'name' => 'EPS', + 'icon' => 'fas fa-hospital', + 'category' => 'lab', + 'route' => '/lab_eps.php', + 'is_active' => true, + 'sort_order' => 22, + 'oleada' => 0, + 'description' => 'Gestión de EPS y aseguradoras', + 'links' => [['name' => 'EPS', 'icon' => 'fas fa-hospital', 'route' => '/lab_eps.php']], +]; diff --git a/modules/lab_eps/views/index.php b/modules/lab_eps/views/index.php new file mode 100644 index 0000000..032d610 --- /dev/null +++ b/modules/lab_eps/views/index.php @@ -0,0 +1,178 @@ + + + + + +EPS — <?= htmlspecialchars($_cfg['empresa_nombre'] ?? 'ERP') ?> + + + + + + + + +
+
+
EPS / Aseguradoras
+ +
+ +
+
+ + + + + + + + + + + +
NombreEstadoAcciones
Cargando…
+
+
+
+ + + + + + + diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index 2dbca7b..1bc9bb5 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -1000,7 +1000,9 @@ document.addEventListener('DOMContentLoaded', function() {
- +
@@ -2324,6 +2326,21 @@ function fmt(n) { const BASE_URL_API_LAB = '/api/lab/'; +// ── Cargar EPS una vez al inicio ───────────────────────────── +(async function() { + try { + const r = await fetch(BASE_URL_API_LAB + 'eps.php?action=list&solo_activas=1'); + const j = await r.json(); + if (!j.ok) return; + const sel = document.getElementById('mpac-eps'); + (j.eps || []).forEach(e => { + const o = document.createElement('option'); + o.value = e.nombre; o.textContent = e.nombre; + sel.appendChild(o); + }); + } catch(_) {} +})(); + function escHtml(str) { const d = document.createElement('div'); d.appendChild(document.createTextNode(String(str)));