From 807070933293e903632d6b5420fc67e9d771ef79 Mon Sep 17 00:00:00 2001 From: Sergio Nicolas Lavaise Date: Thu, 16 Apr 2026 11:37:34 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20parser=20AB:=20buscar=20valor=20despu?= =?UTF-8?q?=C3=A9s=20del=20nombre=20de=20par=C3=A1metro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sections/HistoriaClinica.tsx | 49 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/sections/HistoriaClinica.tsx b/src/sections/HistoriaClinica.tsx index 9df5725..6ecd764 100644 --- a/src/sections/HistoriaClinica.tsx +++ b/src/sections/HistoriaClinica.tsx @@ -781,31 +781,40 @@ if (!esUnidadSiguiente) { for (const linea of lineas) { const lineaLower = linea.toLowerCase().trim(); - const cleanLinea = linea.replace(/show_chart|list_alt/g, '').replace(/,/g, '.'); - const valores = cleanLinea.match(/(\d+\.?\d*)/g); + const cleanLinea = linea.replace(/show_chart|list_alt|\t+/g, ' ').replace(/,/g, '.').replace(/\s+/g, ' ').trim(); - if (lineaLower.includes('ph') && !lineaLower.includes('pco2') && !lineaLower.includes('pco') && valores) { - ph = parseFloat(valores[0]); - } else if ((lineaLower.includes('pco2') || lineaLower.includes('pco 2') || lineaLower.includes('pco₂')) && valores) { - pco2 = parseFloat(valores[0]); - } else if (lineaLower.includes('po2') || lineaLower.includes('po 2') || lineaLower.includes('po₂')) { - if (valores) po2 = parseFloat(valores[0]); - } else if (lineaLower.includes('hco3') && valores) { - hco3 = parseFloat(valores[0]); - } else if (lineaLower.includes('exceso de base') || lineaLower.includes('exceso de bases') || lineaLower.includes('base excess') || lineaLower.includes('be ') || lineaLower.includes('be,')) { - if (valores) be = parseFloat(valores[0]); - } else if (lineaLower.includes('saturación de oxígeno') || lineaLower.includes('saturación de oxigeno') || lineaLower.includes('sato2') || lineaLower.includes('sat o2')) { - if (valores) sato2 = parseFloat(valores[0]); - } else if (lineaLower.includes('lactato') && valores) { - lactato = parseFloat(valores[0]); - } else if (lineaLower.includes('fio2') || lineaLower.includes('fi o2') || lineaLower.includes('fi o₂')) { - if (valores) fio2 = parseFloat(valores[0]); - } else if (lineaLower.match(/\d{4}-\d{2}-\d{2}/)) { - const fechaMatch = lineaLower.match(/(\d{4}-\d{2}-\d{2})/); + const getValue = (param: string): number | undefined => { + const idx = cleanLinea.indexOf(param); + if (idx === -1) return undefined; + const after = cleanLinea.slice(idx + param.length).trim(); + const match = after.match(/(\d+\.?\d*)/); + return match ? parseFloat(match[1]) : undefined; + }; + + if (cleanLinea.includes('ph') && !cleanLinea.includes('pco2') && !cleanLinea.includes('pco')) { + ph = getValue('ph'); + } else if (cleanLinea.includes('pco2') || cleanLinea.includes('pco₂')) { + pco2 = getValue('pco2') || getValue('pco'); + } else if (cleanLinea.includes('po2') || cleanLinea.includes('po₂')) { + po2 = getValue('po2') || getValue('po'); + } else if (cleanLinea.includes('hco3')) { + hco3 = getValue('hco3'); + } else if (cleanLinea.includes('exceso de base') || cleanLinea.includes('exceso de bases') || cleanLinea.includes('base excess')) { + be = getValue('exceso de base') || getValue('base excess'); + } else if (cleanLinea.includes('saturación de oxígeno') || cleanLinea.includes('saturación de oxigeno') || cleanLinea.includes('sato2')) { + sato2 = getValue('saturación de oxígeno') || getValue('saturación de oxigeno') || getValue('sato2'); + } else if (cleanLinea.includes('lactato')) { + lactato = getValue('lactato'); + } else if (cleanLinea.includes('fio2') || cleanLinea.includes('fi o₂')) { + fio2 = getValue('fio2') || getValue('fi o2'); + } else if (cleanLinea.match(/\d{4}-\d{2}-\d{2}/)) { + const fechaMatch = cleanLinea.match(/(\d{4}-\d{2}-\d{2})/); if (fechaMatch) fecha = fechaMatch[1]; } } + console.log('AB parsing:', { ph, pco2, po2, hco3, be, sato2 }); + if (ph !== undefined) { const hora = new Date().toTimeString().slice(0, 5); return {