@peopl-health/nexus 5.76.0-dev.15838 → 5.76.0-dev.15841
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,11 +1,15 @@
|
|
|
1
1
|
const { Symptoms_ID } = require('../config/airtableConfig');
|
|
2
2
|
|
|
3
3
|
const { MapCache } = require('../utils/MapCache');
|
|
4
|
+
const { logger } = require('../utils/logger');
|
|
4
5
|
const { paginate } = require('../utils/paginationUtils');
|
|
6
|
+
const { firstOf } = require('../utils/coercionUtils');
|
|
5
7
|
const { fieldEquals, recordIdIn } = require('../helpers/airtableFormulaHelper');
|
|
8
|
+
const { mergeArchivedRows } = require('../helpers/airtableArchiveHelper');
|
|
6
9
|
const { TRIAGE_FIELDS, SYMPTOM_FIELDS, buildTriageRecord } = require('../helpers/triageRecordHelper');
|
|
7
10
|
|
|
8
11
|
const { getRecordByFilter } = require('./airtableService');
|
|
12
|
+
const { findArchivedByPatient, findArchivedByRecordIds } = require('./airtableArchiveReadService');
|
|
9
13
|
|
|
10
14
|
const DEFAULT_LIMIT = 50;
|
|
11
15
|
const HISTORY_TTL_MS = 60 * 1000;
|
|
@@ -24,11 +28,23 @@ const withinRange = (row, fromDate, toDate) => {
|
|
|
24
28
|
|
|
25
29
|
const linkedIdsOf = (value) => (Array.isArray(value) ? value.filter(Boolean) : []);
|
|
26
30
|
|
|
31
|
+
// Rows deleted from Airtable exist only in the archive; if it cannot be read, the page shows live rows only.
|
|
32
|
+
const readArchived = async (read, params) => {
|
|
33
|
+
try {
|
|
34
|
+
return await read({ baseId: Symptoms_ID, ...params });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.error('[triageHistoryService] Archive read failed, serving live rows only', { table: params.tableName, error: error.message });
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
27
41
|
const readPatientHistory = async (code) => {
|
|
28
|
-
const
|
|
29
|
-
Symptoms_ID, 'triaje_symptoms', fieldEquals('whatsapp_id', code), 'Grid view', TRIAGE_FIELDS,
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
const [live, archived] = await Promise.all([
|
|
43
|
+
getRecordByFilter(Symptoms_ID, 'triaje_symptoms', fieldEquals('whatsapp_id', code), 'Grid view', TRIAGE_FIELDS, true),
|
|
44
|
+
readArchived(findArchivedByPatient, { tableName: 'triaje_symptoms', whatsappId: code, fields: TRIAGE_FIELDS }),
|
|
45
|
+
]);
|
|
46
|
+
const ownRows = archived.filter((row) => firstOf(row.whatsapp_id) === code);
|
|
47
|
+
return { rows: mergeArchivedRows(live || [], ownRows), symptomsById: new Map() };
|
|
32
48
|
};
|
|
33
49
|
|
|
34
50
|
const getPatientHistory = (code) => {
|
|
@@ -67,6 +83,11 @@ const getTriageHistory = async ({ code, startDate, endDate, limit, page } = {})
|
|
|
67
83
|
Symptoms_ID, 'symptoms', recordIdIn(missingIds), null, SYMPTOM_FIELDS, true,
|
|
68
84
|
) || [];
|
|
69
85
|
for (const symptomRow of symptomRows) symptomsById.set(symptomRow._recordId, symptomRow);
|
|
86
|
+
const archivedIds = missingIds.filter((id) => !symptomsById.has(id));
|
|
87
|
+
if (archivedIds.length) {
|
|
88
|
+
const archivedRows = await readArchived(findArchivedByRecordIds, { tableName: 'symptoms', recordIds: archivedIds, fields: SYMPTOM_FIELDS });
|
|
89
|
+
for (const symptomRow of archivedRows) symptomsById.set(symptomRow._recordId, symptomRow);
|
|
90
|
+
}
|
|
70
91
|
}
|
|
71
92
|
|
|
72
93
|
const records = pageRows.map((row) => buildTriageRecord(
|