@peopl-health/nexus 5.75.5 → 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,
@@ -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.5",
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",