@peopl-health/nexus 6.0.0-dev.16560 → 6.0.0-dev.16615
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.
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const runtimeConfig = require('../../config/runtimeConfig');
|
|
2
2
|
|
|
3
3
|
const flagOn = (key) => String(runtimeConfig.get(key, 'false')).trim().toLowerCase() === 'true';
|
|
4
|
+
// Launched behaviour stays on unless the variable is set to 'false'.
|
|
5
|
+
const flagNotOff = (key) => String(runtimeConfig.get(key, 'true')).trim().toLowerCase() !== 'false';
|
|
4
6
|
|
|
5
7
|
function escalationUpdateModeLive() {
|
|
6
|
-
return
|
|
8
|
+
return flagNotOff('ESCALATION_UPDATE_MODE_LIVE');
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
function escalationAssessmentLive() {
|
|
@@ -11,7 +13,7 @@ function escalationAssessmentLive() {
|
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
function feverPatientTimerLive() {
|
|
14
|
-
return
|
|
16
|
+
return flagNotOff('FEVER_PATIENT_TIMER_LIVE');
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
function escalationApproverAlertLive() {
|
|
@@ -19,15 +21,15 @@ function escalationApproverAlertLive() {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
function escalationPatientTimerLive() {
|
|
22
|
-
return
|
|
24
|
+
return flagNotOff('ESCALATION_PATIENT_TIMER_LIVE');
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
function escalationAutoHandoffLive() {
|
|
26
|
-
return
|
|
28
|
+
return flagNotOff('ESCALATION_AUTO_HANDOFF_LIVE');
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
function escalationUntakenAlertsLive() {
|
|
30
|
-
return
|
|
32
|
+
return flagNotOff('ESCALATION_UNTAKEN_ALERTS_LIVE');
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
module.exports = {
|
|
@@ -44,6 +44,7 @@ const { buildTriageResponse } = require('../../fhir/helpers/triagePayloadHelper'
|
|
|
44
44
|
const { keyOf } = require('../../fhir/helpers/symptomAliasHelper');
|
|
45
45
|
const { getCatalog } = require('../../fhir/services/terminologyService');
|
|
46
46
|
const { getRecordByFilter } = require('../../services/airtableService');
|
|
47
|
+
const { findArchivedByRecordIds } = require('../../services/airtableArchiveReadService');
|
|
47
48
|
const { RecommendationPlan } = require('../../shared/dtos/RecommendationPlan');
|
|
48
49
|
const { recommendationId } = require('../../fhir/helpers/recommendationIds');
|
|
49
50
|
const { RecommendationSafetyGate } = require('../../shared/dtos/RecommendationSafetyGate');
|
|
@@ -1130,8 +1131,9 @@ async function readPriorResolutions(adherence = [], patientRecordId = null) {
|
|
|
1130
1131
|
.filter((id) => /^rec[A-Za-z0-9]+$/.test(id || ''));
|
|
1131
1132
|
if (!ids.length) return [];
|
|
1132
1133
|
const formula = `OR(${ids.map((id) => `{recordID}='${id}'`).join(',')})`;
|
|
1133
|
-
const
|
|
1134
|
-
if (!
|
|
1134
|
+
const live = await getRecordByFilter(Symptoms_ID, 'cluster_resolutions', formula).catch(() => null);
|
|
1135
|
+
if (!live) return [];
|
|
1136
|
+
const rows = [...live, ...await readArchivedResolutions(ids.filter((id) => !live.some((row) => row.recordID === id)))];
|
|
1135
1137
|
if (!patientRecordId && rows.length) {
|
|
1136
1138
|
logger.warn('[triageRecommendation] prior resolutions unverified: payload carries no patientRecordId', { count: rows.length });
|
|
1137
1139
|
}
|
|
@@ -1145,6 +1147,17 @@ async function readPriorResolutions(adherence = [], patientRecordId = null) {
|
|
|
1145
1147
|
.filter(Boolean);
|
|
1146
1148
|
}
|
|
1147
1149
|
|
|
1150
|
+
// A resolution deleted from Airtable is read from its archived copy; an unreadable archive only loses that context.
|
|
1151
|
+
async function readArchivedResolutions(ids) {
|
|
1152
|
+
if (!ids.length) return [];
|
|
1153
|
+
try {
|
|
1154
|
+
return await findArchivedByRecordIds({ baseId: Symptoms_ID, tableName: 'cluster_resolutions', recordIds: ids });
|
|
1155
|
+
} catch (error) {
|
|
1156
|
+
logger.warn('[triageRecommendation] archived prior resolutions unreadable', { count: ids.length, error: error?.message });
|
|
1157
|
+
return [];
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1148
1161
|
function ownedByPatient(row, patientRecordId) {
|
|
1149
1162
|
const owners = Array.isArray(row[PATIENT_LOOKUP_FIELD]) ? row[PATIENT_LOOKUP_FIELD] : [];
|
|
1150
1163
|
if (owners.includes(patientRecordId)) return true;
|
|
@@ -179,16 +179,29 @@ async function sweepUntakenAlerts({ now = new Date() } = {}) {
|
|
|
179
179
|
.lean();
|
|
180
180
|
const policy = responseDeadlinePolicy();
|
|
181
181
|
let sent = 0;
|
|
182
|
+
const failed = (message, review, error) => logger.error(message, {
|
|
183
|
+
escalationReviewId: String(review._id), error: redactDirectIdentifiers(String(error?.message || error)),
|
|
184
|
+
});
|
|
182
185
|
for (const review of reviews) {
|
|
186
|
+
let clock;
|
|
187
|
+
try {
|
|
188
|
+
clock = untakenClockOf(review, policy);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
failed('[UntakenAlert] Could not check a review for an untaken alert', review, error);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
// A failed team alert must not keep the case from the doctor, so each step fails on its own.
|
|
183
194
|
try {
|
|
184
|
-
const clock = untakenClockOf(review, policy);
|
|
185
195
|
const stage = alerts && clock && dueStageOf(review, clock, now);
|
|
186
196
|
if (stage && await alertIfUntaken(review, clock, stage, now)) sent += 1;
|
|
187
|
-
if (autoHandoff) await settleCharacterization(review, clock, now);
|
|
188
197
|
} catch (error) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
failed('[UntakenAlert] Could not check a review for an untaken alert', review, error);
|
|
199
|
+
}
|
|
200
|
+
if (!autoHandoff) continue;
|
|
201
|
+
try {
|
|
202
|
+
await settleCharacterization(review, clock, now);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
failed('[UntakenAlert] Could not settle the characterization of a review', review, error);
|
|
192
205
|
}
|
|
193
206
|
}
|
|
194
207
|
return sent;
|