@peopl-health/nexus 5.61.0-dev.11234 → 5.61.0-dev.11236

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.
@@ -851,8 +851,15 @@ async function prepareDoctorAlert(review, kind, urgencyLevel) {
851
851
  return { approver, message };
852
852
  }
853
853
 
854
- const topUrgencyOf = (review) => (review.alarms ?? [])
855
- .reduce((top, alarm) => (URGENCY_RANK[alarm.urgencyLevel] > (URGENCY_RANK[top] || 0) ? alarm.urgencyLevel : top), null);
854
+ // The urgency the doctor is asked about now: alarms a decision already answered do not raise it, so a
855
+ // review reopened by an asap alarm after a decided stat is an asap alert.
856
+ const topUrgencyOf = (review) => {
857
+ const alarms = review.alarms ?? [];
858
+ const decidedAt = (review.decisions ?? []).at(-1)?.createdAt;
859
+ const open = decidedAt ? alarms.filter((alarm) => new Date(alarm.raisedAt) > new Date(decidedAt)) : alarms;
860
+ return (open.length ? open : alarms)
861
+ .reduce((top, alarm) => (URGENCY_RANK[alarm.urgencyLevel] > (URGENCY_RANK[top] || 0) ? alarm.urgencyLevel : top), null);
862
+ };
856
863
 
857
864
  const realertStillDue = (review, initial) => !review.closedAt && Boolean(initial) && !answeredSince(review, initial.sentAt);
858
865
 
@@ -877,6 +884,11 @@ async function sendScheduledDoctorAlert({ id, kind, lease = null, now = new Date
877
884
  return null;
878
885
  }
879
886
  const urgencyLevel = kind === 'realert' ? initial.urgencyLevel : topUrgencyOf(review);
887
+ // Only stat and asap alert the doctor; a review reopened by a milder alarm waits for the board.
888
+ if (!ALERTED_URGENCIES.includes(urgencyLevel)) {
889
+ await release();
890
+ return null;
891
+ }
880
892
  // The doctor already heard about this urgency (a recheck, or a retry whose record landed): nothing to send.
881
893
  if (kind === 'initial' && (URGENCY_RANK[urgencyLevel] || 0) <= alertedRankOf(review)) {
882
894
  await release();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.61.0-dev.11234",
3
+ "version": "5.61.0-dev.11236",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",