Fix parser AB: buscar valor después del nombre de parámetro
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user