@peopl-health/nexus 5.44.0-dev.6864 → 5.44.0-dev.6881
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.
|
@@ -15,6 +15,7 @@ const { cleanupFiles } = require('../../helpers/filesHelper.js');
|
|
|
15
15
|
const { getMessages, countMessages } = require('../../services/messageService');
|
|
16
16
|
|
|
17
17
|
const { getAssistantById } = require('./assistantResolver');
|
|
18
|
+
const { recordPausedThreadMessage } = require('./clinicalAirtableService');
|
|
18
19
|
|
|
19
20
|
const MEDIA_BACKLOG_LIMIT = 10;
|
|
20
21
|
|
|
@@ -111,6 +112,8 @@ const preProcessMessagesCore = async (code, message_ = null, thread) => {
|
|
|
111
112
|
return { shouldProcess: false, messages: null, timings, pendingMediaUpdates: [] };
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
if (thread.stopped) await recordPausedThreadMessage({ code, text: lastMessage[0].plainBody || lastMessage[0].body });
|
|
116
|
+
|
|
114
117
|
const backlog = await fetchMediaBacklog(code, lastMessage[0]);
|
|
115
118
|
const replies = [...backlog, ...lastMessage];
|
|
116
119
|
|
|
@@ -12,6 +12,8 @@ const recentIntakeCache = new MapCache({ maxSize: 1000, ttl: 15 * 60 * 1000 });
|
|
|
12
12
|
const EMERGENCY_MERGE_WINDOW_MS = 5 * 60 * 1000;
|
|
13
13
|
const EMERGENCY_URGENCY_RANK = { routine: 0, urgent: 1, asap: 2, stat: 3 };
|
|
14
14
|
const recentEmergencyCache = new MapCache({ maxSize: 500, ttl: EMERGENCY_MERGE_WINDOW_MS });
|
|
15
|
+
const PAUSED_ALERT_WINDOW_MS = 4 * 60 * 60 * 1000;
|
|
16
|
+
const recentPausedAlertCache = new MapCache({ maxSize: 1000, ttl: PAUSED_ALERT_WINDOW_MS });
|
|
15
17
|
const RECORD_ID_RX = /^rec[A-Za-z0-9]+$/;
|
|
16
18
|
|
|
17
19
|
const MEDICAL_URGENCY_TO_EMERGENCY_LEVEL = {
|
|
@@ -97,6 +99,20 @@ async function recordUnresolvedRequest({ code, trace, question, details, resolut
|
|
|
97
99
|
});
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
async function recordPausedThreadMessage({ code, text }) {
|
|
103
|
+
if (recentPausedAlertCache.get(code)) return false;
|
|
104
|
+
const isWritten = await recordUnresolvedRequest({
|
|
105
|
+
code,
|
|
106
|
+
trace: null,
|
|
107
|
+
question: text || 'El paciente envió un archivo sin texto.',
|
|
108
|
+
details: `Bot en pausa: el paciente ${code} escribió y nadie ha respondido. Revisar la conversación.`,
|
|
109
|
+
category: 'contact_team_member',
|
|
110
|
+
urgency: 'soon',
|
|
111
|
+
});
|
|
112
|
+
if (isWritten) recentPausedAlertCache.set(code, true);
|
|
113
|
+
return isWritten;
|
|
114
|
+
}
|
|
115
|
+
|
|
100
116
|
async function readEmergencyRow(recordId, code) {
|
|
101
117
|
try {
|
|
102
118
|
const open = await airtableService.getRecordByFilter(Monitoreo_ID, 'emergencies', `RECORD_ID() = '${recordId}'`, null);
|
|
@@ -161,6 +177,7 @@ async function recordEmergency({ code, trace, symptom, suspectedCondition = '',
|
|
|
161
177
|
function _clearRecentIntakeCache() {
|
|
162
178
|
recentIntakeCache.clear();
|
|
163
179
|
recentEmergencyCache.clear();
|
|
180
|
+
recentPausedAlertCache.clear();
|
|
164
181
|
}
|
|
165
182
|
|
|
166
183
|
async function recordClinicalIntake({ code, trace, messageRaw, source = 'self', isLive = null }) {
|
|
@@ -379,6 +396,7 @@ async function recordClusterRecommendationsMirror({ code, triageRecordId, step1
|
|
|
379
396
|
|
|
380
397
|
module.exports = {
|
|
381
398
|
recordUnresolvedRequest,
|
|
399
|
+
recordPausedThreadMessage,
|
|
382
400
|
recordEmergency,
|
|
383
401
|
recordClinicalIntake,
|
|
384
402
|
recordReminder,
|