@peopl-health/nexus 5.58.4 → 5.59.0-dev.10671
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.
|
@@ -27,7 +27,7 @@ const { readNoteFacts, assertionOf } = require('../clinical/services/escalationN
|
|
|
27
27
|
const { storeContextFacts, readContextFacts } = require('../fhir/services/clinicalContextService');
|
|
28
28
|
|
|
29
29
|
const { getPatientInformation, logPatientChange } = require('./patientService');
|
|
30
|
-
const { getPatientTasks, updatePatientTask } = require('./patientTaskService');
|
|
30
|
+
const { getPatientTasks, openCaseIds, updatePatientTask } = require('./patientTaskService');
|
|
31
31
|
const { getEscalationApprover, listEscalationApprovers } = require('./physicianService');
|
|
32
32
|
const { switchThreadStoppedStatus } = require('./threadService');
|
|
33
33
|
|
|
@@ -404,6 +404,17 @@ function ensureActiveReviewIndex(EscalationReview) {
|
|
|
404
404
|
|
|
405
405
|
const _resetEscalationReviewIndexes = () => { indexesReady = new WeakMap(); };
|
|
406
406
|
|
|
407
|
+
async function reviewCaseIds(review) {
|
|
408
|
+
try {
|
|
409
|
+
return [...new Set([...caseIdsOf(review), ...await openCaseIds(review.patientCode)])];
|
|
410
|
+
} catch (error) {
|
|
411
|
+
logger.error('[EscalationReview] The patient cases could not be read; the review keeps the cases it had', {
|
|
412
|
+
escalationReviewId: String(review._id), error: redactedError(error),
|
|
413
|
+
});
|
|
414
|
+
return caseIdsOf(review);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
407
418
|
async function requestedCaseIds({ patientCode, patientCaseRecordId, patientCaseRecordIds }) {
|
|
408
419
|
const requested = patientCaseRecordIds ?? (patientCaseRecordId === null ? [] : [patientCaseRecordId]);
|
|
409
420
|
if (!Array.isArray(requested)) throw httpError(400, 'patientCaseRecordIds must be an array of case ids');
|
|
@@ -903,6 +914,8 @@ async function handOffToDoctor({ id, mode, physicianEmail = null, sentBy, reques
|
|
|
903
914
|
template: { 1: identity.patientName, 2: identity.treatingDoctor, 3: templateSummary(review), 4: link },
|
|
904
915
|
};
|
|
905
916
|
|
|
917
|
+
const patientCaseRecordIds = await reviewCaseIds(review);
|
|
918
|
+
|
|
906
919
|
const claim = newOperationClaim();
|
|
907
920
|
await updateReview(
|
|
908
921
|
reviewId,
|
|
@@ -917,9 +930,10 @@ async function handOffToDoctor({ id, mode, physicianEmail = null, sentBy, reques
|
|
|
917
930
|
const sent = delivery.transport === 'template' ? Object.values(message.template).join('\n') : message.body;
|
|
918
931
|
const handoff = {
|
|
919
932
|
$push: { doctorHandoffs: { mode, draftNumber, ...delivery, message: sent, sentBy: operator } },
|
|
933
|
+
$set: { patientCaseRecordIds },
|
|
920
934
|
$unset: { identityBlock: '' },
|
|
921
935
|
};
|
|
922
|
-
const recordUpdate = withCaseMirror(review, handoff, { status: 'en revision_medica' });
|
|
936
|
+
const recordUpdate = withCaseMirror({ ...review, patientCaseRecordIds }, handoff, { status: 'en revision_medica' });
|
|
923
937
|
updated = await completeOperation(reviewId, claim, 'handing_off', recordUpdate, 'awaiting_doctor', handoff);
|
|
924
938
|
} catch (error) {
|
|
925
939
|
await releaseReview(reviewId, 'handing_off', review.status, claim);
|
|
@@ -145,10 +145,14 @@ const byOpenThenNewest = (a, b) => (b.isOpen - a.isOpen) || (b.createdAt || '').
|
|
|
145
145
|
|
|
146
146
|
const needsUrgentAttention = (task) => task.needsAttention && task.isUrgent;
|
|
147
147
|
|
|
148
|
-
async function
|
|
148
|
+
async function readAllTasks(kind, whatsappId) {
|
|
149
149
|
const { table, fields, toTask } = TASK_KINDS[kind];
|
|
150
150
|
const rows = await getRecordByFilter(Monitoreo_ID, table, taskFilter(kind, whatsappId), null, fields, true);
|
|
151
|
-
|
|
151
|
+
return rows.map(toTask);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function readTasks(kind, whatsappId) {
|
|
155
|
+
const tasks = (await readAllTasks(kind, whatsappId)).sort(byOpenThenNewest);
|
|
152
156
|
const capped = [...tasks.filter(needsUrgentAttention), ...tasks.filter((task) => !needsUrgentAttention(task))]
|
|
153
157
|
.slice(0, MAX_ROWS)
|
|
154
158
|
.sort(byOpenThenNewest);
|
|
@@ -160,6 +164,11 @@ async function readTasks(kind, whatsappId) {
|
|
|
160
164
|
};
|
|
161
165
|
}
|
|
162
166
|
|
|
167
|
+
async function openCaseIds(code) {
|
|
168
|
+
const cases = await readAllTasks('cases', validWhatsappId(code));
|
|
169
|
+
return cases.filter((patientCase) => patientCase.isOpen).map((patientCase) => patientCase.recordId);
|
|
170
|
+
}
|
|
171
|
+
|
|
163
172
|
async function getPatientTasks(code) {
|
|
164
173
|
const whatsappId = validWhatsappId(code);
|
|
165
174
|
const [requests, cases] = await Promise.all([readTasks('requests', whatsappId), readTasks('cases', whatsappId)]);
|
|
@@ -207,6 +216,7 @@ async function updatePatientTask({ code, kind, recordId, changes, updatedBy, sou
|
|
|
207
216
|
}
|
|
208
217
|
|
|
209
218
|
module.exports = {
|
|
219
|
+
openCaseIds,
|
|
210
220
|
getPatientTasks,
|
|
211
221
|
updatePatientTask,
|
|
212
222
|
};
|