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) {
|
for (const linea of lineas) {
|
||||||
const lineaLower = linea.toLowerCase().trim();
|
const lineaLower = linea.toLowerCase().trim();
|
||||||
const cleanLinea = linea.replace(/show_chart|list_alt/g, '').replace(/,/g, '.');
|
const cleanLinea = linea.replace(/show_chart|list_alt|\t+/g, ' ').replace(/,/g, '.').replace(/\s+/g, ' ').trim();
|
||||||
const valores = cleanLinea.match(/(\d+\.?\d*)/g);
|
|
||||||
|
|
||||||
if (lineaLower.includes('ph') && !lineaLower.includes('pco2') && !lineaLower.includes('pco') && valores) {
|
const getValue = (param: string): number | undefined => {
|
||||||
ph = parseFloat(valores[0]);
|
const idx = cleanLinea.indexOf(param);
|
||||||
} else if ((lineaLower.includes('pco2') || lineaLower.includes('pco 2') || lineaLower.includes('pco₂')) && valores) {
|
if (idx === -1) return undefined;
|
||||||
pco2 = parseFloat(valores[0]);
|
const after = cleanLinea.slice(idx + param.length).trim();
|
||||||
} else if (lineaLower.includes('po2') || lineaLower.includes('po 2') || lineaLower.includes('po₂')) {
|
const match = after.match(/(\d+\.?\d*)/);
|
||||||
if (valores) po2 = parseFloat(valores[0]);
|
return match ? parseFloat(match[1]) : undefined;
|
||||||
} 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 (cleanLinea.includes('ph') && !cleanLinea.includes('pco2') && !cleanLinea.includes('pco')) {
|
||||||
if (valores) be = parseFloat(valores[0]);
|
ph = getValue('ph');
|
||||||
} else if (lineaLower.includes('saturación de oxígeno') || lineaLower.includes('saturación de oxigeno') || lineaLower.includes('sato2') || lineaLower.includes('sat o2')) {
|
} else if (cleanLinea.includes('pco2') || cleanLinea.includes('pco₂')) {
|
||||||
if (valores) sato2 = parseFloat(valores[0]);
|
pco2 = getValue('pco2') || getValue('pco');
|
||||||
} else if (lineaLower.includes('lactato') && valores) {
|
} else if (cleanLinea.includes('po2') || cleanLinea.includes('po₂')) {
|
||||||
lactato = parseFloat(valores[0]);
|
po2 = getValue('po2') || getValue('po');
|
||||||
} else if (lineaLower.includes('fio2') || lineaLower.includes('fi o2') || lineaLower.includes('fi o₂')) {
|
} else if (cleanLinea.includes('hco3')) {
|
||||||
if (valores) fio2 = parseFloat(valores[0]);
|
hco3 = getValue('hco3');
|
||||||
} else if (lineaLower.match(/\d{4}-\d{2}-\d{2}/)) {
|
} else if (cleanLinea.includes('exceso de base') || cleanLinea.includes('exceso de bases') || cleanLinea.includes('base excess')) {
|
||||||
const fechaMatch = lineaLower.match(/(\d{4}-\d{2}-\d{2})/);
|
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];
|
if (fechaMatch) fecha = fechaMatch[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('AB parsing:', { ph, pco2, po2, hco3, be, sato2 });
|
||||||
|
|
||||||
if (ph !== undefined) {
|
if (ph !== undefined) {
|
||||||
const hora = new Date().toTimeString().slice(0, 5);
|
const hora = new Date().toTimeString().slice(0, 5);
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user