@peopl-health/nexus 5.60.0-dev.11139 → 5.60.1
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.
|
@@ -4,20 +4,34 @@ const { objectArg } = require('../../utils/jsonUtils');
|
|
|
4
4
|
|
|
5
5
|
const EXTRACTION_TOOL = 'extractClinicalInfo';
|
|
6
6
|
const LOOKUP_TOOL = 'lookupCtcaeEntry';
|
|
7
|
+
const LANDSCAPE_TOOLS = ['getRouterContextBundle', 'getActiveSymptomLandscape'];
|
|
8
|
+
const IMPRESSION_TOOLS = ['openCondition', 'recordClinicalImpression'];
|
|
7
9
|
|
|
8
10
|
const populated = (grades) => !!grades && Object.keys(grades).length > 0;
|
|
9
11
|
|
|
10
|
-
function
|
|
11
|
-
let scale = null;
|
|
12
|
+
function catalogScale(ctcaeTerm) {
|
|
12
13
|
try {
|
|
13
|
-
scale = getCtcaeCatalog().getGradeScale(ctcaeTerm);
|
|
14
|
+
const scale = getCtcaeCatalog().getGradeScale(ctcaeTerm);
|
|
15
|
+
return populated(scale) ? scale : null;
|
|
14
16
|
} catch {
|
|
15
17
|
return null;
|
|
16
18
|
}
|
|
17
|
-
const keys = Object.keys(scale || {});
|
|
18
|
-
return keys.length ? keys : null;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function gradesDefined(ctcaeTerm) {
|
|
22
|
+
const scale = catalogScale(ctcaeTerm);
|
|
23
|
+
return scale ? Object.keys(scale) : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The refusal below prints the scale after this mark, so a retry in the same turn has read it.
|
|
27
|
+
const scaleDeliveredMark = (ctcaeTerm) => `CTCAE grade_scale for '${ctcaeTerm}':`;
|
|
28
|
+
|
|
29
|
+
const landscapeCases = (payload) => {
|
|
30
|
+
const data = payload.data || payload;
|
|
31
|
+
const cases = data?.landscape?.active_cases || data?.active_cases;
|
|
32
|
+
return Array.isArray(cases) ? cases : [];
|
|
33
|
+
};
|
|
34
|
+
|
|
21
35
|
function ladderReachedModel(trace, ctcaeTerm) {
|
|
22
36
|
if (!ctcaeTerm) return false;
|
|
23
37
|
const steps = Array.isArray(trace?.steps) ? trace.steps : [];
|
|
@@ -32,6 +46,10 @@ function ladderReachedModel(trace, ctcaeTerm) {
|
|
|
32
46
|
const entry = payload.data?.entry || payload.entry;
|
|
33
47
|
if (entry?.ctcae_term === ctcaeTerm && populated(entry.grades)) return true;
|
|
34
48
|
}
|
|
49
|
+
if (LANDSCAPE_TOOLS.includes(step.tool_name)
|
|
50
|
+
&& landscapeCases(payload).some((c) => c?.ctcae_term === ctcaeTerm && populated(c?.grade_scale))) return true;
|
|
51
|
+
if (IMPRESSION_TOOLS.includes(step.tool_name)
|
|
52
|
+
&& typeof payload.error === 'string' && payload.error.includes(scaleDeliveredMark(ctcaeTerm))) return true;
|
|
35
53
|
}
|
|
36
54
|
return false;
|
|
37
55
|
}
|
|
@@ -101,9 +119,16 @@ function noCuratedRubric(ctcaeTerm) {
|
|
|
101
119
|
}
|
|
102
120
|
|
|
103
121
|
function missingLadder(ctcaeTerm) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
const head = `source is 'agent_adjudicated' but the ${ctcaeTerm} grade scale did not reach you this turn, so there was no rubric to adjudicate against.`;
|
|
123
|
+
const scale = catalogScale(ctcaeTerm);
|
|
124
|
+
// Without the catalog the lookup may fail too, so the ungraded record stays available as the way out.
|
|
125
|
+
if (!scale) {
|
|
126
|
+
return `${head} Call lookupCtcaeEntry for '${ctcaeTerm}' and grade from the clauses it returns. `
|
|
127
|
+
+ 'If the lookup cannot return the scale, drop best_estimate AND source together and record possible_range alone.';
|
|
128
|
+
}
|
|
129
|
+
return `${head} Here it is — ${scaleDeliveredMark(ctcaeTerm)} ${JSON.stringify(scale)}. `
|
|
130
|
+
+ 'Read what the patient reported against these clauses, set matched_grade to the clause the evidence meets, '
|
|
131
|
+
+ 'and re-issue the call with the grade that clause supports. Keep best_estimate: a graded read is what the case needs.';
|
|
107
132
|
}
|
|
108
133
|
|
|
109
134
|
module.exports = {
|
|
@@ -2,7 +2,7 @@ const { assembleLandscape } = require('../services/symptomLandscapeService');
|
|
|
2
2
|
|
|
3
3
|
const definition = {
|
|
4
4
|
name: 'getActiveSymptomLandscape',
|
|
5
|
-
description: '**Does:** Returns a snapshot of ALL the patient\'s open symptom cases (`characterizing` | `monitoring`), each fusing the Condition with its head impression, plus active clusters. Read-only.\n\n**Required inputs:** none. Optional `minimum_priority` (`low` (default) returns everything; `medium` returns high+medium; `high` returns only high).\n\n**When to call:** only for a targeted re-read of the case landscape once `getRouterContextBundle` has already loaded the turn\'s context — for example after opening a case, or to narrow with a different `minimum_priority`. The routine load at the start of routing is the bundle\'s `landscape` section, not this tool.\n\n**A case flagged `stale_no_recent_evidence` has had no new evidence for two weeks or more.** `days_since_evidence` says how long. Ask whether the symptom is still there, and close the case with `recordClinicalImpression` `close` when it is not: an open case keeps consuming the landscape and keeps the symptom reading as active on the record.\n\n**When NOT to call:** for the current turn\'s observations (use `extractClinicalInfo`) or closed-case history.\n\n**Returns:** `active_cases[]` (each: `case_id`, `ctcae_term`, `status`, `opened_at`, `current_episode_id`, `mention_ids` (the evidence already on the case — on a turn that extracts nothing new, re-cite one of these with `source: \'carried_forward\'`), `grade_estimate`, `decision_posture`, `trajectory`, derived `priority` + `attention_flags`, `last_assessed_at`, `days_since_evidence`) sorted priority desc then most-recently-opened; `active_clusters[]` (each: `cluster_id`, `label`, `hypothesis_type`, `status`, `confidence`, `clinical_significance`, `member_case_ids`, `relationship_model`); `active_contingencies[]` — the safety nets already armed (each: `plan_id`, `related_case_id`, `related_cluster_id`, `concern`, `awaiting_characterization`, `status`, `created_at`, `expires_at`, `patient_fires_after_silence_minutes`). A target that already appears here does NOT need another `setContingencyPlan` arm — a duplicate is rejected; use `action: \'rearm\'` to replace its net or `action: \'resolve\'` to stand it down.',
|
|
5
|
+
description: '**Does:** Returns a snapshot of ALL the patient\'s open symptom cases (`characterizing` | `monitoring`), each fusing the Condition with its head impression, plus active clusters. Read-only.\n\n**Required inputs:** none. Optional `minimum_priority` (`low` (default) returns everything; `medium` returns high+medium; `high` returns only high).\n\n**When to call:** only for a targeted re-read of the case landscape once `getRouterContextBundle` has already loaded the turn\'s context — for example after opening a case, or to narrow with a different `minimum_priority`. The routine load at the start of routing is the bundle\'s `landscape` section, not this tool.\n\n**A case flagged `stale_no_recent_evidence` has had no new evidence for two weeks or more.** `days_since_evidence` says how long. Ask whether the symptom is still there, and close the case with `recordClinicalImpression` `close` when it is not: an open case keeps consuming the landscape and keeps the symptom reading as active on the record.\n\n**When NOT to call:** for the current turn\'s observations (use `extractClinicalInfo`) or closed-case history.\n\n**Returns:** `active_cases[]` (each: `case_id`, `ctcae_term`, `status`, `opened_at`, `current_episode_id`, `mention_ids` (the evidence already on the case — on a turn that extracts nothing new, re-cite one of these with `source: \'carried_forward\'`), `grade_estimate`, `grade_scale` (the CTCAE clauses for the case\'s term — grade against these; they count as the rubric for an `agent_adjudicated` grade this turn), `decision_posture`, `trajectory`, derived `priority` + `attention_flags`, `last_assessed_at`, `days_since_evidence`) sorted priority desc then most-recently-opened; `active_clusters[]` (each: `cluster_id`, `label`, `hypothesis_type`, `status`, `confidence`, `clinical_significance`, `member_case_ids`, `relationship_model`); `active_contingencies[]` — the safety nets already armed (each: `plan_id`, `related_case_id`, `related_cluster_id`, `concern`, `awaiting_characterization`, `status`, `created_at`, `expires_at`, `patient_fires_after_silence_minutes`). A target that already appears here does NOT need another `setContingencyPlan` arm — a duplicate is rejected; use `action: \'rearm\'` to replace its net or `action: \'resolve\'` to stand it down.',
|
|
6
6
|
strict: false,
|
|
7
7
|
replayScope: 'turn',
|
|
8
8
|
parameters: {
|