@peopl-health/nexus 5.73.0-dev.15250 → 5.73.0-dev.15251
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.
|
@@ -24,7 +24,18 @@ const hashFields = (fields, skip = new Set()) => crypto.createHash('sha256')
|
|
|
24
24
|
.update(stableStringify(Object.fromEntries(Object.entries(fields).filter(([name]) => !skip.has(name)))))
|
|
25
25
|
.digest('hex');
|
|
26
26
|
|
|
27
|
+
// Same shape as airtableService.getRecordByFilter(..., withRecordId = true), flagged as archived.
|
|
28
|
+
const toAirtableRow = (doc) => ({ ...doc.fields, _recordId: doc.recordId, _createdTime: new Date(doc.createdTime).toISOString(), _archived: true });
|
|
29
|
+
|
|
30
|
+
// Union by record id, live row winning; archived rows are appended, so callers sort after merging.
|
|
31
|
+
function mergeArchivedRows(liveRows = [], archivedRows = []) {
|
|
32
|
+
const liveIds = new Set(liveRows.map((row) => row._recordId));
|
|
33
|
+
return [...liveRows, ...archivedRows.filter((row) => !liveIds.has(row._recordId))];
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
module.exports = {
|
|
28
37
|
normalizeFields,
|
|
29
38
|
hashFields,
|
|
39
|
+
toAirtableRow,
|
|
40
|
+
mergeArchivedRows,
|
|
30
41
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { getAirtableArchiveRecord, archiveRecordId } = require('../models/airtableArchiveModel');
|
|
2
|
+
const { toAirtableRow } = require('../helpers/airtableArchiveHelper');
|
|
3
|
+
|
|
4
|
+
const READ_PROJECTION = { recordId: 1, createdTime: 1, fields: 1 };
|
|
5
|
+
|
|
6
|
+
async function findArchivedByPatient({ baseId, tableName, whatsappId, patientRecordId, since }) {
|
|
7
|
+
if (!whatsappId && !patientRecordId) return [];
|
|
8
|
+
const query = { baseId, tableName };
|
|
9
|
+
if (patientRecordId) query['patient.recordId'] = patientRecordId;
|
|
10
|
+
else query['patient.whatsappId'] = whatsappId;
|
|
11
|
+
if (since) query.createdTime = { $gte: since };
|
|
12
|
+
const docs = await getAirtableArchiveRecord().find(query, READ_PROJECTION).sort({ createdTime: -1 }).lean();
|
|
13
|
+
return docs.map(toAirtableRow);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function findArchivedByRecordIds({ baseId, tableName, recordIds }) {
|
|
17
|
+
if (!recordIds?.length) return [];
|
|
18
|
+
const docs = await getAirtableArchiveRecord().find({ _id: { $in: recordIds.map((id) => archiveRecordId(baseId, id)) }, tableName }, READ_PROJECTION).lean();
|
|
19
|
+
return docs.map(toAirtableRow);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
findArchivedByPatient,
|
|
24
|
+
findArchivedByRecordIds,
|
|
25
|
+
};
|