@peopl-health/nexus 5.73.0-dev.15252 → 5.73.0
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.
|
@@ -91,8 +91,8 @@ const WHATSAPP_FIELDS = Object.freeze({
|
|
|
91
91
|
[TABLE.SYMPTOMS]: FIELD.SYMPTOM.WHATSAPP,
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
const
|
|
95
|
-
const
|
|
94
|
+
const LINK_FIELD_TYPES = Object.freeze(['multipleRecordLinks']);
|
|
95
|
+
const CHECKBOX_FIELD_TYPES = Object.freeze(['checkbox']);
|
|
96
96
|
const DATE_FIELD_TYPES = Object.freeze(['dateTime', 'date']);
|
|
97
97
|
const FIRST_MONTH_DAYS = 30;
|
|
98
98
|
|
|
@@ -134,8 +134,8 @@ module.exports = {
|
|
|
134
134
|
EXTERNAL_LINKS,
|
|
135
135
|
PATIENT_FIELDS,
|
|
136
136
|
WHATSAPP_FIELDS,
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
LINK_FIELD_TYPES,
|
|
138
|
+
CHECKBOX_FIELD_TYPES,
|
|
139
139
|
DATE_FIELD_TYPES,
|
|
140
140
|
FIRST_MONTH_DAYS,
|
|
141
141
|
KEEP_REASONS,
|
|
@@ -2,7 +2,7 @@ const crypto = require('crypto');
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
ARCHIVE_TABLES, ARCHIVE_FIELDS, GROUP_LINKS, CARRY_OVER_LINKS, BACKWARD_LINKS, EXTERNAL_LINKS, PATIENT_FIELDS, WHATSAPP_FIELDS,
|
|
5
|
-
COMPUTED_FIELD_TYPES,
|
|
5
|
+
COMPUTED_FIELD_TYPES, LINK_FIELD_TYPES, CHECKBOX_FIELD_TYPES, DATE_FIELD_TYPES, FIRST_MONTH_DAYS, KEEP_REASONS,
|
|
6
6
|
} = require('../config/airtableArchiveConfig');
|
|
7
7
|
|
|
8
8
|
const linkedIds = (record, fieldNames = []) => fieldNames.flatMap((name) => {
|
|
@@ -61,13 +61,13 @@ function resolveArchiveSchema(baseTables = []) {
|
|
|
61
61
|
if (!tablesById.has(tableId)) missing.push(tableId);
|
|
62
62
|
return tablesById.get(tableId)?.name;
|
|
63
63
|
};
|
|
64
|
-
const fieldName = (tableId, fieldId,
|
|
64
|
+
const fieldName = (tableId, fieldId, types) => {
|
|
65
65
|
const field = tablesById.get(tableId)?.fields.find((f) => f.id === fieldId);
|
|
66
|
-
if (!field || (
|
|
66
|
+
if (!field || (types && !types.includes(field.type))) missing.push(fieldId);
|
|
67
67
|
return field?.name;
|
|
68
68
|
};
|
|
69
|
-
const byTableName = (map,
|
|
70
|
-
tableName(tableId), Array.isArray(value) ? value.map((fieldId) => fieldName(tableId, fieldId,
|
|
69
|
+
const byTableName = (map, types) => Object.fromEntries(Object.entries(map).map(([tableId, value]) => [
|
|
70
|
+
tableName(tableId), Array.isArray(value) ? value.map((fieldId) => fieldName(tableId, fieldId, types)) : fieldName(tableId, value, types),
|
|
71
71
|
]));
|
|
72
72
|
|
|
73
73
|
const tables = Object.fromEntries(Object.entries(ARCHIVE_TABLES).map(([key, tableId]) => [key, tableName(tableId)]));
|
|
@@ -75,17 +75,17 @@ function resolveArchiveSchema(baseTables = []) {
|
|
|
75
75
|
const schema = {
|
|
76
76
|
tables,
|
|
77
77
|
tableIds: Object.fromEntries(archived.map((table) => [table.name, table.id])),
|
|
78
|
-
groupLinks: byTableName(GROUP_LINKS,
|
|
79
|
-
carryOverLinks: byTableName(CARRY_OVER_LINKS,
|
|
80
|
-
backwardLinks: byTableName(BACKWARD_LINKS,
|
|
81
|
-
externalLinks: byTableName(EXTERNAL_LINKS,
|
|
82
|
-
patientFields: byTableName(PATIENT_FIELDS,
|
|
78
|
+
groupLinks: byTableName(GROUP_LINKS, LINK_FIELD_TYPES),
|
|
79
|
+
carryOverLinks: byTableName(CARRY_OVER_LINKS, LINK_FIELD_TYPES),
|
|
80
|
+
backwardLinks: byTableName(BACKWARD_LINKS, LINK_FIELD_TYPES),
|
|
81
|
+
externalLinks: byTableName(EXTERNAL_LINKS, LINK_FIELD_TYPES),
|
|
82
|
+
patientFields: byTableName(PATIENT_FIELDS, LINK_FIELD_TYPES),
|
|
83
83
|
whatsappFields: byTableName(WHATSAPP_FIELDS),
|
|
84
|
-
questionnaireTriage: fieldName(ARCHIVE_TABLES.QUESTIONNAIRES, ARCHIVE_FIELDS.QUESTIONNAIRE.TRIAGE,
|
|
85
|
-
questionnaireApproved: fieldName(ARCHIVE_TABLES.QUESTIONNAIRES, ARCHIVE_FIELDS.QUESTIONNAIRE.APPROVED,
|
|
84
|
+
questionnaireTriage: fieldName(ARCHIVE_TABLES.QUESTIONNAIRES, ARCHIVE_FIELDS.QUESTIONNAIRE.TRIAGE, LINK_FIELD_TYPES),
|
|
85
|
+
questionnaireApproved: fieldName(ARCHIVE_TABLES.QUESTIONNAIRES, ARCHIVE_FIELDS.QUESTIONNAIRE.APPROVED, CHECKBOX_FIELD_TYPES),
|
|
86
86
|
questionnaireCreated: fieldName(ARCHIVE_TABLES.QUESTIONNAIRES, ARCHIVE_FIELDS.QUESTIONNAIRE.CREATED, DATE_FIELD_TYPES),
|
|
87
87
|
computed: new Map(archived.map((table) => [table.name, new Set(table.fields.filter((f) => COMPUTED_FIELD_TYPES.includes(f.type)).map((f) => f.name))])),
|
|
88
|
-
snapshot: archived.map(({ id, name, fields }) => ({ id, name, fields: fields.map((f) => ({ id: f.id, name: f.name, type: f.type })) })),
|
|
88
|
+
snapshot: archived.map(({ id, name, fields }) => ({ id, name, fields: fields.map((f) => ({ id: f.id, name: f.name, type: f.type })).sort((a, b) => a.id.localeCompare(b.id)) })),
|
|
89
89
|
};
|
|
90
90
|
return { schema, missing: [...new Set(missing)] };
|
|
91
91
|
}
|
|
@@ -41,8 +41,9 @@ async function readArchiveSchema(baseId) {
|
|
|
41
41
|
// Records come back keyed by name, so a rename during the scans would hide links from the planner.
|
|
42
42
|
async function assertSchemaUnchanged(baseId, schema) {
|
|
43
43
|
const current = await readArchiveSchema(baseId);
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const changed = schema.snapshot.filter((table, i) => stableStringify(table) !== stableStringify(current.snapshot[i])).map((table) => table.id);
|
|
45
|
+
if (changed.length) {
|
|
46
|
+
logger.error('[airtableArchive] Base schema changed during the scan', { baseId, tables: changed });
|
|
46
47
|
throw archiveError('archive_schema_mismatch');
|
|
47
48
|
}
|
|
48
49
|
}
|