@peopl-health/nexus 5.46.0-dev.7270 → 5.46.0-dev.7272

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.
@@ -13,6 +13,8 @@ const ATTENTION_REQUEST_STATUS = 'sin atender';
13
13
  const ATTENTION_OPERATIONS_STATUS = 'pendiente';
14
14
  const ATTENTION_CASE_WINDOW_DAYS = 14;
15
15
  const ATTENTION_CASE_WINDOW_MS = ATTENTION_CASE_WINDOW_DAYS * 24 * 60 * 60 * 1000;
16
+ const URGENT_REQUEST_URGENCY = 'urgent';
17
+ const URGENT_CASE_TYPES = ['Urgencia', 'Emergencia'];
16
18
 
17
19
  const isRequestOpen = (status) => !CLOSED_REQUEST_STATUSES.includes(status);
18
20
 
@@ -30,12 +32,18 @@ const needsCaseAttention = (status, operationsStatus, createdAt) => operationsSt
30
32
  && !CLOSED_CASE_STATUSES.includes(status)
31
33
  && isWithinAttentionWindow(createdAt);
32
34
 
35
+ const isRequestUrgent = (urgency) => urgency === URGENT_REQUEST_URGENCY;
36
+
37
+ const isCaseUrgent = (type) => URGENT_CASE_TYPES.includes(type);
38
+
33
39
  module.exports = {
34
40
  ATTENTION_CASE_WINDOW_DAYS,
35
41
  ATTENTION_OPERATIONS_STATUS,
36
42
  ATTENTION_REQUEST_STATUS,
37
43
  isCaseOpen,
44
+ isCaseUrgent,
38
45
  isRequestOpen,
46
+ isRequestUrgent,
39
47
  needsCaseAttention,
40
48
  needsRequestAttention,
41
49
  };
@@ -1,7 +1,14 @@
1
1
  const { Monitoreo_ID } = require('../config/airtableConfig');
2
2
 
3
3
  const { escapeFormulaValue, fieldEquals, recordIdIn } = require('../helpers/airtableFormulaHelper');
4
- const { isCaseOpen, isRequestOpen, needsCaseAttention, needsRequestAttention } = require('../helpers/patientTaskRulesHelper');
4
+ const {
5
+ isCaseOpen,
6
+ isCaseUrgent,
7
+ isRequestOpen,
8
+ isRequestUrgent,
9
+ needsCaseAttention,
10
+ needsRequestAttention,
11
+ } = require('../helpers/patientTaskRulesHelper');
5
12
 
6
13
  const { getRecordByFilter, updateRecordByFilter } = require('../services/airtableService');
7
14
  const { logPatientChange } = require('../services/patientService');
@@ -74,6 +81,7 @@ const toRequest = (row) => ({
74
81
  isForDoctorOffice: row.doctor_office === true,
75
82
  isOpen: isRequestOpen(row.status),
76
83
  needsAttention: needsRequestAttention(row.status),
84
+ isUrgent: isRequestUrgent(row.urgency),
77
85
  });
78
86
 
79
87
  const toCase = (row) => ({
@@ -90,6 +98,7 @@ const toCase = (row) => ({
90
98
  recommendation: row.recomendation_final ?? null,
91
99
  isOpen: isCaseOpen(row.status, row.status_operaciones),
92
100
  needsAttention: needsCaseAttention(row.status, row.status_operaciones, row.created || row._createdTime),
101
+ isUrgent: isCaseUrgent(row.type),
93
102
  });
94
103
 
95
104
  const TASK_KINDS = {
@@ -7,6 +7,8 @@ const {
7
7
  ATTENTION_CASE_WINDOW_DAYS,
8
8
  ATTENTION_OPERATIONS_STATUS,
9
9
  ATTENTION_REQUEST_STATUS,
10
+ isCaseUrgent,
11
+ isRequestUrgent,
10
12
  needsCaseAttention,
11
13
  needsRequestAttention,
12
14
  } = require('../helpers/patientTaskRulesHelper');
@@ -15,9 +17,7 @@ const { getRecordByFilter } = require('../services/airtableService');
15
17
 
16
18
  const CACHE_KEY = 'open-tasks';
17
19
  const CACHE_TTL_MS = 60000;
18
- const URGENT_REQUEST_URGENCY = 'urgent';
19
- const URGENT_CASE_TYPES = ['Urgencia', 'Emergencia'];
20
- const REQUEST_FIELDS = ['whatsapp_id', 'status', 'urgency', 'created_time'];
20
+ const REQUEST_FIELDS = ['whatsapp_id', 'status', 'urgency'];
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
23
  const CASE_FILTER = `AND(${fieldEquals('status_operaciones', ATTENTION_OPERATIONS_STATUS)}, OR(IS_AFTER({created}, DATEADD(NOW(), -${ATTENTION_CASE_WINDOW_DAYS}, 'days')), {created} = BLANK()))`;
@@ -30,11 +30,10 @@ const codesOf = (row) => (Array.isArray(row.whatsapp_id) ? row.whatsapp_id : [ro
30
30
  .map((value) => String(value || '').trim())
31
31
  .filter(Boolean);
32
32
 
33
- const addTask = (summary, code, kind, isUrgent, createdAt) => {
34
- const entry = summary.get(code) || { requests: 0, cases: 0, isUrgent: false, oldestAt: null };
33
+ const addTask = (summary, code, kind, isUrgent) => {
34
+ const entry = summary.get(code) || { requests: 0, cases: 0, isUrgent: false };
35
35
  entry[kind] += 1;
36
36
  entry.isUrgent = entry.isUrgent || isUrgent;
37
- if (createdAt && (!entry.oldestAt || createdAt < entry.oldestAt)) entry.oldestAt = createdAt;
38
37
  summary.set(code, entry);
39
38
  };
40
39
 
@@ -47,15 +46,13 @@ async function loadSummary() {
47
46
 
48
47
  for (const row of requestRows || []) {
49
48
  if (!needsRequestAttention(row.status)) continue;
50
- const isUrgent = row.urgency === URGENT_REQUEST_URGENCY;
51
- for (const code of codesOf(row)) addTask(summary, code, 'requests', isUrgent, row.created_time || row._createdTime || null);
49
+ for (const code of codesOf(row)) addTask(summary, code, 'requests', isRequestUrgent(row.urgency));
52
50
  }
53
51
 
54
52
  for (const row of caseRows || []) {
55
53
  const createdAt = row.created || row._createdTime || null;
56
54
  if (!needsCaseAttention(row.status, row.status_operaciones, createdAt)) continue;
57
- const isUrgent = URGENT_CASE_TYPES.includes(row.type);
58
- for (const code of codesOf(row)) addTask(summary, code, 'cases', isUrgent, createdAt);
55
+ for (const code of codesOf(row)) addTask(summary, code, 'cases', isCaseUrgent(row.type));
59
56
  }
60
57
 
61
58
  return summary;
@@ -75,6 +72,7 @@ async function getOpenTaskSummary() {
75
72
  },
76
73
  (error) => {
77
74
  if (inFlight === load) inFlight = null;
75
+ if (loadGeneration !== generation) return getOpenTaskSummary();
78
76
  throw error;
79
77
  }
80
78
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.46.0-dev.7270",
3
+ "version": "5.46.0-dev.7272",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",