@peopl-health/nexus 5.61.0-dev.11233 → 5.61.0-dev.11235
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.
|
@@ -796,11 +796,16 @@ async function suggestDraft({ id, requestedBy, requestId = null } = {}) {
|
|
|
796
796
|
return { ...draft, doctorText: withIdentity({ identity, review, doctorText: draft.doctorText }) };
|
|
797
797
|
}
|
|
798
798
|
|
|
799
|
-
// The most urgent level the doctor was actually alerted about
|
|
799
|
+
// The most urgent level the doctor was actually alerted about since the last decision: a failed attempt
|
|
800
|
+
// told them nothing, and a review reopened after a decision is a new question for them.
|
|
800
801
|
// Scheduling and sending gate on the same one.
|
|
801
|
-
const alertedRankOf = (review) =>
|
|
802
|
-
|
|
803
|
-
|
|
802
|
+
const alertedRankOf = (review) => {
|
|
803
|
+
const decidedAt = (review.decisions ?? []).at(-1)?.createdAt;
|
|
804
|
+
const sinceMs = decidedAt ? new Date(decidedAt).getTime() : -Infinity;
|
|
805
|
+
return Math.max(0, ...(review.doctorAlerts ?? [])
|
|
806
|
+
.filter((sent) => sent.kind === 'initial' && !sent.error && new Date(sent.sentAt).getTime() > sinceMs)
|
|
807
|
+
.map((sent) => URGENCY_RANK[sent.urgencyLevel] || 0));
|
|
808
|
+
};
|
|
804
809
|
|
|
805
810
|
// A stat or asap alarm more urgent than anything the doctor was already told about is due now.
|
|
806
811
|
async function scheduleDoctorAlert(review, alarm, now) {
|
|
@@ -846,8 +851,15 @@ async function prepareDoctorAlert(review, kind, urgencyLevel) {
|
|
|
846
851
|
return { approver, message };
|
|
847
852
|
}
|
|
848
853
|
|
|
849
|
-
|
|
850
|
-
|
|
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
|
+
};
|
|
851
863
|
|
|
852
864
|
const realertStillDue = (review, initial) => !review.closedAt && Boolean(initial) && !answeredSince(review, initial.sentAt);
|
|
853
865
|
|