From df2dcf139f478b6d6ab43f31f8083a28bf68f437 Mon Sep 17 00:00:00 2001 From: Sergio Nicolas Lavaise Date: Mon, 13 Apr 2026 11:24:42 -0300 Subject: [PATCH] =?UTF-8?q?Fix:=20C=C3=A1lculo=20autom=C3=A1tico=20de=20es?= =?UTF-8?q?tado=20de=20laboratorio=20(Normal/Alto/Bajo)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sections/HistoriaClinica.tsx | 66 ++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/sections/HistoriaClinica.tsx b/src/sections/HistoriaClinica.tsx index 015c988..e4bdbab 100644 --- a/src/sections/HistoriaClinica.tsx +++ b/src/sections/HistoriaClinica.tsx @@ -78,6 +78,38 @@ const PARAMETROS_COMUNES: Record 'RIN': { unidad: '', referencia: '0.8-1.2' }, }; +const RANGOS_LABORATORIO: Record = { + 'Hematocrito': { min: 36, max: 46 }, + 'Hemoglobina': { min: 12, max: 16 }, + 'Leucocitos': { min: 4.5, max: 11 }, + 'Plaquetas': { min: 150, max: 450 }, + 'Glucemia': { min: 70, max: 100 }, + 'Urea': { min: 17, max: 43 }, + 'Creatinina': { min: 0.7, max: 1.3 }, + 'Sodio': { min: 135, max: 145 }, + 'Potasio': { min: 3.5, max: 5.0 }, + 'Cloro': { min: 98, max: 106 }, + 'Bilirrubina Total': { min: 0.1, max: 1.2 }, + 'Bilirrubina Directa': { min: 0, max: 0.3 }, + 'GOT': { min: 10, max: 40 }, + 'GPT': { min: 10, max: 40 }, + 'Tiempo de Protrombina': { min: 12, max: 14 }, + 'KPTT': { min: 25, max: 35 }, + 'INR': { min: 0.8, max: 1.2 }, +}; + +function calcularEstadoLaboratorio(parametro: string, valor: string): 'Normal' | 'Alto' | 'Bajo' { + const rango = RANGOS_LABORATORIO[parametro]; + if (!rango) return 'Normal'; + + const num = parseFloat(valor); + if (isNaN(num)) return 'Normal'; + + if (num < rango.min) return 'Bajo'; + if (num > rango.max) return 'Alto'; + return 'Normal'; +} + export function HistoriaClinica({ internacion, paciente, @@ -421,23 +453,23 @@ function SeccionLaboratorios({ lab, patientId, add, update, del }: { const buildResultados = (): ResultadoLaboratorio[] => { const res: ResultadoLaboratorio[] = []; - if (hto) res.push({ parametro: 'Hematocrito', valor: hto, unidad: '%', estado: 'Normal' }); - if (hb) res.push({ parametro: 'Hemoglobina', valor: hb, unidad: 'g/dL', estado: 'Normal' }); - if (gb) res.push({ parametro: 'Leucocitos', valor: gb, unidad: '/mm3', estado: 'Normal' }); - if (plaq) res.push({ parametro: 'Plaquetas', valor: plaq, unidad: '/mm3', estado: 'Normal' }); - if (gluc) res.push({ parametro: 'Glucemia', valor: gluc, unidad: 'mg/dL', estado: 'Normal' }); - if (urea) res.push({ parametro: 'Urea', valor: urea, unidad: 'mg/dL', estado: 'Normal' }); - if (creat) res.push({ parametro: 'Creatinina', valor: creat, unidad: 'mg/dL', estado: 'Normal' }); - if (na) res.push({ parametro: 'Sodio', valor: na, unidad: 'mEq/L', estado: 'Normal' }); - if (k) res.push({ parametro: 'Potasio', valor: k, unidad: 'mEq/L', estado: 'Normal' }); - if (cl) res.push({ parametro: 'Cloro', valor: cl, unidad: 'mEq/L', estado: 'Normal' }); - if (bt) res.push({ parametro: 'Bilirrubina Total', valor: bt, unidad: 'mg/dL', estado: 'Normal' }); - if (bd) res.push({ parametro: 'Bilirrubina Directa', valor: bd, unidad: 'mg/dL', estado: 'Normal' }); - if (got) res.push({ parametro: 'GOT', valor: got, unidad: 'U/L', estado: 'Normal' }); - if (gpt) res.push({ parametro: 'GPT', valor: gpt, unidad: 'U/L', estado: 'Normal' }); - if (tp) res.push({ parametro: 'Tiempo de Protrombina', valor: tp, unidad: 'seg', estado: 'Normal' }); - if (kptt) res.push({ parametro: 'KPTT', valor: kptt, unidad: 'seg', estado: 'Normal' }); - if (rin) res.push({ parametro: 'INR', valor: rin, unidad: '', estado: 'Normal' }); + if (hto) res.push({ parametro: 'Hematocrito', valor: hto, unidad: '%', estado: calcularEstadoLaboratorio('Hematocrito', hto) }); + if (hb) res.push({ parametro: 'Hemoglobina', valor: hb, unidad: 'g/dL', estado: calcularEstadoLaboratorio('Hemoglobina', hb) }); + if (gb) res.push({ parametro: 'Leucocitos', valor: gb, unidad: '/mm3', estado: calcularEstadoLaboratorio('Leucocitos', gb) }); + if (plaq) res.push({ parametro: 'Plaquetas', valor: plaq, unidad: '/mm3', estado: calcularEstadoLaboratorio('Plaquetas', plaq) }); + if (gluc) res.push({ parametro: 'Glucemia', valor: gluc, unidad: 'mg/dL', estado: calcularEstadoLaboratorio('Glucemia', gluc) }); + if (urea) res.push({ parametro: 'Urea', valor: urea, unidad: 'mg/dL', estado: calcularEstadoLaboratorio('Urea', urea) }); + if (creat) res.push({ parametro: 'Creatinina', valor: creat, unidad: 'mg/dL', estado: calcularEstadoLaboratorio('Creatinina', creat) }); + if (na) res.push({ parametro: 'Sodio', valor: na, unidad: 'mEq/L', estado: calcularEstadoLaboratorio('Sodio', na) }); + if (k) res.push({ parametro: 'Potasio', valor: k, unidad: 'mEq/L', estado: calcularEstadoLaboratorio('Potasio', k) }); + if (cl) res.push({ parametro: 'Cloro', valor: cl, unidad: 'mEq/L', estado: calcularEstadoLaboratorio('Cloro', cl) }); + if (bt) res.push({ parametro: 'Bilirrubina Total', valor: bt, unidad: 'mg/dL', estado: calcularEstadoLaboratorio('Bilirrubina Total', bt) }); + if (bd) res.push({ parametro: 'Bilirrubina Directa', valor: bd, unidad: 'mg/dL', estado: calcularEstadoLaboratorio('Bilirrubina Directa', bd) }); + if (got) res.push({ parametro: 'GOT', valor: got, unidad: 'U/L', estado: calcularEstadoLaboratorio('GOT', got) }); + if (gpt) res.push({ parametro: 'GPT', valor: gpt, unidad: 'U/L', estado: calcularEstadoLaboratorio('GPT', gpt) }); + if (tp) res.push({ parametro: 'Tiempo de Protrombina', valor: tp, unidad: 'seg', estado: calcularEstadoLaboratorio('Tiempo de Protrombina', tp) }); + if (kptt) res.push({ parametro: 'KPTT', valor: kptt, unidad: 'seg', estado: calcularEstadoLaboratorio('KPTT', kptt) }); + if (rin) res.push({ parametro: 'INR', valor: rin, unidad: '', estado: calcularEstadoLaboratorio('INR', rin) }); return res; };