From 921c6abd8c6fe5d59e4a486eb1b29fd14d27724c Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 25 Mar 2026 14:18:33 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20eliminar=20bloque=20hu=C3=A9rfano=20de?= =?UTF-8?q?=20m=C3=A9todos=20de=20notasManager=20(SyntaxError=20toggle)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enfermero_portal.php | 400 ------------------------------------------- 1 file changed, 400 deletions(-) diff --git a/enfermero_portal.php b/enfermero_portal.php index 0921f0f..306586a 100644 --- a/enfermero_portal.php +++ b/enfermero_portal.php @@ -854,406 +854,6 @@ function renderOrdenesEnfermero(item) { }).join(''); } -function _fmtFechaCorta(s) { - - // ── Toggle sección ──────────────────────────────────────────────────── - async toggle(domId, btn) { - const body = document.getElementById(`notas-body-${domId}`); - const chevron = btn.querySelector('.nota-chevron'); - if (!body) return; - const abrir = body.classList.contains('d-none'); - body.classList.toggle('d-none', !abrir); - chevron?.classList.toggle('open', abrir); - if (abrir && !this._cache[domId]) { - await this.cargar(domId); - } else if (abrir) { - this._renderBody(domId); - } - }, - - // ── Cargar desde API ───────────────────────────────────────────────── - async cargar(domId) { - const body = document.getElementById(`notas-body-${domId}`); - if (!body) return; - body.innerHTML = '
Cargando…
'; - try { - const r = await fetch(`api/lab/get_notas_domicilio.php?domicilio_id=${domId}`); - const d = await r.json(); - if (!d.success) throw new Error(d.error || 'Error al cargar notas'); - this._cache[domId] = { - clinica: d.data.find(n => n.tipo === 'clinica') || null, - libres: d.data.filter(n => n.tipo === 'libre'), - }; - this._renderBody(domId); - // Badge contador - const total = d.data.length; - const badge = document.getElementById(`nota-count-${domId}`); - if (badge) { badge.textContent = total; badge.style.display = total ? '' : 'none'; } - } catch (e) { - if (body) body.innerHTML = `
${esc(e.message)}
`; - } - }, - - // ── Render cuerpo expandido ────────────────────────────────────────── - _renderBody(domId) { - const body = document.getElementById(`notas-body-${domId}`); - if (!body) return; - const pacNac = body.dataset.pacNac || ''; - const menor = this._esmenor(pacNac); - const cache = this._cache[domId] || { clinica: null, libres: [] }; - - body.innerHTML = ` -
- ${this._fichaHTML(cache.clinica, domId, menor)} - ${cache.libres.map(n => this._libreHTML(n)).join('')} - -
`; - }, - - _fichaHTML(nota, domId, menor) { - const vacio = !nota; - const tieneAcud = nota?.acudiente_nombre || nota?.acudiente_documento; - return `
-
-
- Ficha clínica - ${menor === true ? ' · menor de edad' : ''} -
- -
- ${vacio - ? `
Sin información registrada
` - : `
- ${nota.antecedentes ? `
Antecedentes
${esc(nota.antecedentes).replace(/\n/g,'
')}
` : ''} - ${nota.medicamentos ? `
Medicamentos
${esc(nota.medicamentos).replace(/\n/g,'
')}
` : ''} - ${tieneAcud ? `
Acudiente
-
${esc(nota.acudiente_nombre||'—')} · ${esc(nota.acudiente_documento||'—')}
` : ''} -
`} -
`; - }, - - _libreHTML(nota) { - const domId = nota.domicilio_id; - return `
-
-
${esc(nota.titulo||'Nota')}
-
- - -
-
- ${nota.cuerpo ? `
${nota.cuerpo}
` : ''} - ${nota.imagen_path ? `` : ''} -
${_fmtFechaCorta(nota.created_at||'')}
-
`; - }, - - // ── Abrir bottom sheet: Ficha clínica ──────────────────────────────── - abrirClinica(domId) { - this._editDomId = domId; - this._editTipo = 'clinica'; - this._editNota = this._cache[domId]?.clinica || null; - const bodyEl = document.getElementById(`notas-body-${domId}`); - this._editPacNac = bodyEl?.dataset?.pacNac || ''; - const menor = this._esmenor(this._editPacNac); - const nota = this._editNota; - const inner = document.getElementById('nota-sheet-inner'); - - inner.innerHTML = ` -
-
- Ficha clínica -
- -
- -
- - -
-
- - -
- -
-
- Datos del acudiente - ${menor === true - ? 'obligatorio (paciente menor de edad)' - : ' (si aplica)'} -
-
- - -
-
- - -
-
- -
- -
`; - - this._abrirSheet(); - }, - - // ── Abrir bottom sheet: Nota libre nueva ──────────────────────────── - abrirLibre(domId) { - const bodyEl = document.getElementById(`notas-body-${domId}`); - this._editDomId = domId; - this._editTipo = 'libre'; - this._editNota = null; - this._editPacNac = bodyEl?.dataset?.pacNac || ''; - this._renderFormLibre(null); - this._abrirSheet(); - }, - - // ── Abrir bottom sheet: Editar nota libre ─────────────────────────── - abrirEditarLibre(domId, notaId) { - const nota = (this._cache[domId]?.libres||[]).find(n => +n.id === +notaId); - const bodyEl = document.getElementById(`notas-body-${domId}`); - this._editDomId = domId; - this._editTipo = 'libre'; - this._editNota = nota || null; - this._editPacNac = bodyEl?.dataset?.pacNac || ''; - this._renderFormLibre(nota); - this._abrirSheet(); - }, - - _renderFormLibre(nota) { - const inner = document.getElementById('nota-sheet-inner'); - inner.innerHTML = ` -
-
- ${nota ? 'Editar nota' : 'Nueva nota'} -
- -
- -
- - -
- -
- -
- - - - - - -
-
-
- -
- -
- ${nota?.imagen_path ? `
- - -
` : ''} -
- - -
- - `; - - // Cargar HTML en contenteditable - if (nota?.cuerpo) { - requestAnimationFrame(() => { - const el = document.getElementById('nl-cuerpo'); - if (el) el.innerHTML = nota.cuerpo; - }); - } - }, - - _fmt(cmd) { document.getElementById('nl-cuerpo')?.focus(); document.execCommand(cmd, false, null); }, - _insertLista() { document.getElementById('nl-cuerpo')?.focus(); document.execCommand('insertUnorderedList', false, null); }, - _limpiarFormato() { document.getElementById('nl-cuerpo')?.focus(); document.execCommand('removeFormat', false, null); }, - - _previsualizarImg(input) { - if (!input.files?.[0]) return; - const reader = new FileReader(); - reader.onload = e => { - const prev = document.getElementById('nl-preview'); - if (prev) prev.innerHTML = `
- - -
`; - }; - reader.readAsDataURL(input.files[0]); - }, - - _quitarImg() { - document.getElementById('nl-preview').innerHTML = ''; - const inp = document.getElementById('nl-img-input'); - if (inp) inp.value = ''; - const h = document.getElementById('nl-img-guardada'); - if (h) h.value = ''; - }, - - // ── Guardar ────────────────────────────────────────────────────────── - async guardar() { - const btnId = this._editTipo === 'clinica' ? 'nc-guardar-btn' : 'nl-guardar-btn'; - const btn = document.getElementById(btnId); - const labs = { clinica: 'Guardar ficha clínica', libre: 'Guardar nota' }; - if (btn) { btn.disabled = true; btn.innerHTML = 'Guardando…'; } - - try { - let imagenPath = null; - - if (this._editTipo === 'libre') { - const imgInput = document.getElementById('nl-img-input'); - if (imgInput?.files?.[0]) { - imagenPath = await this._subirImagen(imgInput.files[0]); - } else { - imagenPath = document.getElementById('nl-img-guardada')?.value || null; - } - } - - let payload = { domicilio_id: this._editDomId, tipo: this._editTipo }; - if (this._editNota?.id) payload.id = +this._editNota.id; - - if (this._editTipo === 'clinica') { - payload.antecedentes = document.getElementById('nc-antecedentes')?.value.trim() || null; - payload.medicamentos = document.getElementById('nc-medicamentos')?.value.trim() || null; - const menor = this._esmenor(this._editPacNac); - const acNombre = document.getElementById('nc-acud-nombre')?.value.trim() || null; - const acDoc = document.getElementById('nc-acud-doc')?.value.trim() || null; - if (menor === true && (!acNombre || !acDoc)) { - alert('El nombre y documento del acudiente son obligatorios para pacientes menores de edad.'); - if (btn) { btn.disabled = false; btn.innerHTML = `${labs.clinica}`; } - return; - } - payload.acudiente_nombre = acNombre; - payload.acudiente_documento = acDoc; - } else { - const titulo = document.getElementById('nl-titulo')?.value.trim(); - if (!titulo) { - alert('El título de la nota es obligatorio.'); - if (btn) { btn.disabled = false; btn.innerHTML = `${labs.libre}`; } - return; - } - payload.titulo = titulo; - payload.cuerpo = document.getElementById('nl-cuerpo')?.innerHTML.trim() || null; - payload.imagen_path = imagenPath; - } - - const r = await fetch('api/lab/save_nota_domicilio.php', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(payload), - }); - const d = await r.json(); - if (!d.success) throw new Error(d.error || 'Error al guardar'); - - delete this._cache[this._editDomId]; - this.cerrarSheet(); - await this.cargar(this._editDomId); - } catch (e) { - alert('Error: ' + e.message); - if (btn) { btn.disabled = false; btn.innerHTML = `Reintentar`; } - } - }, - - async _subirImagen(file) { - const fd = new FormData(); - fd.append('file', file); - const r = await fetch('api/lab/upload_nota_imagen.php', { method: 'POST', body: fd }); - const d = await r.json(); - if (!d.success) throw new Error(d.error || 'Error al subir imagen'); - return d.imagen_path; - }, - - async eliminar(notaId, domId) { - if (!confirm('¿Eliminar esta nota?')) return; - try { - const r = await fetch('api/lab/delete_nota_domicilio.php', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ id: notaId }), - }); - const d = await r.json(); - if (!d.success) throw new Error(d.error || 'Error al eliminar'); - delete this._cache[domId]; - await this.cargar(domId); - } catch (e) { - alert('Error: ' + e.message); - } - }, - - _abrirSheet() { - const sheet = document.getElementById('nota-sheet'); - const backdrop = document.getElementById('nota-backdrop'); - if (!sheet || !backdrop) return; - sheet.style.transform = 'translateY(100%)'; - sheet.style.transition = ''; - sheet.style.display = 'block'; - backdrop.style.display = 'block'; - requestAnimationFrame(() => { - sheet.style.transition = 'transform .32s cubic-bezier(.4,0,.2,1)'; - sheet.style.transform = 'translateY(0)'; - }); - }, - - cerrarSheet() { - const sheet = document.getElementById('nota-sheet'); - const backdrop = document.getElementById('nota-backdrop'); - if (!sheet) return; - sheet.style.transition = 'transform .28s cubic-bezier(.4,0,.2,1)'; - sheet.style.transform = 'translateY(100%)'; - setTimeout(() => { - sheet.style.display = 'none'; - if (backdrop) backdrop.style.display = 'none'; - }, 300); - }, -}; - function _fmtFechaCorta(s) { if (!s) return ''; return new Date(s).toLocaleString('es-CO', { day:'2-digit', month:'short', hour:'2-digit', minute:'2-digit' });