@peopl-health/nexus 5.46.0-dev.7268 → 5.46.0-dev.7269

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.
@@ -20,10 +20,11 @@ const URGENT_CASE_TYPES = ['Urgencia', 'Emergencia'];
20
20
  const REQUEST_FIELDS = ['whatsapp_id', 'status', 'urgency', 'created_time'];
21
21
  const CASE_FIELDS = ['whatsapp_id', 'status', 'status_operaciones', 'type', 'created'];
22
22
  const REQUEST_FILTER = `AND(${fieldEquals('message_tag', 'request')}, ${fieldEquals('status', ATTENTION_REQUEST_STATUS)})`;
23
- const CASE_FILTER = `AND(${fieldEquals('status_operaciones', ATTENTION_OPERATIONS_STATUS)}, IS_AFTER({created}, DATEADD(NOW(), -${ATTENTION_CASE_WINDOW_DAYS}, 'days')))`;
23
+ const CASE_FILTER = `AND(${fieldEquals('status_operaciones', ATTENTION_OPERATIONS_STATUS)}, OR(IS_AFTER({created}, DATEADD(NOW(), -${ATTENTION_CASE_WINDOW_DAYS}, 'days')), {created} = BLANK()))`;
24
24
 
25
25
  const cache = new MapCache({ maxSize: 1, ttl: CACHE_TTL_MS });
26
26
  let inFlight = null;
27
+ let generation = 0;
27
28
 
28
29
  const codesOf = (row) => (Array.isArray(row.whatsapp_id) ? row.whatsapp_id : [row.whatsapp_id])
29
30
  .map((value) => String(value || '').trim())
@@ -40,21 +41,22 @@ const addTask = (summary, code, kind, isUrgent, createdAt) => {
40
41
 
41
42
  async function loadSummary() {
42
43
  const [requestRows, caseRows] = await Promise.all([
43
- getRecordByFilter(Monitoreo_ID, 'unresolved_questions', REQUEST_FILTER, null, REQUEST_FIELDS),
44
- getRecordByFilter(Monitoreo_ID, 'patient_cases', CASE_FILTER, null, CASE_FIELDS),
44
+ getRecordByFilter(Monitoreo_ID, 'unresolved_questions', REQUEST_FILTER, null, REQUEST_FIELDS, true),
45
+ getRecordByFilter(Monitoreo_ID, 'patient_cases', CASE_FILTER, null, CASE_FIELDS, true),
45
46
  ]);
46
47
  const summary = new Map();
47
48
 
48
49
  for (const row of requestRows || []) {
49
50
  if (!needsRequestAttention(row.status)) continue;
50
51
  const isUrgent = row.urgency === URGENT_REQUEST_URGENCY;
51
- for (const code of codesOf(row)) addTask(summary, code, 'requests', isUrgent, row.created_time || null);
52
+ for (const code of codesOf(row)) addTask(summary, code, 'requests', isUrgent, row.created_time || row._createdTime || null);
52
53
  }
53
54
 
54
55
  for (const row of caseRows || []) {
55
- if (!needsCaseAttention(row.status, row.status_operaciones, row.created)) continue;
56
+ const createdAt = row.created || row._createdTime || null;
57
+ if (!needsCaseAttention(row.status, row.status_operaciones, createdAt)) continue;
56
58
  const isUrgent = URGENT_CASE_TYPES.includes(row.type);
57
- for (const code of codesOf(row)) addTask(summary, code, 'cases', isUrgent, row.created || null);
59
+ for (const code of codesOf(row)) addTask(summary, code, 'cases', isUrgent, createdAt);
58
60
  }
59
61
 
60
62
  return summary;
@@ -64,9 +66,10 @@ async function getOpenTaskSummary() {
64
66
  const cached = cache.get(CACHE_KEY);
65
67
  if (cached) return cached;
66
68
  if (!inFlight) {
69
+ const loadGeneration = generation;
67
70
  inFlight = loadSummary()
68
71
  .then((summary) => {
69
- cache.set(CACHE_KEY, summary);
72
+ if (loadGeneration === generation) cache.set(CACHE_KEY, summary);
70
73
  return summary;
71
74
  })
72
75
  .finally(() => {
@@ -77,6 +80,7 @@ async function getOpenTaskSummary() {
77
80
  }
78
81
 
79
82
  function clearOpenTaskSummary() {
83
+ generation += 1;
80
84
  cache.clear();
81
85
  inFlight = null;
82
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.46.0-dev.7268",
3
+ "version": "5.46.0-dev.7269",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",