@peopl-health/nexus 5.75.4 → 6.0.0-dev.15739

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.
@@ -14,11 +14,16 @@ function feverPatientTimerLive() {
14
14
  return flagOn('FEVER_PATIENT_TIMER_LIVE');
15
15
  }
16
16
 
17
+ function escalationApproverAlertLive() {
18
+ return flagOn('ESCALATION_APPROVER_ALERT_LIVE');
19
+ }
20
+
17
21
  function escalationPatientTimerLive() {
18
22
  return flagOn('ESCALATION_PATIENT_TIMER_LIVE');
19
23
  }
20
24
 
21
25
  module.exports = {
26
+ escalationApproverAlertLive,
22
27
  escalationAssessmentLive,
23
28
  escalationPatientTimerLive,
24
29
  escalationUpdateModeLive,
@@ -401,7 +401,9 @@ class BaseLLMProvider {
401
401
  };
402
402
  const local = (at) => (at ? `${getCurrentMexicoDateTime(at)}${ago(at)}` : null);
403
403
  const said = (message) => (message ? `${local(message.at)} — «${sanitizeInlineText(message.text)}»` : null);
404
+ const self = checkIn.reminderId ? `${checkIn.reminderId}${checkIn.dueAt ? `, programado para ${local(checkIn.dueAt)}` : ''}` : null;
404
405
  const pending = lines([
406
+ ['este check-in', self],
405
407
  ['lo que querías preguntarle', checkIn.question],
406
408
  ['por qué quedó abierto', checkIn.concern],
407
409
  ['qué dato esperabas', checkIn.awaiting],
@@ -424,6 +426,7 @@ class BaseLLMProvider {
424
426
  '', '## Check-ins que ya le llegaron en las últimas 48 h', ...(sent.length ? sent : ['- ninguno']),
425
427
  '',
426
428
  `Cierra el turno con \`${OUTREACH_DECISION_TOOL}\`. Antes, revisa la conversación desde que quedó pendiente:`,
429
+ '- Este check-in es el seguimiento que está venciendo ahora, aunque lo veas programado unos minutos más tarde: ya no está pendiente y no se puede actualizar. Si decides esperar, programa uno nuevo.',
427
430
  '- Si ya lo respondió, a ti o al equipo, no se lo vuelvas a preguntar. Si es una red de contingencia, resuélvela con setContingencyPlan y registra hold con hold_reason answered_since_armed.',
428
431
  '- Si tu último mensaje ya le hace esta pregunta o la cubre, y ella estuvo activa hoy y dejó de contestar hace menos de 6 h, no la repitas hoy: programa la siguiente vez o resuélvela si ya no hace falta.',
429
432
  '- Si sólo quedó una pregunta tuya sin respuesta y lleva 8 h o más en silencio, retomarla es justo para lo que existe este check-in: escríbele, salvo que sea de noche.',
@@ -96,6 +96,8 @@ async function planCheckInDue({ code, reminderId, type, question = '', firstName
96
96
  if (await checkInsPausedUntil(code, now)) return { mode: 'stale', reason: 'patient_paused', planId };
97
97
  checkIn = {
98
98
  type,
99
+ reminderId,
100
+ dueAt: null,
99
101
  question: netQuestion,
100
102
  concern: net.carePlan.concern,
101
103
  awaiting: net.carePlan.awaitingCharacterization,
@@ -111,6 +113,8 @@ async function planCheckInDue({ code, reminderId, type, question = '', firstName
111
113
  if (await checkInsPausedUntil(code, now)) return { mode: 'stale', reason: 'patient_paused' };
112
114
  checkIn = {
113
115
  type,
116
+ reminderId,
117
+ dueAt: plan.fireAt || null,
114
118
  question: plan.message || question,
115
119
  concern: plan.windowReasoning,
116
120
  awaiting: null,
package/lib/index.d.ts CHANGED
@@ -468,7 +468,7 @@ declare module '@peopl-health/nexus' {
468
468
  lastInboundAt?: string | null;
469
469
  lastOutboundAt?: string | null;
470
470
  lastOutreach?: string | null;
471
- checkIn?: { type: string; question: string; concern?: string | null; awaiting?: string | null; armedAt?: string | null; urgency?: string | null; otherPlans?: number | null } | null;
471
+ checkIn?: { type: string; reminderId?: string | null; dueAt?: string | null; question: string; concern?: string | null; awaiting?: string | null; armedAt?: string | null; urgency?: string | null; otherPlans?: number | null } | null;
472
472
  recentCheckIns?: string[];
473
473
  exchange?: { patient: { at: string; text: string } | null; own: { at: string; text: string } | null; ownMessagesToday: number } | null;
474
474
  asOf?: string | null;
@@ -37,6 +37,7 @@ const { humanReplyFilter } = require('../clinical/config/safetyNetConfig');
37
37
  const {
38
38
  feverPatientTimerLive: feverTimerLive,
39
39
  escalationPatientTimerLive: escalationTimerLive,
40
+ escalationApproverAlertLive,
40
41
  } = require('../clinical/flags/escalationFlags');
41
42
  const { chemoContextLive } = require('../clinical/flags/clinicalContextFlags');
42
43
  const { cytotoxicWindowDays, daysSinceLastCytotoxic } = require('../clinical/helpers/chemoContextHelper');
@@ -88,6 +89,7 @@ const PATIENT_TIMER_OPERATOR = 'escalation_patient_timer';
88
89
  const STAFF_ORIGINS = ['whatsapp_platform', 'instruction', 'system'];
89
90
  const PRE_DECISION_STATUSES = ['open', 'documenting', 'draft_ready', 'handing_off', 'awaiting_doctor'];
90
91
  const ALERT_OPERATOR = 'bot:escalationAlert';
92
+ const AIRTABLE_TRANSPORT = 'airtable';
91
93
  const RECLASSIFIABLE_STATUSES = [...DOCUMENTING_STATUSES, 'awaiting_doctor'];
92
94
  const SAME_URGENCY = 'The review is already at that urgency';
93
95
  const RECLASSIFY_CHANGED = 'The review changed while you were reclassifying it; read it again before changing the urgency';
@@ -1184,13 +1186,18 @@ async function sendScheduledDoctorAlert({ id, kind, lease = null, now = new Date
1184
1186
 
1185
1187
  let delivery;
1186
1188
  try {
1187
- const { approver, message } = await prepareDoctorAlert(review, urgencyLevel);
1188
- const fresh = await loadReview(review._id);
1189
- if (fresh.closedAt || !PRE_DECISION_STATUSES.includes(fresh.status)) {
1190
- await release();
1191
- return null;
1189
+ if (escalationApproverAlertLive()) {
1190
+ const { approver, message } = await prepareDoctorAlert(review, urgencyLevel);
1191
+ const fresh = await loadReview(review._id);
1192
+ if (fresh.closedAt || !PRE_DECISION_STATUSES.includes(fresh.status)) {
1193
+ await release();
1194
+ return null;
1195
+ }
1196
+ delivery = { physicianEmail: approver.email, ...(await sendDoctorAlert({ message, approver, operator: ALERT_OPERATOR })) };
1197
+ } else {
1198
+ // Airtable's notifyEmergency alerts the team; the entry still starts this level's patient timer.
1199
+ delivery = { transport: AIRTABLE_TRANSPORT };
1192
1200
  }
1193
- delivery = { physicianEmail: approver.email, ...(await sendDoctorAlert({ message, approver, operator: ALERT_OPERATOR })) };
1194
1201
  } catch (error) {
1195
1202
  delivery = { error: redactedError(error) };
1196
1203
  logger.error('[EscalationReview] The doctor alert was not sent', { escalationReviewId: String(review._id), kind, error: delivery.error });
@@ -1228,7 +1235,7 @@ async function sendScheduledDoctorAlert({ id, kind, lease = null, now = new Date
1228
1235
  }
1229
1236
  }
1230
1237
  await audit(updated ?? review, ALERT_OPERATOR, null, {
1231
- action: 'doctor_alerted', urgencyLevel, delivered: !sent.error,
1238
+ action: 'doctor_alerted', urgencyLevel, delivered: sent.transport === AIRTABLE_TRANSPORT ? null : !sent.error, transport: sent.transport,
1232
1239
  });
1233
1240
  if (gap && !timer) await audit(updated ?? review, ALERT_OPERATOR, null, { action: 'patient_prompt_not_armed', reason: gap });
1234
1241
  return updated;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.75.4",
3
+ "version": "6.0.0-dev.15739",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",