From d30dbab8f0a637beb35376ba227107fd89cc7b4b Mon Sep 17 00:00:00 2001 From: Sergio Nicolas Lavaise Date: Fri, 24 Apr 2026 01:30:17 -0300 Subject: [PATCH] =?UTF-8?q?Fix:=20corregir=20permisos=20en=20Cultivos=20y?= =?UTF-8?q?=20limpiar=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Agregar canEdit prop a Cultivos.tsx para controlar botones - Reescribir Cultivos.tsx eliminando código duplicado - Corregir App.tsx para que cultivos case funcione correctamente - Hacer patient prop opcional en Cultivos.tsx --- server/data/hospital.db-journal | Bin 0 -> 4616 bytes src/App.tsx | 24 +- src/sections/Cultivos.tsx | 798 +++++++++++++------------------- 3 files changed, 344 insertions(+), 478 deletions(-) create mode 100644 server/data/hospital.db-journal diff --git a/server/data/hospital.db-journal b/server/data/hospital.db-journal new file mode 100644 index 0000000000000000000000000000000000000000..0dec0ad9733708af234cfb288792a5a9914816d2 GIT binary patch literal 4616 zcmeHJ%WC9C6!nDJ2C_-WQV0eDY00HW>(RS*kHAzd>_xO8c;E{nx20lIpe);mrQ|I^3FGM|K4KAG=H`tkb zZ|oT+jPi!o_TbeUn~N%w)E?L`Xig;~!tU94M$3}r0;Gp{j#*7Xm~#g2LF{`mN>dON zlw9B=0IL+7y6mNC;2_`eA~>$;k4p9u9vfQHLU4V>i-HKDI8g{Wlavr9INTczcZMLE z%629um`_{AsZu!p8l_7RY-c4_0g` z{J}ZMhjI#942^Jc1l3 zacvoqXL!m*-M~S2Q+YCzEzMLYD$%gH7ztjtWuu5%o={#;2^`~mNEYNS&&&Ys{?9#4 z;Nq+Mi&QpvM9V~6+*!qINwp6~Vj%NEdFP>RFM0+NmF#mJdyq~}CLq#*MLtc!A}gE_ zXV?kTG;^{fO&wB%5k*lPrMXT(0$zi+4bY$>N#~+$Rif$OfuO{hkXYrA=nCy2;ndz6 z?&`vVP${PKC9cF3?b2(XR`5w88I)tsp5szTdk{o!zh}36Q2@$$S}T13J`%EmtiSB3 zwy=gHrlrUjSH3QAJl~BBoauIcxB=85Z3)z51Jvk3 z!oL}xp03mb^V2n*ZUC?c*+(m8hAZ$58>*Y(y3>g>=tuXMaSPxcPeuR%?R714kQN!BxYsTKEUz7ihK*0KIf_f(5tr`=AO

KAnaR;ldY4ZqNzCZi*@;|?X Bfm;9o literal 0 HcmV?d00001 diff --git a/src/App.tsx b/src/App.tsx index 1225c7a..4b909f2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -113,21 +113,29 @@ function AppContent() { getPacienteById={store.getPacienteById} /> ); - case 'cultivos': + case 'cultivos': { + const internacion = store.getInternacionById(store.currentInternacionId || ''); + const paciente = internacion ? store.getPacienteById(internacion.pacienteId) : undefined; + if (!internacion || !paciente) { + return ( +

+

Internación no encontrada

+ +
+ ); + } return ( c.pacienteId === paciente.id)} + patient={paciente} + internacionId={internacion.id} onAgregarCultivo={store.agregarCultivo} onActualizarCultivo={store.actualizarCultivo} onEliminarCultivo={store.eliminarCultivo} - getPacienteById={store.getPacienteById} - getCamaById={store.getCamaById} - getInternacionActivaByPaciente={store.getInternacionActivaByPaciente} + canEdit={store.canEditInternacion(internacion.id)} /> ); + } case 'historiaclinica': { const internacion = store.getInternacionById(store.currentInternacionId || ''); const paciente = internacion ? store.getPacienteById(internacion.pacienteId) : undefined; diff --git a/src/sections/Cultivos.tsx b/src/sections/Cultivos.tsx index 79b4566..661ab18 100644 --- a/src/sections/Cultivos.tsx +++ b/src/sections/Cultivos.tsx @@ -11,28 +11,22 @@ import type { Cultivo, Paciente, Cama, Internacion } from '@/types'; interface CultivosProps { cultivos: Cultivo[]; - pacientes: Paciente[]; - internaciones: Internacion[]; - camas: Cama[]; + patient?: Paciente; + internacionId: string; onAgregarCultivo: (cultivo: Omit) => void; onActualizarCultivo?: (id: string, datos: Partial) => void; onEliminarCultivo: (id: string) => void; - getPacienteById: (id: string) => Paciente | undefined; - getCamaById: (id: string) => Cama | undefined; - getInternacionActivaByPaciente: (pacienteId: string) => Internacion | undefined; + canEdit: boolean; } export function Cultivos({ cultivos, - pacientes, - internaciones, - camas, + patient, + internacionId, onAgregarCultivo, onActualizarCultivo, onEliminarCultivo, - getPacienteById, - getCamaById, - getInternacionActivaByPaciente, + canEdit, }: CultivosProps) { const [busqueda, setBusqueda] = useState(''); const [filtroEstado, setFiltroEstado] = useState<'todos' | 'NAF/Pendiente' | 'Parcial' | 'Positivo' | 'Negativo'>('todos'); @@ -40,91 +34,62 @@ export function Cultivos({ const [dialogoParcialAbierto, setDialogoParcialAbierto] = useState(false); const [dialogoDefinitivoAbierto, setDialogoDefinitivoAbierto] = useState(false); const [cultivoSeleccionado, setCultivoSeleccionado] = useState(null); - - const [pacienteSeleccionado, setPacienteSeleccionado] = useState(''); - const [busquedaPaciente, setBusquedaPaciente] = useState(''); + const [fechaToma, setFechaToma] = useState(new Date().toISOString().split('T')[0]); const [protocolo, setProtocolo] = useState(''); const [tipoMuestra, setTipoMuestra] = useState('HMCx2'); const [observaciones, setObservaciones] = useState(''); - + const [fechaResultado, setFechaResultado] = useState(new Date().toISOString().split('T')[0]); const [estadoResultado, setEstadoResultado] = useState('Positivo'); const [germen, setGermen] = useState(''); const [sensible, setSensible] = useState(''); const [resistente, setResistente] = useState(''); - const resetFormularioNuevo = () => { - setPacienteSeleccionado(''); - setBusquedaPaciente(''); + const cultivosFiltrados = cultivos.filter(c => { + if (filtroEstado !== 'todos' && c.estado !== filtroEstado) return false; + if (busqueda) { + const term = busqueda.toLowerCase(); + return ( + c.protocolo?.toLowerCase().includes(term) || + c.germen?.toLowerCase().includes(term) || + c.tipoMuestra.toLowerCase().includes(term) + ); + } + return true; + }); + + const getEstadoColor = (estado: string) => { + switch (estado) { + case 'NAF/Pendiente': return 'bg-amber-100 text-amber-800'; + case 'Parcial': return 'bg-orange-100 text-orange-800'; + case 'Positivo': return 'bg-red-100 text-red-800'; + case 'Negativo': return 'bg-green-100 text-green-800'; + default: return 'bg-gray-100 text-gray-800'; + } + }; + + const getEstadoLabel = (estado: string) => { + switch (estado) { + case 'NAF/Pendiente': return 'NAF'; + case 'Parcial': return 'Parcial'; + case 'Positivo': return 'Positivo'; + case 'Negativo': return 'Negativo'; + default: return estado; + } + }; + + const abrirNuevo = () => { + setCultivoSeleccionado(null); setFechaToma(new Date().toISOString().split('T')[0]); setProtocolo(''); setTipoMuestra('HMCx2'); setObservaciones(''); - }; - - const pacientesFiltrados = pacientes.filter(p => { - if (!busquedaPaciente) return true; - const texto = `${p.apellido} ${p.nombre} ${p.dni}`.toLowerCase(); - return texto.includes(busquedaPaciente.toLowerCase()); - }); - - const resetFormularioResultado = () => { - setFechaResultado(new Date().toISOString().split('T')[0]); - setEstadoResultado('Positivo'); - setGermen(''); - setSensible(''); - setResistente(''); - setCultivoSeleccionado(null); - }; - - const handleAgregar = () => { - if (pacienteSeleccionado && fechaToma && tipoMuestra) { - onAgregarCultivo({ - pacienteId: pacienteSeleccionado, - fechaToma, - protocolo: protocolo || undefined, - tipoMuestra, - observaciones: observaciones || undefined, - estado: 'NAF/Pendiente', - }); - resetFormularioNuevo(); - setDialogoNuevoAbierto(false); - } - }; - - const handleParcial = () => { - if (cultivoSeleccionado && onActualizarCultivo && germen) { - onActualizarCultivo(cultivoSeleccionado.id, { - estado: 'Parcial', - protocolo: protocolo || undefined, - germen: germen || undefined, - sensible: sensible || undefined, - resistente: resistente || undefined, - }); - resetFormularioResultado(); - setDialogoParcialAbierto(false); - } - }; - - const handleDefinitivo = () => { - if (cultivoSeleccionado && onActualizarCultivo) { - onActualizarCultivo(cultivoSeleccionado.id, { - fechaResultado, - protocolo: protocolo || undefined, - estado: estadoResultado, - germen: germen || undefined, - sensible: sensible || undefined, - resistente: resistente || undefined, - }); - resetFormularioResultado(); - setDialogoDefinitivoAbierto(false); - } + setDialogoNuevoAbierto(true); }; const abrirParcial = (cultivo: Cultivo) => { setCultivoSeleccionado(cultivo); - setProtocolo(cultivo.protocolo || ''); setGermen(cultivo.germen || ''); setSensible(cultivo.sensible || ''); setResistente(cultivo.resistente || ''); @@ -133,446 +98,339 @@ export function Cultivos({ const abrirDefinitivo = (cultivo: Cultivo) => { setCultivoSeleccionado(cultivo); - setProtocolo(cultivo.protocolo || ''); - setFechaResultado(cultivo.fechaResultado || new Date().toISOString().split('T')[0]); - setEstadoResultado(cultivo.estado === 'Parcial' || cultivo.estado === 'Positivo' ? 'Positivo' : cultivo.estado); + setFechaResultado(new Date().toISOString().split('T')[0]); + setEstadoResultado(cultivo.estado === 'Parcial' ? 'Positivo' : cultivo.estado); setGermen(cultivo.germen || ''); setSensible(cultivo.sensible || ''); setResistente(cultivo.resistente || ''); setDialogoDefinitivoAbierto(true); }; - const getEstadoColor = (estado: Cultivo['estado']) => { - switch (estado) { - case 'NAF/Pendiente': return 'bg-amber-100 text-amber-800'; - case 'Parcial': return 'bg-orange-100 text-orange-800'; - case 'Positivo': return 'bg-red-100 text-red-800'; - case 'Negativo': return 'bg-green-100 text-green-800'; + const guardarNuevo = () => { + if (!protocolo.trim()) return; + onAgregarCultivo({ + pacienteId: patient.id, + internacionId, + fechaToma, + protocolo, + tipoMuestra, + observaciones: observaciones || undefined, + estado: 'NAF/Pendiente', + }); + setDialogoNuevoAbierto(false); + }; + + const guardarParcial = () => { + if (!cultivoSeleccionado || !germen.trim()) return; + if (onActualizarCultivo) { + onActualizarCultivo(cultivoSeleccionado.id, { + estado: 'Parcial', + germen, + sensible: sensible || undefined, + resistente: resistente || undefined, + }); } + setDialogoParcialAbierto(false); }; - const getEstadoLabel = (estado: Cultivo['estado']) => { - switch (estado) { - case 'NAF/Pendiente': return 'NAF/Pendiente'; - case 'Parcial': return 'Parcial'; - case 'Positivo': return 'Positivo'; - case 'Negativo': return 'Negativo Final'; + const guardarDefinitivo = () => { + if (!cultivoSeleccionado) return; + if (onActualizarCultivo) { + onActualizarCultivo(cultivoSeleccionado.id, { + estado: estadoResultado, + fechaResultado, + germen: cultivoSeleccionado.germen, + sensible: cultivoSeleccionado.sensible, + resistente: cultivoSeleccionado.resistente, + }); } + setDialogoDefinitivoAbierto(false); }; - const getNumeroCama = (pacienteId: string): string | null => { - const internacion = getInternacionActivaByPaciente(pacienteId); - if (!internacion) return null; - const cama = getCamaById(internacion.camaId); - return cama ? cama.numero : null; + const getNumeroCama = (pacienteId: string) => { + return ''; }; - const cultivosFiltrados = cultivos.filter(c => { - const paciente = getPacienteById(c.pacienteId); - const textoBusqueda = paciente ? `${paciente.apellido} ${paciente.nombre} ${paciente.dni}`.toLowerCase() : ''; - const coincideBusqueda = !busqueda || textoBusqueda.includes(busqueda.toLowerCase()); - const coincideEstado = filtroEstado === 'todos' || c.estado === filtroEstado; - return coincideBusqueda && coincideEstado; - }).sort((a, b) => new Date(b.fechaToma).getTime() - new Date(a.fechaToma).getTime()); - return ( -
-
-
-

Cultivos

-

Gestión de cultivos microbiológicos y antibiogramas

+
+
+
+
+ + setBusqueda(e.target.value)} + className="pl-8" + /> +
+
- - - - - - - Nuevo Cultivo - -
- {!pacienteSeleccionado ? ( -
- - setBusquedaPaciente(e.target.value)} - placeholder="Ingrese apellido, nombre o DNI..." - autoFocus - /> - {busquedaPaciente && ( -
- {pacientesFiltrados.length === 0 ? ( -

No se encontraron pacientes

- ) : ( - pacientesFiltrados.map(p => ( - - )) - )} + {canEdit && ( + + )} +
+ +
+ {cultivosFiltrados.map((cultivo) => ( + + +
+
+
+
+
- )} -
- ) : ( -
- - {(() => { - const p = pacientes.find(x => x.id === pacienteSeleccionado); - return p ? `${p.apellido}, ${p.nombre} - DNI: ${p.dni}` : ''; - })()} - - -
- )} -
-
- - setFechaToma(e.target.value)} /> -
-
- - setProtocolo(e.target.value)} placeholder="N° Protocolo" /> +
+

+ {patient ? `${patient.apellido}, ${patient.nombre}` : 'Paciente no encontrado'} +

+
+ + + {cultivo.fechaToma} + + {cultivo.tipoMuestra} + + {getEstadoLabel(cultivo.estado)} + +
+
+
+
+ {canEdit && onActualizarCultivo && cultivo.estado === 'NAF/Pendiente' && ( + + )} + {canEdit && onActualizarCultivo && (cultivo.estado === 'Positivo' || cultivo.estado === 'Negativo') && ( + + )} + {canEdit && onActualizarCultivo && cultivo.estado === 'Parcial' && ( + + )} + {canEdit && ( + + )} +
+ + {cultivo.protocolo && ( +

+ Protocolo: {cultivo.protocolo} +

+ )} + {cultivo.observaciones && ( +

+ {cultivo.observaciones} +

+ )} + + {cultivo.estado === 'Parcial' && cultivo.germen && ( +
+

+ + PARCIAL - Germen: {cultivo.germen} +

+ {(cultivo.sensible || cultivo.resistente) && ( +
+ {cultivo.sensible && ( +

Sensible: {cultivo.sensible}

+ )} + {cultivo.resistente && ( +

Resistente: {cultivo.resistente}

+ )} +
+ )} +
+ )} + + {cultivo.estado === 'Positivo' && cultivo.germen && ( +
+

+ + Germen: {cultivo.germen} +

+ {cultivo.fechaResultado && ( +

+ Resultado: {cultivo.fechaResultado} +

+ )} + {(cultivo.sensible || cultivo.resistente) && ( +
+ {cultivo.sensible && ( +
+

Sensible a:

+

{cultivo.sensible}

+
+ )} + {cultivo.resistente && ( +
+

Resistente a:

+

{cultivo.resistente}

+
+ )} +
+ )} +
+ )} + + {cultivo.estado === 'Negativo' && ( +
+

+ + Cultivo Negativo +

+
+ )}
-
- - setFechaToma(e.target.value)} /> +
+
+ +
-
- -