Fix laboratory parser regex capturing number from B12 parameter name
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user