@peopl-health/nexus 5.47.1 → 5.48.0-dev.7343

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.
@@ -68,6 +68,11 @@ function validateGateInheritance(elements, gate) {
68
68
  path: 'elements[].escalation.routes',
69
69
  problem: 'gate equipo_tratante_hoy ⇒ un elemento heredado debe incluir equipo_medico_tratante',
70
70
  });
71
+ } else if (!sameDayTeamElements.some((element) => /\bhoy\b/i.test(element.recommendation.patient.mainRecommendation))) {
72
+ issues.push({
73
+ path: 'elements[].recommendation.patient.main_recommendation',
74
+ problem: 'gate equipo_tratante_hoy ⇒ la recomendación heredada debe indicar explícitamente contactar al equipo hoy',
75
+ });
71
76
  }
72
77
  }
73
78
  return issues;
@@ -92,13 +97,17 @@ function validate(elements, options = {}) {
92
97
  }
93
98
  }
94
99
  const count = patient.mainRecommendation ? sentenceCount(patient.mainRecommendation) : 0;
95
- const minSentences = isTriagePlan ? 3 : 2;
100
+ const inheritsSameDayTeamGate = inheritsUrgentGate(element, options.gate)
101
+ && options.gate.escalationRoute === 'equipo_tratante_hoy'
102
+ && element.escalation.routes.includes('equipo_medico_tratante');
103
+ const minSentences = isTriagePlan ? (inheritsSameDayTeamGate ? 4 : 3) : 2;
96
104
  if (patient.mainRecommendation && !(count >= minSentences && count <= 4)) {
105
+ const expected = minSentences === 4 ? 'exactamente 4 oraciones' : `${minSentences}-4 oraciones`;
97
106
  issues.push({
98
107
  path: `${path}.recommendation.patient.main_recommendation`,
99
108
  code: SENTENCE_COUNT_CODE,
100
109
  warning: true,
101
- problem: `${minSentences}-4 oraciones; detectadas: ${count}`,
110
+ problem: `${expected}; detectadas: ${count}`,
102
111
  });
103
112
  }
104
113
  if (element.escalation.urgentUnder24h && !patient.whenToEscalate) {
@@ -15,7 +15,9 @@ const toMap = (arr, keyFn, valFn) => arr.reduce((m, item) => {
15
15
  return key ? { ...m, [key]: valFn(item) } : m;
16
16
  }, {});
17
17
 
18
- const buildThreadFilter = (filter, { triageIds, pendingTaskCodes }) => {
18
+ const PENDING_TASK_FILTERS = ['pending-tasks', 'pending-cases', 'pending-requests'];
19
+
20
+ const buildThreadFilter = (filter, { triageIds, taskCodes }) => {
19
21
  const base = { lastMessageAt: { $ne: null } };
20
22
  switch (filter) {
21
23
  case 'unread':
@@ -29,7 +31,11 @@ const buildThreadFilter = (filter, { triageIds, pendingTaskCodes }) => {
29
31
  case 'triage-last-month':
30
32
  return { ...base, code: { $in: triageIds } };
31
33
  case 'pending-tasks':
32
- return { ...base, code: { $in: pendingTaskCodes } };
34
+ return { ...base, code: { $in: taskCodes.all } };
35
+ case 'pending-cases':
36
+ return { ...base, code: { $in: taskCodes.cases } };
37
+ case 'pending-requests':
38
+ return { ...base, code: { $in: taskCodes.requests } };
33
39
  case 'all':
34
40
  default:
35
41
  return base;
@@ -43,15 +49,20 @@ const fetchConversationData = async (filter, skip, limit) => {
43
49
  triageIds = (triageRecords || []).map(r => r.whatsapp_id).filter(Boolean);
44
50
  }
45
51
 
46
- const openTaskMap = filter === 'pending-tasks'
52
+ const openTaskMap = PENDING_TASK_FILTERS.includes(filter)
47
53
  ? await getOpenTaskSummary()
48
54
  : await getOpenTaskSummary().catch((error) => {
49
55
  logger.warn('[fetchConversationData] Open task summary unavailable', { error: error.message });
50
56
  return null;
51
57
  });
52
- const pendingTaskCodes = [...(openTaskMap?.keys() || [])];
58
+ const taskEntries = [...(openTaskMap?.entries() || [])];
59
+ const taskCodes = {
60
+ all: taskEntries.map(([code]) => code),
61
+ cases: taskEntries.filter(([, entry]) => entry.cases > 0).map(([code]) => code),
62
+ requests: taskEntries.filter(([, entry]) => entry.requests > 0).map(([code]) => code),
63
+ };
53
64
 
54
- const threadFilter = buildThreadFilter(filter, { triageIds, pendingTaskCodes });
65
+ const threadFilter = buildThreadFilter(filter, { triageIds, taskCodes });
55
66
 
56
67
  logger.info('[fetchConversationData] Applying filter', { filter });
57
68
  const startTime = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.47.1",
3
+ "version": "5.48.0-dev.7343",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",