@peopl-health/nexus 6.4.13 → 6.4.14
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.
|
@@ -2195,24 +2195,19 @@ function replyOutcome(delivery, sendThrew) {
|
|
|
2195
2195
|
}
|
|
2196
2196
|
|
|
2197
2197
|
// A notice that fails is logged and never undoes what it reports.
|
|
2198
|
-
async function noticeCaseThread(review, { header,
|
|
2198
|
+
async function noticeCaseThread(review, { header, action, kind }) {
|
|
2199
2199
|
try {
|
|
2200
2200
|
const { patient, doctor, link } = await teamAlertIdentity(review);
|
|
2201
2201
|
// Every alarm, not only those since the decision: the case's alarm always came before it.
|
|
2202
2202
|
const recordId = [...(review.alarms ?? [])].reverse().find((alarm) => alarm.emergencyRecordId)?.emergencyRecordId;
|
|
2203
2203
|
const quoted = await readGroupMessageId(recordId, review.patientCode);
|
|
2204
|
-
const sent = await sendGroupNotice([header, `${patient} (${doctor})`,
|
|
2204
|
+
const sent = await sendGroupNotice([header, `${patient} (${doctor})`, action, link].join('\n'), quoted, [header, action].join('\n'));
|
|
2205
2205
|
if (!sent.delivered) logger.error(`[EscalationReview] The ${kind} notice did not reach the group`, { escalationReviewId: String(review._id), error: sent.error });
|
|
2206
2206
|
} catch (error) {
|
|
2207
2207
|
logger.error(`[EscalationReview] The ${kind} notice failed`, { escalationReviewId: String(review._id), error: redactedError(error) });
|
|
2208
2208
|
}
|
|
2209
2209
|
}
|
|
2210
2210
|
|
|
2211
|
-
const notifyPlanIssues = (review, issues) => noticeCaseThread(review, {
|
|
2212
|
-
header: '⚠️ Revisar el envío del plan', lines: issues.map((issue) => `- ${issue}`), kind: 'plan check',
|
|
2213
|
-
action: 'Qué hacer: revisar el chat; corregir con la paciente o volver a mandar la receta si hace falta',
|
|
2214
|
-
});
|
|
2215
|
-
|
|
2216
2211
|
async function sendPlanThroughAssistant({ claimed, claim, decisionNumber, plan, operator, requestId }) {
|
|
2217
2212
|
const reviewId = claimed._id;
|
|
2218
2213
|
const release = () => releaseReview(reviewId, 'sending', 'approved', claim).catch((releaseError) => {
|
|
@@ -2250,7 +2245,6 @@ async function sendPlanThroughAssistant({ claimed, claim, decisionNumber, plan,
|
|
|
2250
2245
|
}
|
|
2251
2246
|
if (outcome === 'unknown') {
|
|
2252
2247
|
logger.error('[EscalationReview] The assistant reply could not be confirmed; leaving the review in sending', { escalationReviewId: String(reviewId) });
|
|
2253
|
-
await notifyPlanIssues(claimed, ['no se pudo confirmar que el mensaje salió; el caso sigue en «enviando»']);
|
|
2254
2248
|
throw httpError(502, 'The assistant reply could not be confirmed; check the chat before sending again', SEND_UNCONFIRMED);
|
|
2255
2249
|
}
|
|
2256
2250
|
|
|
@@ -2270,10 +2264,14 @@ async function sendPlanThroughAssistant({ claimed, claim, decisionNumber, plan,
|
|
|
2270
2264
|
await audit(review, operator, requestId, {
|
|
2271
2265
|
action: status, decisionNumber, transport: 'assistant', checks: issues.length, ...(prescriberEmail && { prescription: prescriptionFailed ? 'failed' : 'created' }),
|
|
2272
2266
|
});
|
|
2273
|
-
if (
|
|
2267
|
+
if (prescriptionFailed) {
|
|
2268
|
+
await noticeCaseThread(review, {
|
|
2269
|
+
header: '⚠️ No se pudo crear la receta', kind: 'prescription',
|
|
2270
|
+
action: 'Qué hacer: revisar el chat y volver a mandar la receta',
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2274
2273
|
if (!queued) await armCaseFollowUp(review);
|
|
2275
|
-
|
|
2276
|
-
if (plan.followUp.kind === 'none' && !queued && !issues.length) {
|
|
2274
|
+
if (plan.followUp.kind === 'none' && !queued && !prescriptionFailed) {
|
|
2277
2275
|
try {
|
|
2278
2276
|
return await closeEscalationReview({ id: reviewId, closedBy: operator, requestId });
|
|
2279
2277
|
} catch (error) {
|