Fix internacion lookup, persistence and fallback patient resolution
This commit is contained in:
@@ -94,6 +94,7 @@ export function useHospitalStore() {
|
||||
if (mounted && body) {
|
||||
const defaults = defaultState();
|
||||
const storedUser = sessionStorage.getItem('hospital_user');
|
||||
const storedInternacionId = sessionStorage.getItem('hospital_current_internacion_id');
|
||||
const currentUser = storedUser ? JSON.parse(storedUser) : null;
|
||||
const normalized = {
|
||||
...defaults,
|
||||
@@ -103,6 +104,7 @@ export function useHospitalStore() {
|
||||
atb: body.atb || [],
|
||||
glucemias: body.glucemias || [],
|
||||
movimientosIndicaciones: body.movimientosIndicaciones || [],
|
||||
currentInternacionId: storedInternacionId || body.currentInternacionId || null,
|
||||
currentUser,
|
||||
isAuthenticated: !!currentUser,
|
||||
};
|
||||
@@ -1237,15 +1239,24 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
|
||||
// Funciones de utilidad para consultas
|
||||
const getPacienteById = useCallback((id: string) => {
|
||||
return state.pacientes.find(p => p.id === id);
|
||||
if (!id) return undefined;
|
||||
const target = String(id).trim().toLowerCase();
|
||||
return state.pacientes.find(p =>
|
||||
(p.id && String(p.id).trim().toLowerCase() === target) ||
|
||||
(p.dni && String(p.dni).trim().toLowerCase() === target)
|
||||
);
|
||||
}, [state.pacientes]);
|
||||
|
||||
const getCamaById = useCallback((id: string) => {
|
||||
return state.camas.find(c => c.id === id);
|
||||
if (!id) return undefined;
|
||||
const target = String(id).trim().toLowerCase();
|
||||
return state.camas.find(c => c.id && String(c.id).trim().toLowerCase() === target);
|
||||
}, [state.camas]);
|
||||
|
||||
const getInternacionById = useCallback((id: string) => {
|
||||
return state.internaciones.find(i => i.id === id);
|
||||
if (!id) return undefined;
|
||||
const target = String(id).trim().toLowerCase();
|
||||
return state.internaciones.find(i => i.id && String(i.id).trim().toLowerCase() === target);
|
||||
}, [state.internaciones]);
|
||||
|
||||
const getInternacionActivaByPaciente = useCallback((pacienteId: string) => {
|
||||
@@ -1309,6 +1320,11 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
|
||||
// Current internacion selection (for HC page)
|
||||
const setCurrentInternacion = useCallback((id?: string | null) => {
|
||||
if (id) {
|
||||
sessionStorage.setItem('hospital_current_internacion_id', id);
|
||||
} else {
|
||||
sessionStorage.removeItem('hospital_current_internacion_id');
|
||||
}
|
||||
setState(prev => ({ ...prev, currentInternacionId: id ?? null }));
|
||||
}, []);
|
||||
|
||||
@@ -1434,5 +1450,6 @@ const actualizarInternacion = useCallback(async (internacionId: string, datos: P
|
||||
getCamaGrupoId,
|
||||
getInternacionGrupoId,
|
||||
getPacienteGrupoId,
|
||||
isLoaded,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user