@peopl-health/nexus 5.57.0-dev.9493 → 5.57.0-dev.9514
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -290,7 +290,9 @@ function buildSymptomSignalsBlock(symptomSignals) {
|
|
|
290
290
|
}).join('\n');
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
function buildSafetySignals({
|
|
293
|
+
function buildSafetySignals({
|
|
294
|
+
graded = [], riskAssessment = null, riskUnavailable = false, freeTextBits = [], patterns = null,
|
|
295
|
+
}) {
|
|
294
296
|
const signals = [];
|
|
295
297
|
const reported = graded.filter((symptom) => symptom.grade >= 1);
|
|
296
298
|
for (const symptom of reported) {
|
|
@@ -306,9 +308,11 @@ function buildSafetySignals({ graded = [], riskAssessment = null, freeTextBits =
|
|
|
306
308
|
signals.push(`EACAR de vigilancia reportado: ${symptom.term}`);
|
|
307
309
|
}
|
|
308
310
|
}
|
|
309
|
-
|
|
310
|
-
const text =
|
|
311
|
-
if (
|
|
311
|
+
if (riskUnavailable) signals.push('EACAR de vigilancia: no disponible (la evaluación de riesgo no se pudo leer)');
|
|
312
|
+
const text = freeTextBits.filter(Boolean).join(' ');
|
|
313
|
+
if (!Array.isArray(patterns) || !patterns.length) {
|
|
314
|
+
if (text) signals.push('patrón de bandera roja: no disponible (los patrones de seguridad no se pudieron leer)');
|
|
315
|
+
} else if (text) {
|
|
312
316
|
for (const flag of detectSafetyFlags(text, patterns)) {
|
|
313
317
|
signals.push(`patrón de bandera roja: ${flag}`);
|
|
314
318
|
}
|
|
@@ -443,7 +443,6 @@ async function generateTriageRecommendations({ payload, provider, runId = null,
|
|
|
443
443
|
settle.adherenceMalformed = payload.adherence.length - adherenceEntries.length;
|
|
444
444
|
|
|
445
445
|
const painMostImportant = triageResponse.pain?.mostImportant || null;
|
|
446
|
-
// Patient words only: buildSafetySignals scans these for red-flag patterns.
|
|
447
446
|
const freeTextBits = [
|
|
448
447
|
triageResponse.otherSymptomsText,
|
|
449
448
|
...triageResponse.otherSymptomsNotProctcae,
|
|
@@ -475,8 +474,12 @@ async function generateTriageRecommendations({ payload, provider, runId = null,
|
|
|
475
474
|
if (profile === undefined) return finish({ status: 'failed', stage: 'assemble', reason: 'profile_read_failed' });
|
|
476
475
|
if (!profile) return finish({ status: 'failed', stage: 'assemble', reason: 'no_clinical_profile' });
|
|
477
476
|
|
|
478
|
-
const riskRead = await readPatientRiskAssessments({ patientId: code, limit: 1 })
|
|
479
|
-
.then((
|
|
477
|
+
const riskRead = await readPatientRiskAssessments({ patientId: code, limit: 1, includeDiagnostics: true })
|
|
478
|
+
.then(({ records, omittedCount }) => {
|
|
479
|
+
const unreadable = !records.length && omittedCount > 0;
|
|
480
|
+
if (unreadable) logger.warn('[triageRecommendation] every stored risk assessment is malformed; section degraded', { code, omittedCount });
|
|
481
|
+
return { assessments: records, failed: unreadable };
|
|
482
|
+
})
|
|
480
483
|
.catch((err) => {
|
|
481
484
|
logger.warn('[triageRecommendation] risk assessment unavailable; section degraded', { code, error: err?.message });
|
|
482
485
|
return { assessments: [], failed: true };
|
|
@@ -496,8 +499,13 @@ async function generateTriageRecommendations({ payload, provider, runId = null,
|
|
|
496
499
|
return [];
|
|
497
500
|
}),
|
|
498
501
|
]);
|
|
499
|
-
const patterns = await getSafetyFlagPatterns().catch(() =>
|
|
500
|
-
|
|
502
|
+
const patterns = await getSafetyFlagPatterns().catch((err) => {
|
|
503
|
+
logger.warn('[triageRecommendation] safety patterns unavailable; pre-screen marks them as such', { code, error: err?.message });
|
|
504
|
+
return null;
|
|
505
|
+
});
|
|
506
|
+
const safetySignals = buildSafetySignals({
|
|
507
|
+
graded, riskAssessment, riskUnavailable: riskRead.failed, freeTextBits, patterns,
|
|
508
|
+
});
|
|
501
509
|
|
|
502
510
|
// Ungraded pain has to reach the sub-agents as unknown, not vanish with its own block.
|
|
503
511
|
const askedTerms = [...new Set([...answeredTermList, ...ungradedTerms])];
|