@peopl-health/nexus 5.59.0-dev.10730 → 5.59.0-dev.10731
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.
|
@@ -930,7 +930,7 @@ async function handOffToDoctor({ id, mode, physicianEmail = null, sentBy, reques
|
|
|
930
930
|
const sent = delivery.transport === 'template' ? Object.values(message.template).join('\n') : message.body;
|
|
931
931
|
const handoff = {
|
|
932
932
|
$push: { doctorHandoffs: { mode, draftNumber, ...delivery, message: sent, sentBy: operator } },
|
|
933
|
-
$
|
|
933
|
+
$addToSet: { patientCaseRecordIds: { $each: patientCaseRecordIds } },
|
|
934
934
|
$unset: { identityBlock: '' },
|
|
935
935
|
};
|
|
936
936
|
const recordUpdate = withCaseMirror({ ...review, patientCaseRecordIds }, handoff, { status: 'en revision_medica' });
|
|
@@ -1076,22 +1076,25 @@ async function sendApprovedIndications({ id, outsideWindowRoute = null, sentBy,
|
|
|
1076
1076
|
const review = await completeOperation(reviewId, claim, 'sending', recordUpdate, status);
|
|
1077
1077
|
await audit(review, operator, requestId, { action: status, decisionNumber, transport: delivery.transport });
|
|
1078
1078
|
const sent = await syncCase(review, operator, requestId);
|
|
1079
|
-
if (review.status !== 'indications_sent' || decision === 'needs_intervention'
|
|
1080
|
-
const
|
|
1081
|
-
|
|
1082
|
-
|
|
1079
|
+
if (review.status !== 'indications_sent' || decision === 'needs_intervention') return sent;
|
|
1080
|
+
const decided = review.decisions[decisionNumber - 1];
|
|
1081
|
+
const decidedOn = new Date(review.drafts?.[decided?.draftNumber - 1]?.createdAt ?? decided?.createdAt ?? 0).getTime();
|
|
1082
|
+
if ((review.alarms ?? []).some((alarm) => new Date(alarm.raisedAt).getTime() > decidedOn)) {
|
|
1083
|
+
logger.warn('[EscalationReview] An alarm arrived after the draft the doctor decided on; the review stays open for it', {
|
|
1083
1084
|
escalationReviewId: String(review._id),
|
|
1084
1085
|
});
|
|
1085
1086
|
return sent;
|
|
1086
1087
|
}
|
|
1087
1088
|
try {
|
|
1088
1089
|
const closed = await closeEscalationReview({ id: reviewId, closedBy: operator, requestId, expectedAlarmCount: (review.alarms ?? []).length });
|
|
1089
|
-
return
|
|
1090
|
+
return closed;
|
|
1090
1091
|
} catch (error) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1092
|
+
const stored = await loadReview(reviewId).catch(() => sent.review);
|
|
1093
|
+
let note = 'The indications were delivered but the review did not close; close it by hand';
|
|
1094
|
+
if (stored.status === 'closed') note = 'The review closed, but a step after closing failed';
|
|
1095
|
+
else if (error.statusCode === 409) note = 'An alarm joined while the review was closing; it stays open for it';
|
|
1096
|
+
logger.error(`[EscalationReview] ${note}`, { escalationReviewId: String(review._id), error: redactedError(error) });
|
|
1097
|
+
return { ...sent, review: stored };
|
|
1095
1098
|
}
|
|
1096
1099
|
}
|
|
1097
1100
|
|
|
@@ -1184,7 +1187,13 @@ async function closeEscalationReview({ id, closedBy, deliveryConfirmed = false,
|
|
|
1184
1187
|
const closeChanges = { action: interrupted ? 'closed_from_interruption' : 'closed' };
|
|
1185
1188
|
if (interrupted) closeChanges.fromStatus = current.status;
|
|
1186
1189
|
if (queued) closeChanges.deliveryConfirmed = true;
|
|
1187
|
-
|
|
1190
|
+
try {
|
|
1191
|
+
await audit(review, operator, requestId, closeChanges);
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
logger.error('[EscalationReview] The review closed but its audit entry was not written', {
|
|
1194
|
+
escalationReviewId: String(review._id), error: redactedError(error),
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1188
1197
|
await recordEpisode(review);
|
|
1189
1198
|
return syncCase(await resumeAssistant(review, operator, requestId), operator, requestId);
|
|
1190
1199
|
}
|