@peopl-health/nexus 5.45.0-dev.7182 → 5.45.0-dev.7188

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,7 +4,11 @@ const {
4
4
  } = require('../../fhir/helpers/symptomAliasHelper');
5
5
  const { str, strList } = require('../../utils/coercionUtils');
6
6
 
7
- const URGENT_CARD_NAME = 'Contacto con tu equipo médico hoy';
7
+ const URGENT_CARD_NAMES = {
8
+ equipo_tratante_hoy: 'Contacto con tu equipo médico hoy',
9
+ urgencias: 'Atención médica urgente',
10
+ emergencia: 'Atención médica inmediata',
11
+ };
8
12
  const SURFACE_MAX = 6;
9
13
 
10
14
  const itemTerm = (catalog, item) => (catalog?.item_index ? termForItem(catalog, item) : null);
@@ -120,29 +124,45 @@ function stripToReportedTargets(element, boundary) {
120
124
  return true;
121
125
  }
122
126
 
123
- function reframeOnReported(element, boundary) {
124
- const anchors = (boundary.reported || [])
125
- .filter((symptom) => survives(keyOf(symptom.ctcaeTerm), boundary))
126
- .slice(0, SURFACE_MAX);
127
- if (!anchors.length) return false;
128
- element.targetedCtcaeTerms = anchors.map((symptom) => symptom.ctcaeTerm);
129
- element.symptoms = element.symptoms.filter((symptom) => survives(keyOf(symptom.ctcaeTerm), boundary));
130
- setCardSurface(element, anchors.map((symptom) => symptom.label));
127
+ const deniedToday = (term, { deniedKeys, deniedAeKeys }) => deniedKeys.has(keyOf(term)) || deniedAeKeys.has(keyOf(term));
128
+
129
+ const ownTargetsOf = (element, boundary) => element.targetedCtcaeTerms.filter((term) => !deniedToday(term, boundary));
130
+
131
+ function keepTargets(element, targets, boundary) {
132
+ if (!targets.length) return false;
133
+ element.targetedCtcaeTerms = targets;
134
+ element.symptoms = element.symptoms.filter((symptom) => !deniedToday(symptom.ctcaeTerm, boundary));
131
135
  return true;
132
136
  }
133
137
 
138
+ const urgentCardName = (gate) => URGENT_CARD_NAMES[gate.escalationRoute] || URGENT_CARD_NAMES.urgencias;
139
+
134
140
  // El gate urgente viaja en esta tarjeta: se le cambia el rótulo, no se descarta.
135
141
  function reframeOnGate(element, boundary) {
136
142
  if (boundary.gate?.urgentUnder24h !== true || element.escalation?.urgentUnder24h !== true) return false;
137
- if (!reframeOnReported(element, boundary)) return false;
138
- element.nameShort = URGENT_CARD_NAME;
143
+ const own = ownTargetsOf(element, boundary);
144
+ const anchors = (boundary.reported || [])
145
+ .filter((symptom) => survives(keyOf(symptom.ctcaeTerm), boundary))
146
+ .slice(0, SURFACE_MAX)
147
+ .map((symptom) => symptom.ctcaeTerm);
148
+ const touchesDenial = [...element.targetedCtcaeTerms, ...element.symptoms.map((symptom) => symptom.ctcaeTerm)]
149
+ .some((term) => deniedToday(term, boundary));
150
+ const catalogLabels = own.map((term) => symptomRecord(boundary.catalog, resolveTerm(boundary.catalog, term))?.es);
151
+ const header = catalogLabels.every(Boolean) || touchesDenial
152
+ ? catalogLabels.filter(Boolean)
153
+ : strList(element.recommendation.symptomsPatientFacing);
154
+ if (!keepTargets(element, own.length ? own : anchors, boundary)) return false;
155
+ const name = urgentCardName(boundary.gate);
156
+ element.nameShort = name;
157
+ element.recommendation.symptomsPatientFacing = header.length ? [...new Set(header)].slice(0, SURFACE_MAX) : [name];
139
158
  return true;
140
159
  }
141
160
 
142
161
  function applyCardSurfaceBoundary(elements, boundary, repairs = [], { rescue = false } = {}) {
143
- if (!boundary) return { elements, dropped: 0, stripped: 0 };
162
+ if (!boundary) return { elements, dropped: 0, stripped: 0, urgentReframed: [] };
144
163
  const kept = [];
145
164
  const unanchored = [];
165
+ const urgentReframed = [];
146
166
  let dropped = 0;
147
167
  let stripped = 0;
148
168
  for (const element of elements) {
@@ -159,8 +179,9 @@ function applyCardSurfaceBoundary(elements, boundary, repairs = [], { rescue = f
159
179
  continue;
160
180
  }
161
181
  if (reframeOnGate(element, boundary)) {
162
- repairs.push(`elemento (rank ${element.rank}) reencuadrado sobre los síntomas reportados para conservar el gate urgente: ${breach.why}`);
182
+ repairs.push(`elemento (rank ${element.rank}) urgente conservado con un título genérico para mantener el gate: ${breach.why}`);
163
183
  stripped += 1;
184
+ urgentReframed.push(element);
164
185
  kept.push(element);
165
186
  continue;
166
187
  }
@@ -169,10 +190,10 @@ function applyCardSurfaceBoundary(elements, boundary, repairs = [], { rescue = f
169
190
  dropped += 1;
170
191
  }
171
192
  const rescued = rescue && !kept.length
172
- ? unanchored.sort((a, b) => a.rank - b.rank).find((element) => reframeOnReported(element, boundary))
193
+ ? unanchored.sort((a, b) => a.rank - b.rank).find((element) => keepTargets(element, ownTargetsOf(element, boundary), boundary))
173
194
  : null;
174
195
  if (rescued) {
175
- repairs.push(`elemento (rank ${rescued.rank}) reencuadrado sobre los síntomas reportados en vez de descartar el plan entero`);
196
+ repairs.push(`elemento (rank ${rescued.rank}) conservado sobre su propio objetivo en vez de descartar el plan entero`);
176
197
  kept.push(rescued);
177
198
  stripped += 1;
178
199
  dropped -= 1;
@@ -181,7 +202,9 @@ function applyCardSurfaceBoundary(elements, boundary, repairs = [], { rescue = f
181
202
  kept.sort((a, b) => a.rank - b.rank);
182
203
  kept.forEach((element, index) => { element.rank = index + 1; });
183
204
  }
184
- return { elements: kept, dropped, stripped };
205
+ return {
206
+ elements: kept, dropped, stripped, urgentReframed,
207
+ };
185
208
  }
186
209
 
187
210
  module.exports = {
@@ -7,6 +7,7 @@ const ESCALATION_ELLIPSIS = /…|\.\.\./;
7
7
  const ESCALATION_LENGTH_CODE = 'when_to_escalate_length';
8
8
  const SENTENCE_COUNT_CODE = 'main_recommendation_sentence_count';
9
9
  const ATTRIBUTION_CODE = 'unsourced_care_team_attribution';
10
+ const URGENT_WITHOUT_TODAY_EVIDENCE_CODE = 'urgent_without_today_evidence';
10
11
 
11
12
  const ATTRIBUTIONS = [
12
13
  'como lo indico tu equipo', 'tal como lo indico tu equipo', 'como te lo indico tu equipo',
@@ -138,6 +139,15 @@ function validate(elements, options = {}) {
138
139
  issues.push({ path: `${path}.recommendation`, problem: 'sin main_recommendation, sin otc_offer y sin followup=team_referral — el paciente no recibe nada' });
139
140
  }
140
141
  if (isTriagePlan) issues.push(...attributionIssues(patient, path));
142
+ if (isTriagePlan && options.urgentReframed?.includes(element)) {
143
+ issues.push({
144
+ path,
145
+ code: URGENT_WITHOUT_TODAY_EVIDENCE_CODE,
146
+ warning: true,
147
+ problem: 'la tarjeta urgente no nombra ningún síntoma reportado en este triaje; se conservó con un título '
148
+ + 'genérico para no perder el gate.',
149
+ });
150
+ }
141
151
  if (recommendation.otcOffer !== null) {
142
152
  for (const field of ['dose', 'frequency', 'duration', 'warnings']) {
143
153
  if (!recommendation.otcOffer[field]) {
@@ -607,7 +607,9 @@ async function runPlan({ provider, presetId, casoBase, gate, boundary = null, ri
607
607
  repairs = [];
608
608
  const built = rawElements.map((raw) => buildElement(raw, repairs));
609
609
  stripOtcOffers(built, repairs);
610
- const { elements, dropped, stripped } = applyCardSurfaceBoundary(built, boundary, repairs, { rescue: last });
610
+ const {
611
+ elements, dropped, stripped, urgentReframed,
612
+ } = applyCardSurfaceBoundary(built, boundary, repairs, { rescue: last });
611
613
  deniedCardsDropped = dropped;
612
614
  deniedTargetsStripped = stripped;
613
615
  if (!elements.length) {
@@ -616,7 +618,7 @@ async function runPlan({ provider, presetId, casoBase, gate, boundary = null, ri
616
618
  return { attempts: attempt, repairs, failure: { status: 'failed', stage: 'validate', reason: 'plan_all_denied', hardRejectIssues: lastIssues } };
617
619
  }
618
620
  rankReordered = applyRankOrder(elements, gate, repairs);
619
- const issues = validate(elements, { gate, lane: 'triage' });
621
+ const issues = validate(elements, { gate, lane: 'triage', urgentReframed });
620
622
  const blocking = blockingIssues(issues);
621
623
  if (blocking.length) {
622
624
  lastIssues = blocking;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.45.0-dev.7182",
3
+ "version": "5.45.0-dev.7188",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",