@peopl-health/nexus 5.68.6 → 5.68.7
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.
|
@@ -507,6 +507,25 @@ async function recordReviewUpdate({ code, update, now = new Date(), settleInBack
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
+
const STALE_INTERRUPTION_NOTES = 'Cerrada automáticamente al llegar una alarma nueva; nadie verificó si la operación interrumpida se completó';
|
|
511
|
+
|
|
512
|
+
async function closeStaleInterruption(EscalationReview, patientCode, now) {
|
|
513
|
+
try {
|
|
514
|
+
const stale = await EscalationReview.findOne({
|
|
515
|
+
patientCode,
|
|
516
|
+
closedAt: null,
|
|
517
|
+
status: { $in: INTERRUPTED_STATUSES },
|
|
518
|
+
updatedAt: { $lte: new Date(now.getTime() - INTERRUPTION_GRACE_MS) },
|
|
519
|
+
}, { updatedAt: 1 }).lean();
|
|
520
|
+
if (!stale) return;
|
|
521
|
+
await closeEscalationReview({
|
|
522
|
+
id: String(stale._id), closedBy: BOT_OPERATOR, interruptionNotes: STALE_INTERRUPTION_NOTES, expectedUpdatedAt: stale.updatedAt,
|
|
523
|
+
});
|
|
524
|
+
} catch (error) {
|
|
525
|
+
logger[error?.statusCode === 409 ? 'warn' : 'error']('[EscalationReview] The interrupted review was not closed before the new alarm', { error: redactedError(error) });
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
510
529
|
async function recordEscalationAlarm({ code, alarm, now = new Date() } = {}) {
|
|
511
530
|
try {
|
|
512
531
|
const patientCode = patientCodeOf(code);
|
|
@@ -518,6 +537,7 @@ async function recordEscalationAlarm({ code, alarm, now = new Date() } = {}) {
|
|
|
518
537
|
.lean();
|
|
519
538
|
|
|
520
539
|
await ensureActiveReviewIndex(EscalationReview);
|
|
540
|
+
await closeStaleInterruption(EscalationReview, patientCode, now);
|
|
521
541
|
const joined = await join();
|
|
522
542
|
if (joined) {
|
|
523
543
|
await scheduleDoctorAlert(joined, entry, now);
|