@peopl-health/nexus 6.4.9 → 6.4.10
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.
|
@@ -36,6 +36,10 @@ function escalationWatchExpiryLive() {
|
|
|
36
36
|
return flagNotOff('ESCALATION_WATCH_EXPIRY_LIVE');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
function escalationWatchTeamNoticeLive() {
|
|
40
|
+
return flagOn('ESCALATION_WATCH_TEAM_NOTICE_LIVE');
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
module.exports = {
|
|
40
44
|
escalationApproverAlertLive,
|
|
41
45
|
escalationAssessmentLive,
|
|
@@ -44,5 +48,6 @@ module.exports = {
|
|
|
44
48
|
escalationUntakenAlertsLive,
|
|
45
49
|
escalationUpdateModeLive,
|
|
46
50
|
escalationWatchExpiryLive,
|
|
51
|
+
escalationWatchTeamNoticeLive,
|
|
47
52
|
feverPatientTimerLive,
|
|
48
53
|
};
|
|
@@ -2,7 +2,7 @@ const { logger } = require('../utils/logger');
|
|
|
2
2
|
const { redactDirectIdentifiers } = require('../utils/sanitizerUtils');
|
|
3
3
|
const { getEscalationReview } = require('../models/escalationReviewModel');
|
|
4
4
|
const { readGroupMessageId } = require('../clinical/services/clinicalAirtableService');
|
|
5
|
-
const { escalationWatchExpiryLive } = require('../clinical/flags/escalationFlags');
|
|
5
|
+
const { escalationWatchExpiryLive, escalationWatchTeamNoticeLive } = require('../clinical/flags/escalationFlags');
|
|
6
6
|
|
|
7
7
|
const { countMessages } = require('./messageService');
|
|
8
8
|
const { logPatientChange } = require('./patientService');
|
|
@@ -24,6 +24,7 @@ const TEAM_WAIT_MS = 2 * 60 * 60 * 1000;
|
|
|
24
24
|
// A reminder this late (an outage, a deploy) is not sent; the team notice still goes.
|
|
25
25
|
const STALE_MS = 30 * 60 * 1000;
|
|
26
26
|
const getMessaging = () => require('../core/NexusMessaging');
|
|
27
|
+
const REMINDED_UNTILS = { $map: { input: { $filter: { input: { $ifNull: ['$watchNotices', []] }, cond: { $eq: ['$$this.kind', 'reminder'] } } }, in: '$$this.until' } };
|
|
27
28
|
|
|
28
29
|
const timeOf = (value) => new Date(value).getTime();
|
|
29
30
|
|
|
@@ -128,12 +129,16 @@ async function noticeTeam(review, reminder, now) {
|
|
|
128
129
|
return true;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
// A watch that ran out is never closed silently: the patient gets one reminder, then the team is told.
|
|
132
|
+
// A watch that ran out is never closed silently: the patient gets one reminder, then the team is told while its flag is on.
|
|
132
133
|
async function sweepExpiredWatches({ now = new Date() } = {}) {
|
|
133
134
|
if (!escalationWatchExpiryLive()) return 0;
|
|
135
|
+
const teamNotice = escalationWatchTeamNoticeLive();
|
|
136
|
+
const query = { closedAt: null, status: 'monitoring', monitoringUntil: { $lte: now } };
|
|
137
|
+
// With no team notice a reminded watch has nothing left to send, so it must not hold a sweep slot.
|
|
138
|
+
if (!teamNotice) query.$expr = { $not: [{ $in: ['$monitoringUntil', REMINDED_UNTILS] }] };
|
|
134
139
|
const reviews = await getEscalationReview()
|
|
135
140
|
.find(
|
|
136
|
-
|
|
141
|
+
query,
|
|
137
142
|
{ patientCode: 1, status: 1, monitoringUntil: 1, watchNotices: 1, 'alarms.emergencyRecordId': 1 },
|
|
138
143
|
)
|
|
139
144
|
.sort({ monitoringUntil: 1 })
|
|
@@ -144,6 +149,7 @@ async function sweepExpiredWatches({ now = new Date() } = {}) {
|
|
|
144
149
|
try {
|
|
145
150
|
if (noticesOf(review, 'team').some((entry) => !failed(entry))) continue;
|
|
146
151
|
const [reminder] = noticesOf(review, 'reminder');
|
|
152
|
+
if (reminder && !teamNotice) continue;
|
|
147
153
|
if (await (reminder ? noticeTeam(review, reminder, now) : remindPatient(review, now))) sent += 1;
|
|
148
154
|
} catch (error) {
|
|
149
155
|
logger.error('[WatchExpiry] Could not check an expired watch', { escalationReviewId: String(review._id), error: redactDirectIdentifiers(String(error?.message || error)) });
|