@peopl-health/nexus 5.71.0 → 5.71.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.
@@ -27,6 +27,7 @@ function flagsByStatus(sections) {
27
27
  absent: named(false),
28
28
  unassessed: pending.map((flag) => inlineOf(flag.flag)),
29
29
  drugSafety: pending.filter((flag) => flag.blocksDrug !== false).map((flag) => inlineOf(flag.flag)),
30
+ urgent: pending.filter((flag) => flag.urgentIfPositive === true).map((flag) => inlineOf(flag.flag)),
30
31
  };
31
32
  }
32
33
 
@@ -60,13 +61,16 @@ function proposalLine({ proposal, withheldReason, conduct, sections }) {
60
61
  const declared = [...(proposal.conditions ?? []), ...(proposal.ruledOut ?? []).map((key) => `descartado ${key}`)]
61
62
  .map((key) => inlineOf(key)?.replace(/_/g, ' ')).filter(Boolean);
62
63
  const table = formularyFor(proposal.symptom)?.label;
63
- const { unassessed, drugSafety } = flagsByStatus(sections);
64
- const lead = drugSafety.length
65
- ? `→ Propuesta para su aprobación si se confirma sin ${drugSafety.join(', ')} (tabla ${table})`
64
+ const { unassessed, drugSafety, urgent } = flagsByStatus(sections);
65
+ const gate = unassessed.filter((flag) => drugSafety.includes(flag) || urgent.includes(flag));
66
+ const call = urgent.length ? `Llamar antes de indicar: ${urgent.join(', ')}. ` : '';
67
+ const lead = gate.length
68
+ ? `→ ${call}Propuesta para su aprobación si se confirma sin ${gate.join(', ')} (tabla ${table})`
66
69
  : `→ Propuesta para su aprobación (tabla ${table})`;
70
+ const armedConduct = urgent.length ? inlineOf(conduct) : null;
67
71
  return [
68
72
  `${lead}: ${sentence(drugs.join('; '))}`,
69
- unassessed.length && 'Si algo de lo pendiente es positivo: valoración presencial.',
73
+ armedConduct ? sentence(armedConduct) : unassessed.length && 'Si algo de lo pendiente es positivo: valoración presencial.',
70
74
  declared.length && `Verificar: ${sentence(declared.join(', '))}`,
71
75
  ].filter(Boolean).join(' ');
72
76
  }
@@ -36,14 +36,16 @@ function settleProposal(parsed) {
36
36
  const items = Array.isArray(raw?.items) ? raw.items : [];
37
37
  const stated = trimmed(parsed?.proposalWithheldReason);
38
38
  const conduct = stated && !drugsNamedIn(stated).length ? stated : null;
39
- if (withheld) return { proposal: null, withheldReason: withheld, conduct, strippedItems: items.length };
40
- if (!items.length) return { proposal: null, withheldReason: null, conduct, strippedItems: 0 };
39
+ const { present, urgent } = flagsByStatus(parsed);
40
+ const callFirst = urgent.length && !present.length ? `llamar antes de indicar: ${urgent.join(', ')}` : null;
41
+ if (withheld) return { proposal: null, withheldReason: [withheld, callFirst].filter(Boolean).join('; '), conduct, strippedItems: items.length };
42
+ if (!items.length) return { proposal: null, withheldReason: callFirst, conduct, strippedItems: 0 };
41
43
 
42
44
  const conditions = Array.isArray(raw.conditions) ? raw.conditions : [];
43
45
  const ruledOut = Array.isArray(raw.ruledOut) ? raw.ruledOut : [];
44
46
  const proposal = { symptom: raw.symptom, items, conditions, ruledOut };
45
47
  const { valid, issues } = validateProposal(proposal, { conditions, ruledOut });
46
- return valid ? { proposal, withheldReason: null, strippedItems: 0 } : { invalid: issues };
48
+ return valid ? { proposal, withheldReason: null, conduct, strippedItems: 0 } : { invalid: issues };
47
49
  }
48
50
 
49
51
  const textList = (value) => (Array.isArray(value) ? value.map(trimmed).filter(Boolean) : []);
@@ -155,7 +157,11 @@ async function generateEscalationDraft({
155
157
 
156
158
  const issues = settled.flatMap((entry) => entry.invalid ?? []);
157
159
  if (!issues.length) issues.push(...crossSymptomIssues(proposals));
158
- const confirmed = settled.filter((entry) => entry.proposal && !flagsByStatus(entry.block).drugSafety.length).map((entry) => entry.proposal);
160
+ const isConfirmed = ({ block, proposal }) => {
161
+ const { drugSafety, urgent } = flagsByStatus(block);
162
+ return proposal && !drugSafety.length && !urgent.length;
163
+ };
164
+ const confirmed = settled.filter(isConfirmed).map((entry) => entry.proposal);
159
165
  const patientDrugs = unproposedDrugsIn(patientMessage, confirmed);
160
166
  if (!issues.length && patientDrugs.length) {
161
167
  issues.push(`el mensaje al paciente menciona ${patientDrugs.join(', ')}, que no está en la propuesta de tratamiento`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.71.0",
3
+ "version": "5.71.1",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",