-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpendiente-evolucion.html
More file actions
212 lines (174 loc) · 4.72 KB
/
pendiente-evolucion.html
File metadata and controls
212 lines (174 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Pendientes por evolucionar</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="module">
import { createClient } from "https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm";
const supabase = createClient(
"https://dmcfrmpqlkrqbpjhrfyo.supabase.co",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRtY2ZybXBxbGtycWJwamhyZnlvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjI5MzU0MDIsImV4cCI6MjA3ODUxMTQwMn0.YY_6t_lCTs5mK-a_eEdBFa6l9_NBM3B4YDtWOXayCBE"
);
let datosGlobales = [];
/* =========================
UTILIDADES
========================= */
function diffDias(fecha) {
const hoy = new Date().toISOString().slice(0,10);
return Math.floor(
(new Date(hoy) - new Date(fecha)) / 86400000
);
}
/* =========================
CARGA
========================= */
async function cargarPendientes() {
const { data, error } = await supabase
.from("pendientes_evolucion")
.select("*")
.order("fecha", { ascending: false });
if (error) {
console.error(error);
mostrarError();
return;
}
datosGlobales = data || [];
cargarFiltroProfesional(datosGlobales);
render(datosGlobales);
}
/* =========================
FILTRO PROFESIONAL
========================= */
function cargarFiltroProfesional(lista) {
const select = document.getElementById("filtroProfesional");
select.innerHTML = `<option value="">Todos los profesionales</option>`;
const profesionales = [...new Set(lista.map(r => r.nombre_profesional))];
profesionales.forEach(p => {
const opt = document.createElement("option");
opt.value = p;
opt.textContent = p;
select.appendChild(opt);
});
}
function aplicarFiltro() {
const profesional = document.getElementById("filtroProfesional").value;
const filtrados = profesional
? datosGlobales.filter(r => r.nombre_profesional === profesional)
: datosGlobales;
render(filtrados);
}
/* =========================
RENDER
========================= */
function render(lista) {
const tbody = document.querySelector("tbody");
tbody.innerHTML = "";
let hoy = 0, historicos = 0;
lista.forEach(p => {
const atraso = diffDias(p.fecha);
let clase = "", label = "";
if (atraso === 0) {
clase = "hoy"; label = "HOY"; hoy++;
} else if (atraso === 1) {
clase = "amarillo"; label = "1 día"; historicos++;
} else {
clase = "rojo"; label = `${atraso} días`; historicos++;
}
const url = `https://cacg1022.github.io/ODONTOLOGIA/evoluciones.html?auto=1&cedula=${p.documento_paciente}`;
tbody.insertAdjacentHTML("beforeend", `
<tr class="${clase}">
<td>${p.fecha}</td>
<td>${p.hora}</td>
<td>${p.nombre_paciente}</td>
<td>${p.documento_paciente}</td>
<td>${p.nombre_profesional}</td>
<td>${label}</td>
<td>
<a class="btn" href="${url}" target="_blank">
Ir a evolucionar
</a>
</td>
</tr>
`);
});
document.getElementById("hoy").textContent = hoy;
document.getElementById("historicos").textContent = historicos;
}
function mostrarError() {
document.querySelector("tbody").innerHTML =
`<tr><td colspan="7">Error cargando pendientes</td></tr>`;
}
window.onload = cargarPendientes;
</script>
<style>
body { font-family: system-ui; background:#f6f8fb; padding:20px; }
h1 { margin-bottom:12px; }
.controls {
display:flex;
gap:12px;
align-items:center;
margin-bottom:14px;
}
select {
padding:8px 10px;
border-radius:8px;
border:1px solid #ccc;
}
.cards { display:flex; gap:12px; margin-bottom:14px; }
.card { background:#fff; padding:12px 18px; border-radius:12px; }
table {
width:100%;
border-collapse:collapse;
background:#fff;
border-radius:12px;
overflow:hidden;
}
th,td {
padding:10px;
border-bottom:1px solid #eee;
text-align:left;
}
tr.hoy { background:#e6f7ff; }
tr.amarillo { background:#fff4cc; }
tr.rojo { background:#ffe4e4; }
.btn {
padding:6px 10px;
background:#2563eb;
color:#fff;
text-decoration:none;
border-radius:6px;
font-size:13px;
}
.btn:hover {
background:#1e40af;
}
</style>
</head>
<body>
<h1>🚨 Pendientes por evolucionar</h1>
<div class="controls">
<select id="filtroProfesional" onchange="aplicarFiltro()">
<option value="">Cargando profesionales...</option>
</select>
</div>
<div class="cards">
<div class="card">Pendientes hoy: <b id="hoy">0</b></div>
<div class="card">Pendientes históricos: <b id="historicos">0</b></div>
</div>
<table>
<thead>
<tr>
<th>Fecha</th>
<th>Hora</th>
<th>Paciente</th>
<th>Documento</th>
<th>Profesional</th>
<th>Atraso</th>
<th>Acción</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>