@peopl-health/nexus 5.51.0-dev.7643 → 5.51.0-dev.7644
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.
|
@@ -4,7 +4,6 @@ const { redactDirectIdentifiers } = require('../utils/sanitizerUtils');
|
|
|
4
4
|
const {
|
|
5
5
|
addCallLog,
|
|
6
6
|
addDraft,
|
|
7
|
-
cancelEscalationReview,
|
|
8
7
|
closeEscalationReview,
|
|
9
8
|
getEscalationReviewById,
|
|
10
9
|
handOffToDoctor,
|
|
@@ -136,16 +135,6 @@ const closeEscalationReviewController = async (req, res) => {
|
|
|
136
135
|
}
|
|
137
136
|
};
|
|
138
137
|
|
|
139
|
-
const cancelEscalationReviewController = async (req, res) => {
|
|
140
|
-
try {
|
|
141
|
-
const { triggeredBy, reason = null } = req.body || {};
|
|
142
|
-
const review = await cancelEscalationReview({ id: req.params.id, cancelledBy: triggeredBy, reason, requestId: req.requestId });
|
|
143
|
-
res.status(200).json({ success: true, review });
|
|
144
|
-
} catch (error) {
|
|
145
|
-
respondWithError(res, error, 'cancelling escalation review', { reviewId: req.params?.id });
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
138
|
const syncEscalationReviewCaseController = async (req, res) => {
|
|
150
139
|
try {
|
|
151
140
|
const { triggeredBy } = req.body || {};
|
|
@@ -163,7 +152,6 @@ const syncEscalationReviewCaseController = async (req, res) => {
|
|
|
163
152
|
module.exports = {
|
|
164
153
|
addEscalationReviewCallLogController,
|
|
165
154
|
addEscalationReviewDraftController,
|
|
166
|
-
cancelEscalationReviewController,
|
|
167
155
|
closeEscalationReviewController,
|
|
168
156
|
getEscalationReviewController,
|
|
169
157
|
handOffEscalationReviewController,
|
|
@@ -7,7 +7,6 @@ const { logger } = require('../utils/logger');
|
|
|
7
7
|
const CALL_OUTCOMES = ['contacted', 'no_answer', 'voicemail'];
|
|
8
8
|
const HANDOFF_MODES = ['sent_whatsapp', 'copied'];
|
|
9
9
|
const INTERRUPTED_STATUSES = ['handing_off', 'sending'];
|
|
10
|
-
const CANCELLABLE_STATUSES = ['open', 'documenting', 'draft_ready'];
|
|
11
10
|
const DOCTOR_DECISIONS = ['approved', 'edited_approved', 'needs_intervention', 'returned'];
|
|
12
11
|
const DECISION_SOURCES = ['platform', 'registered_by_navigator'];
|
|
13
12
|
|
|
@@ -84,7 +83,6 @@ const escalationReviewSchema = new mongoose.Schema({
|
|
|
84
83
|
'indications_queued',
|
|
85
84
|
'indications_sent',
|
|
86
85
|
'closed',
|
|
87
|
-
'cancelled',
|
|
88
86
|
],
|
|
89
87
|
default: 'open',
|
|
90
88
|
},
|
|
@@ -102,7 +100,6 @@ const escalationReviewSchema = new mongoose.Schema({
|
|
|
102
100
|
|
|
103
101
|
escalationReviewSchema.index({ patientCode: 1, createdAt: -1 });
|
|
104
102
|
escalationReviewSchema.index({ activeCaseKey: 1 }, { unique: true, sparse: true });
|
|
105
|
-
escalationReviewSchema.index({ patientCode: 1 }, { unique: true, partialFilterExpression: { closedAt: null } });
|
|
106
103
|
|
|
107
104
|
const getEscalationReview = () => {
|
|
108
105
|
const dbName = getModelDatabase('EscalationReview');
|
|
@@ -113,7 +110,6 @@ const getEscalationReview = () => {
|
|
|
113
110
|
|
|
114
111
|
module.exports = {
|
|
115
112
|
CALL_OUTCOMES,
|
|
116
|
-
CANCELLABLE_STATUSES,
|
|
117
113
|
DECISION_SOURCES,
|
|
118
114
|
DOCTOR_DECISIONS,
|
|
119
115
|
HANDOFF_MODES,
|
package/lib/routes/index.js
CHANGED
|
@@ -126,7 +126,6 @@ const escalationReviewRouteDefinitions = {
|
|
|
126
126
|
'POST /:id/decisions': 'recordEscalationReviewDecisionController',
|
|
127
127
|
'POST /:id/patient-deliveries': 'sendEscalationReviewIndicationsController',
|
|
128
128
|
'POST /:id/close': 'closeEscalationReviewController',
|
|
129
|
-
'POST /:id/cancel': 'cancelEscalationReviewController',
|
|
130
129
|
'POST /:id/case-sync': 'syncEscalationReviewCaseController'
|
|
131
130
|
};
|
|
132
131
|
|
|
@@ -286,7 +285,6 @@ const builtInControllers = {
|
|
|
286
285
|
recordEscalationReviewDecisionController: escalationReviewController.recordEscalationReviewDecisionController,
|
|
287
286
|
sendEscalationReviewIndicationsController: escalationReviewController.sendEscalationReviewIndicationsController,
|
|
288
287
|
closeEscalationReviewController: escalationReviewController.closeEscalationReviewController,
|
|
289
|
-
cancelEscalationReviewController: escalationReviewController.cancelEscalationReviewController,
|
|
290
288
|
syncEscalationReviewCaseController: escalationReviewController.syncEscalationReviewCaseController
|
|
291
289
|
};
|
|
292
290
|
|
|
@@ -6,7 +6,6 @@ const { logger } = require('../utils/logger');
|
|
|
6
6
|
const { PATIENT_CODE, redactDirectIdentifiers } = require('../utils/sanitizerUtils');
|
|
7
7
|
const {
|
|
8
8
|
CALL_OUTCOMES,
|
|
9
|
-
CANCELLABLE_STATUSES,
|
|
10
9
|
DECISION_SOURCES,
|
|
11
10
|
DOCTOR_DECISIONS,
|
|
12
11
|
HANDOFF_MODES,
|
|
@@ -249,24 +248,6 @@ const deliveryTransport = (message, result) => {
|
|
|
249
248
|
return result.deferred ? 'template_recovery' : 'text';
|
|
250
249
|
};
|
|
251
250
|
|
|
252
|
-
let indexesReady = new WeakMap();
|
|
253
|
-
|
|
254
|
-
function ensureActiveReviewIndex(EscalationReview) {
|
|
255
|
-
const pending = indexesReady.get(EscalationReview);
|
|
256
|
-
if (pending) return pending;
|
|
257
|
-
|
|
258
|
-
const building = EscalationReview.ensureIndexes().catch((error) => {
|
|
259
|
-
indexesReady.delete(EscalationReview);
|
|
260
|
-
if (error?.code !== DUPLICATE_KEY_ERROR) throw error;
|
|
261
|
-
logger.error('[EscalationReview] A uniqueness index could not be built', { error: redactedError(error) });
|
|
262
|
-
throw httpError(409, 'Escalation reviews cannot be opened: a uniqueness index could not be built. The server log names the index and the conflict; resolve it and retry.');
|
|
263
|
-
});
|
|
264
|
-
indexesReady.set(EscalationReview, building);
|
|
265
|
-
return building;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const _resetEscalationReviewIndexes = () => { indexesReady = new WeakMap(); };
|
|
269
|
-
|
|
270
251
|
async function openEscalationReview({ code, patientCaseRecordId = null, openedBy, requestId = null } = {}) {
|
|
271
252
|
const patientCode = patientCodeOf(code);
|
|
272
253
|
const operator = requiredText(openedBy, 'openedBy');
|
|
@@ -283,14 +264,14 @@ async function openEscalationReview({ code, patientCaseRecordId = null, openedBy
|
|
|
283
264
|
}
|
|
284
265
|
|
|
285
266
|
const EscalationReview = getEscalationReview();
|
|
286
|
-
await
|
|
267
|
+
await EscalationReview.init();
|
|
287
268
|
let review;
|
|
288
269
|
try {
|
|
289
270
|
review = (await EscalationReview.create(fields)).toObject();
|
|
290
271
|
} catch (error) {
|
|
291
|
-
if (error?.code !== DUPLICATE_KEY_ERROR) throw error;
|
|
292
|
-
const existing = await EscalationReview.findOne({
|
|
293
|
-
if (!existing) throw httpError(409, '
|
|
272
|
+
if (error?.code !== DUPLICATE_KEY_ERROR || !fields.activeCaseKey) throw error;
|
|
273
|
+
const existing = await EscalationReview.findOne({ activeCaseKey: fields.activeCaseKey }).lean();
|
|
274
|
+
if (!existing) throw httpError(409, 'The patient case review changed while opening; try again');
|
|
294
275
|
return { review: existing, created: false };
|
|
295
276
|
}
|
|
296
277
|
await audit(review, operator, requestId, { action: 'opened', patientCaseRecordId });
|
|
@@ -543,17 +524,6 @@ async function closeEscalationReview({ id, closedBy, deliveryConfirmed = false,
|
|
|
543
524
|
return syncCase(review, operator, requestId);
|
|
544
525
|
}
|
|
545
526
|
|
|
546
|
-
async function cancelEscalationReview({ id, cancelledBy, reason = null, requestId = null } = {}) {
|
|
547
|
-
const reviewId = reviewIdOf(id);
|
|
548
|
-
const operator = requiredText(cancelledBy, 'cancelledBy');
|
|
549
|
-
const review = await updateReview(reviewId, CANCELLABLE_STATUSES, {
|
|
550
|
-
$set: { status: 'cancelled', closedBy: operator, closedAt: new Date() },
|
|
551
|
-
$unset: { activeCaseKey: '' },
|
|
552
|
-
});
|
|
553
|
-
await audit(review, operator, requestId, { action: 'cancelled', reason: optionalText(reason) });
|
|
554
|
-
return review;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
527
|
async function syncEscalationReviewCase({ id, syncedBy, requestId = null } = {}) {
|
|
558
528
|
const reviewId = reviewIdOf(id);
|
|
559
529
|
const operator = requiredText(syncedBy, 'syncedBy');
|
|
@@ -561,10 +531,8 @@ async function syncEscalationReviewCase({ id, syncedBy, requestId = null } = {})
|
|
|
561
531
|
}
|
|
562
532
|
|
|
563
533
|
module.exports = {
|
|
564
|
-
_resetEscalationReviewIndexes,
|
|
565
534
|
addCallLog,
|
|
566
535
|
addDraft,
|
|
567
|
-
cancelEscalationReview,
|
|
568
536
|
closeEscalationReview,
|
|
569
537
|
getEscalationReviewById,
|
|
570
538
|
handOffToDoctor,
|