@peopl-health/nexus 5.59.7 → 5.59.8

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.
@@ -86,32 +86,12 @@ const audit = (review, updatedBy, requestId, changes) => logPatientChange({
86
86
  changes: { escalationReviewId: String(review._id), ...changes },
87
87
  });
88
88
 
89
- async function pauseAssistantFor(patientCode) {
90
- try {
91
- const result = await switchThreadStoppedStatus(patientCode, true, { byOperator: true });
92
- return Boolean(result?.modifiedCount);
93
- } catch (error) {
94
- logger.error('[EscalationReview] The assistant could not be paused for this patient', { error: error.message });
95
- return false;
96
- }
97
- }
98
-
99
- const passPauseToOpenReview = (review) => getEscalationReview().findOneAndUpdate(
100
- { patientCode: review.patientCode, closedAt: null, _id: { $ne: review._id } },
101
- { $set: { assistantPausedByReview: true } },
102
- ).lean();
103
-
104
89
  async function resumeAssistant(review, operator = null, requestId = null) {
105
90
  if (review.assistantPausedByReview !== true) return review;
106
91
  const stopClaiming = () => getEscalationReview()
107
92
  .updateOne({ _id: review._id }, { $set: { assistantPausedByReview: false } });
108
93
  try {
109
- if (!await passPauseToOpenReview(review)) {
110
- await switchThreadStoppedStatus(review.patientCode, false);
111
- if (await passPauseToOpenReview(review)) {
112
- await switchThreadStoppedStatus(review.patientCode, true, { byOperator: true });
113
- }
114
- }
94
+ await switchThreadStoppedStatus(review.patientCode, false);
115
95
  await stopClaiming();
116
96
  return { ...review, assistantPausedByReview: false };
117
97
  } catch (error) {
@@ -481,10 +461,7 @@ async function openEscalationReview({
481
461
  if (!patient) throw httpError(404, 'Patient not found');
482
462
 
483
463
  const recordIds = await requestedCaseIds({ patientCode, patientCaseRecordId, patientCaseRecordIds });
484
- const pausedHere = await pauseAssistantFor(patientCode);
485
- const fields = {
486
- patientCode, openedBy: operator, patientCaseRecordIds: recordIds, assistantPausedByReview: pausedHere,
487
- };
464
+ const fields = { patientCode, openedBy: operator, patientCaseRecordIds: recordIds, assistantPausedByReview: false };
488
465
 
489
466
  const EscalationReview = getEscalationReview();
490
467
  let review;
@@ -492,19 +469,9 @@ async function openEscalationReview({
492
469
  await ensureActiveReviewIndex(EscalationReview);
493
470
  review = (await EscalationReview.create(fields)).toObject();
494
471
  } catch (error) {
495
- if (error?.code !== DUPLICATE_KEY_ERROR) {
496
- if (pausedHere) {
497
- await switchThreadStoppedStatus(patientCode, false).catch((resumeError) => {
498
- logger.error('[EscalationReview] A failed open left the assistant paused', {
499
- error: resumeError.message,
500
- });
501
- });
502
- }
503
- throw error;
504
- }
472
+ if (error?.code !== DUPLICATE_KEY_ERROR) throw error;
505
473
  let existing = await EscalationReview.findOne({ patientCode, closedAt: null }).lean();
506
474
  if (!existing) {
507
- if (pausedHere) await switchThreadStoppedStatus(patientCode, false).catch(() => {});
508
475
  throw httpError(409, 'This patient already has a review being opened; try again in a moment');
509
476
  }
510
477
  if (recordIds.length && !(existing.patientCaseRecordIds ?? []).length) {
@@ -519,29 +486,13 @@ async function openEscalationReview({
519
486
  } else {
520
487
  const fresh = await EscalationReview.findOne({ _id: existing._id, closedAt: null }).lean();
521
488
  if (!fresh) {
522
- if (pausedHere) await switchThreadStoppedStatus(patientCode, false).catch(() => {});
523
489
  throw httpError(409, 'The review closed while this one was being opened; try again');
524
490
  }
525
491
  existing = fresh;
526
492
  }
527
493
  }
528
- if (pausedHere && existing.assistantPausedByReview !== true) {
529
- try {
530
- await EscalationReview.updateOne({ _id: existing._id }, { $set: { assistantPausedByReview: true } });
531
- existing.assistantPausedByReview = true;
532
- } catch (error) {
533
- logger.error('[EscalationReview] The pause was not recorded against the open review', {
534
- escalationReviewId: String(existing._id), error: error.message,
535
- });
536
- }
537
- }
538
494
  return { review: existing, created: false };
539
495
  }
540
- const held = pausedHere || await pauseAssistantFor(patientCode);
541
- if (held !== review.assistantPausedByReview) {
542
- await EscalationReview.updateOne({ _id: review._id }, { $set: { assistantPausedByReview: held } });
543
- review.assistantPausedByReview = held;
544
- }
545
496
  await audit(review, operator, requestId, { action: 'opened', patientCaseRecordIds: recordIds });
546
497
  return { review, created: true };
547
498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.59.7",
3
+ "version": "5.59.8",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",