From bf62f94380c6332369061bf9c1cbefb4edf6b124 Mon Sep 17 00:00:00 2001 From: snlavaise Date: Tue, 11 Aug 2026 15:53:52 +0000 Subject: [PATCH] Fix laboratory parser regex capturing number from B12 parameter name --- src/sections/HistoriaClinica.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/sections/HistoriaClinica.tsx b/src/sections/HistoriaClinica.tsx index 77bc332..88ff37f 100644 --- a/src/sections/HistoriaClinica.tsx +++ b/src/sections/HistoriaClinica.tsx @@ -1092,6 +1092,7 @@ function SeccionLaboratorios({ lab, patientId, internacionId, add, update, del, if (resultados.some(r => r.parametro === group.nombre)) continue; let matchedClave = false; + let matchedClaveString = ''; for (const clave of group.claves) { if (group.nombre === 'Colesterol Total' && clave === 'colesterol') { if (lineaLower.includes('ldl') || lineaLower.includes('hdl') || lineaLower.includes('no')) { @@ -1105,13 +1106,24 @@ function SeccionLaboratorios({ lab, patientId, internacionId, add, update, del, } if (matchClave(lineaLower, clave)) { matchedClave = true; + matchedClaveString = clave; break; } } if (matchedClave) { - // Extraer primer valor numérico (soporta enteros y decimales con punto o coma) - const match = linea.match(/[a-zA-ZáéíóúñÁÉÍÓÚÑ]+.*?(\d+(?:[.,]\d+)?)/); + // Extraer la porción de texto posterior a la clave/nombre del parámetro para evitar capturar números dentro del nombre (ej: B12, T4) + let subLinea = linea; + const idxClave = lineaLower.indexOf(matchedClaveString); + if (idxClave !== -1) { + subLinea = linea.substring(idxClave + matchedClaveString.length); + } + + let match = subLinea.match(/(\d+(?:[.,]\d+)?)/); + if (!match) { + match = linea.match(/[a-zA-ZáéíóúñÁÉÍÓÚÑ]+.*?(\d+(?:[.,]\d+)?)/); + } + if (match && match[1]) { const valor = parseFloat(match[1].replace(',', '.')); if (!isNaN(valor) && valor > 0 && valor < 1000000) {