@peopl-health/nexus 5.61.0-dev.11232 → 5.61.0-dev.11233

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.
@@ -6,6 +6,8 @@ const { logger } = require('../utils/logger');
6
6
 
7
7
  const CALL_OUTCOMES = ['contacted', 'no_answer', 'voicemail'];
8
8
  const URGENCY_LEVELS = ['stat', 'asap', 'urgent', 'routine'];
9
+ // One ranking for the board's order and the doctor alerts' urgency gate.
10
+ const URGENCY_RANK = { routine: 1, urgent: 2, asap: 3, stat: 4 };
9
11
  const HANDOFF_MODES = ['sent_whatsapp', 'copied'];
10
12
  const INTERRUPTED_STATUSES = ['handing_off', 'sending'];
11
13
  const CANCELLABLE_AFTER_HANDOFF_STATUSES = ['awaiting_doctor', 'approved', 'returned', 'indications_queued'];
@@ -221,6 +223,7 @@ module.exports = {
221
223
  HANDOFF_MODES,
222
224
  INTERRUPTED_STATUSES,
223
225
  RETURN_REASONS,
226
+ URGENCY_RANK,
224
227
  getEscalationReview,
225
228
  escalationReviewSchema,
226
229
  };
@@ -15,6 +15,7 @@ const {
15
15
  HANDOFF_MODES,
16
16
  INTERRUPTED_STATUSES,
17
17
  RETURN_REASONS,
18
+ URGENCY_RANK,
18
19
  getEscalationReview,
19
20
  } = require('../models/escalationReviewModel');
20
21
  const { getPatientAuditLog } = require('../models/patientAuditLogModel');
@@ -58,7 +59,6 @@ const DECIDABLE_STATUSES = ['draft_ready', 'awaiting_doctor'];
58
59
  const FOLLOWUP_STATUSES = ['indications_sent', 'indications_queued'];
59
60
  const SETTLED_TRAJECTORIES = ['improving', 'stable'];
60
61
  const ALERTED_URGENCIES = ['stat', 'asap'];
61
- const URGENCY_RANK = { routine: 1, urgent: 2, asap: 3, stat: 4 };
62
62
  const DEFAULT_STAT_REALERT_MINUTES = 15;
63
63
  const PRE_DECISION_STATUSES = ['open', 'documenting', 'draft_ready', 'handing_off', 'awaiting_doctor'];
64
64
  const ALERT_OPERATOR = 'bot:escalationAlert';
@@ -1442,7 +1442,7 @@ async function recordDoctorDecision({
1442
1442
  ? { status: 'cancelled', closedBy: operator, closedAt: new Date(), cancellationReason: `no_requiere${comment ? `: ${comment}` : ''}` }
1443
1443
  : { status: statusAfter(decision) },
1444
1444
  // Nothing new since the draft was checked against: an update landing meanwhile refuses the decision.
1445
- }, { drafts: { $size: review.drafts.length }, alarms: { $size: (review.alarms ?? []).length }, updates: { $size: (review.updates ?? []).length } });
1445
+ }, { drafts: { $size: review.drafts.length }, alarms: { $size: (review.alarms ?? []).length }, ...latestUpdateGuard(review) });
1446
1446
  await audit(updated, operator, requestId, {
1447
1447
  action: 'doctor_decision', decision, source, draftNumber, ...(returnReason && { returnReason }),
1448
1448
  });
@@ -1524,6 +1524,13 @@ async function recordDirectIndication({ code, triggeredBy, body, messageId = nul
1524
1524
  }
1525
1525
  }
1526
1526
 
1527
+ // The updates history is capped, so once full its length stays put; the guard names the newest update.
1528
+ const latestUpdateGuard = (review) => {
1529
+ const updates = review.updates ?? [];
1530
+ if (!updates.length) return { 'updates.0': { $exists: false } };
1531
+ return { updates: { $size: updates.length }, [`updates.${updates.length - 1}.turnId`]: updates.at(-1).turnId };
1532
+ };
1533
+
1527
1534
  const arrivedAfter = (review, since) => Boolean(since) && [
1528
1535
  ...(review.alarms ?? []).map((alarm) => alarm.raisedAt),
1529
1536
  ...(review.updates ?? []).map((update) => update.at),
@@ -1,8 +1,7 @@
1
1
  const { httpError } = require('../utils/httpErrorUtils');
2
- const { getEscalationReview } = require('../models/escalationReviewModel');
2
+ const { URGENCY_RANK, getEscalationReview } = require('../models/escalationReviewModel');
3
3
 
4
4
  const DONE_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
5
- const URGENCY_RANK = { stat: 4, asap: 3, urgent: 2, routine: 1 };
6
5
  const RETURNED_STATUSES = ['returned'];
7
6
  const FOLLOWUP_STATUSES = ['indications_sent', 'indications_queued'];
8
7
  const DONE_STATUSES = ['closed', 'cancelled'];
@@ -45,6 +44,7 @@ const boardRowOf = (review, bucket) => {
45
44
  alarmCount: alarms.length,
46
45
  since,
47
46
  closedAt: review.closedAt || null,
47
+ updatedSinceSeen: review.updatedSinceSeen === true,
48
48
  };
49
49
  };
50
50
 
@@ -56,7 +56,7 @@ const byMostRecentlyClosed = (a, b) => new Date(b.closedAt) - new Date(a.closedA
56
56
  async function listReviewBoard({ bucket, now = new Date() } = {}) {
57
57
  const reviews = await getEscalationReview()
58
58
  .find(bucketQuery(bucket, now), {
59
- patientCode: 1, status: 1, 'alarms.urgencyLevel': 1, 'alarms.symptom': 1, 'alarms.raisedAt': 1, createdAt: 1, closedAt: 1,
59
+ patientCode: 1, status: 1, 'alarms.urgencyLevel': 1, 'alarms.symptom': 1, 'alarms.raisedAt': 1, createdAt: 1, closedAt: 1, updatedSinceSeen: 1,
60
60
  })
61
61
  .lean();
62
62
  const rows = reviews.map((review) => boardRowOf(review, bucket))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.61.0-dev.11232",
3
+ "version": "5.61.0-dev.11233",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",