@peopl-health/nexus 6.0.0 → 6.0.1

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.
@@ -116,9 +116,27 @@ const buildTriageRecord = (row, symptomRows = []) => ({
116
116
  code: row?.whatsapp_id || null,
117
117
  });
118
118
 
119
+ // Airtable's rollups miss the symptoms it unlinked: grades come from the symptoms shown, and the filtered counts cannot be rebuilt.
120
+ const regradeFromShownSymptoms = (record, { stillLinks = false } = {}) => {
121
+ const grades = record.symptoms.map((symptom) => symptom.gradeNum).filter((grade) => grade !== null);
122
+ // A linked symptom that could not be read still counts through Airtable's own rollup.
123
+ const maxGrades = stillLinks && record.maxGrade !== null ? [...grades, record.maxGrade] : grades;
124
+ const minGrades = stillLinks && record.minGrade !== null ? [...grades, record.minGrade] : grades;
125
+ return {
126
+ ...record,
127
+ maxGrade: maxGrades.length ? Math.max(...maxGrades) : null,
128
+ minGrade: minGrades.length ? Math.min(...minGrades) : null,
129
+ positiveCount: null,
130
+ gradeTwoCount: null,
131
+ gradeThreeCount: null,
132
+ totalSymptoms: null,
133
+ };
134
+ };
135
+
119
136
  module.exports = {
120
137
  TRIAGE_FIELDS,
121
138
  SYMPTOM_FIELDS,
122
139
  buildSymptom,
123
140
  buildTriageRecord,
141
+ regradeFromShownSymptoms,
124
142
  };
@@ -6,7 +6,7 @@ const { paginate } = require('../utils/paginationUtils');
6
6
  const { firstOf } = require('../utils/coercionUtils');
7
7
  const { fieldEquals, recordIdIn } = require('../helpers/airtableFormulaHelper');
8
8
  const { mergeArchivedRows } = require('../helpers/airtableArchiveHelper');
9
- const { TRIAGE_FIELDS, SYMPTOM_FIELDS, buildTriageRecord } = require('../helpers/triageRecordHelper');
9
+ const { TRIAGE_FIELDS, SYMPTOM_FIELDS, buildTriageRecord, regradeFromShownSymptoms } = require('../helpers/triageRecordHelper');
10
10
 
11
11
  const { getRecordByFilter } = require('./airtableService');
12
12
  const { findArchivedByPatient, findArchivedByRecordIds } = require('./airtableArchiveReadService');
@@ -108,10 +108,13 @@ const getTriageHistory = async ({ code, startDate, endDate, limit, page } = {})
108
108
  for (const symptomRow of archivedRows) symptomsById.set(symptomRow._recordId, symptomRow);
109
109
  }
110
110
 
111
- const records = pageRows.map((row) => buildTriageRecord(
112
- row,
113
- symptomIdsOf(row).map((id) => symptomsById.get(id)).filter(Boolean),
114
- ));
111
+ const records = pageRows.map((row) => {
112
+ const linked = new Set(linkedIdsOf(row.symptoms));
113
+ const shown = symptomIdsOf(row).map((id) => symptomsById.get(id)).filter(Boolean);
114
+ const record = buildTriageRecord(row, shown);
115
+ const unlinkedShown = shown.some((symptomRow) => !linked.has(symptomRow._recordId));
116
+ return unlinkedShown ? regradeFromShownSymptoms(record, { stillLinks: linked.size > 0 }) : record;
117
+ });
115
118
 
116
119
  return { records, pagination };
117
120
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",