Spaces:
Running
Running
Update js/labAnalysisModule.js
Browse files- js/labAnalysisModule.js +55 -39
js/labAnalysisModule.js
CHANGED
|
@@ -115,7 +115,7 @@ export async function analyzeLabResults(text) {
|
|
| 115 |
}
|
| 116 |
|
| 117 |
|
| 118 |
-
// --- INICIO: Función displayLabResults (MODIFICADA con
|
| 119 |
/**
|
| 120 |
* Muestra los resultados de laboratorio formateados en la UI.
|
| 121 |
* @param {string} resultsText - El texto formateado recibido de la IA.
|
|
@@ -135,56 +135,72 @@ export function displayLabResults(resultsText, containerElement, filterAltered)
|
|
| 135 |
}
|
| 136 |
|
| 137 |
const lines = resultsText.split('\n').filter(line => line.trim() !== '');
|
| 138 |
-
let linesToDisplay = lines;
|
| 139 |
|
|
|
|
| 140 |
if (filterAltered) {
|
| 141 |
-
console.log("--- INICIO FILTRO ALTERADOS ---");
|
| 142 |
-
const
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
//
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
//
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
| 166 |
}
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
-
} // Fin del bucle
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
| 176 |
} else {
|
| 177 |
-
|
| 178 |
-
|
| 179 |
}
|
| 180 |
-
|
| 181 |
-
|
|
|
|
| 182 |
|
| 183 |
-
// Formateo y renderizado (sin cambios
|
| 184 |
const fragment = document.createDocumentFragment();
|
| 185 |
linesToDisplay.forEach(line => {
|
| 186 |
const p = document.createElement('p');
|
| 187 |
p.style.margin = '0 0 0.3em 0';
|
|
|
|
| 188 |
p.innerHTML = line.replace(
|
| 189 |
/\*\*(.*?)\*\*/g,
|
| 190 |
'<strong class="text-red-600 font-bold">$1</strong>'
|
|
|
|
| 115 |
}
|
| 116 |
|
| 117 |
|
| 118 |
+
// --- INICIO: Función displayLabResults (MODIFICADA con filtro a NIVEL PARÁMETRO) ---
|
| 119 |
/**
|
| 120 |
* Muestra los resultados de laboratorio formateados en la UI.
|
| 121 |
* @param {string} resultsText - El texto formateado recibido de la IA.
|
|
|
|
| 135 |
}
|
| 136 |
|
| 137 |
const lines = resultsText.split('\n').filter(line => line.trim() !== '');
|
| 138 |
+
let linesToDisplay = lines; // Por defecto, mostrar todas
|
| 139 |
|
| 140 |
+
// Aplicar filtro A NIVEL DE PARÁMETRO si está activo
|
| 141 |
if (filterAltered) {
|
| 142 |
+
console.log("--- INICIO FILTRO ALTERADOS (Nivel Parámetro) ---");
|
| 143 |
+
const filteredOutputLines = []; // Aquí guardaremos las líneas reconstruidas
|
| 144 |
+
const alterationRegex = /\*\*.*?\*\*/; // Regex para detectar **...**
|
| 145 |
+
|
| 146 |
+
for (const line of lines) { // Iterar sobre las líneas originales de la IA
|
| 147 |
+
// Intentar separar la línea en "Cabecera: Contenido"
|
| 148 |
+
const headerMatch = line.match(/^([^:]+):\s*(.*)$/);
|
| 149 |
+
|
| 150 |
+
if (headerMatch) {
|
| 151 |
+
// Si coincide el formato "Cabecera: Contenido"
|
| 152 |
+
const headerName = headerMatch[1].trim(); // Ej: "Hematología"
|
| 153 |
+
const contentPart = headerMatch[2].trim(); // Ej: "Hematíes... | Hemoglobina..."
|
| 154 |
+
|
| 155 |
+
// Dividir el contenido en parámetros individuales usando "|"
|
| 156 |
+
const parameters = contentPart.split('|')
|
| 157 |
+
.map(p => p.trim()) // Quitar espacios extra de cada parámetro
|
| 158 |
+
.filter(p => p); // Quitar posibles parámetros vacíos
|
| 159 |
+
|
| 160 |
+
const alteredParametersInLine = []; // Guardar solo los parámetros alterados de ESTA línea
|
| 161 |
+
|
| 162 |
+
// Revisar cada parámetro de la línea actual
|
| 163 |
+
for (const param of parameters) {
|
| 164 |
+
if (alterationRegex.test(param)) { // Si el parámetro contiene **...**
|
| 165 |
+
alteredParametersInLine.push(param); // Añadirlo a la lista de alterados de esta línea
|
| 166 |
+
console.log(` -> Parámetro Alterado Encontrado: "${param}" bajo "${headerName}"`);
|
| 167 |
+
}
|
| 168 |
}
|
| 169 |
+
|
| 170 |
+
// Si encontramos algún parámetro alterado en esta línea...
|
| 171 |
+
if (alteredParametersInLine.length > 0) {
|
| 172 |
+
// ...reconstruir la línea solo con la cabecera y esos parámetros alterados.
|
| 173 |
+
const filteredLine = `${headerName}: ${alteredParametersInLine.join(' | ')}`;
|
| 174 |
+
filteredOutputLines.push(filteredLine); // Añadir la línea reconstruida al resultado final
|
| 175 |
+
console.log(` -> Línea Filtrada Construida: "${filteredLine}"`);
|
| 176 |
+
} else {
|
| 177 |
+
// Si no hubo alterados en esta línea, simplemente la ignoramos (no se añade a filteredOutputLines)
|
| 178 |
+
console.log(` -> Cabecera "${headerName}" sin parámetros alterados, omitiendo línea completa.`);
|
| 179 |
+
}
|
| 180 |
+
} else {
|
| 181 |
+
// Si una línea no tiene el formato "Cabecera: Contenido", la ignoramos al filtrar
|
| 182 |
+
console.log(` -> Línea ignorada en filtro (no coincide formato Cabecera: Contenido): "${line}"`);
|
| 183 |
}
|
| 184 |
+
} // Fin del bucle sobre las líneas originales
|
| 185 |
|
| 186 |
+
// Asignar el resultado del filtrado a linesToDisplay
|
| 187 |
+
if (filteredOutputLines.length === 0 && lines.length > 0) {
|
| 188 |
+
linesToDisplay = ["No se encontraron resultados marcados como alterados."];
|
| 189 |
+
console.log("--- FIN FILTRO ALTERADOS (Resultado: Vacío) ---");
|
| 190 |
} else {
|
| 191 |
+
linesToDisplay = filteredOutputLines; // Usar las líneas reconstruidas y filtradas
|
| 192 |
+
console.log("--- FIN FILTRO ALTERADOS (Resultado: Mostrando filtrados por parámetro) ---");
|
| 193 |
}
|
| 194 |
+
console.log("Líneas finales a mostrar (filtrado por parámetro):", linesToDisplay);
|
| 195 |
+
|
| 196 |
+
} // Fin if(filterAltered)
|
| 197 |
|
| 198 |
+
// Formateo y renderizado (sin cambios, opera sobre linesToDisplay)
|
| 199 |
const fragment = document.createDocumentFragment();
|
| 200 |
linesToDisplay.forEach(line => {
|
| 201 |
const p = document.createElement('p');
|
| 202 |
p.style.margin = '0 0 0.3em 0';
|
| 203 |
+
// Reemplazar **valor** por <strong> con estilo
|
| 204 |
p.innerHTML = line.replace(
|
| 205 |
/\*\*(.*?)\*\*/g,
|
| 206 |
'<strong class="text-red-600 font-bold">$1</strong>'
|