@peopl-health/nexus 6.1.0-dev.18191 → 6.1.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.
@@ -1,4 +1,4 @@
1
- const FORMULARY_VERSION = '2026-09-28';
1
+ const FORMULARY_VERSION = '2026-10-29';
2
2
 
3
3
  const MEDICAL_REVIEW = 'valoración médica';
4
4
 
@@ -224,6 +224,17 @@ const TREATMENT_FORMULARY = deepFreeze([
224
224
  { drug: 'Hidrocortisona tópica', brand: 'LOCOID', strength: null, position: '1L', tableLabel: '1L en dermatitis/rash inflamatorio leve', class: 'corticoide_topico' },
225
225
  ],
226
226
  },
227
+ {
228
+ key: 'molestia_ocular_egfr',
229
+ label: 'Molestias en los ojos con panitumumab o cetuximab',
230
+ drugs: [
231
+ {
232
+ drug: 'Dexametasona/neomicina', strength: null, position: '1L', tableLabel: '1L gotas oftálmicas, solo con panitumumab o cetuximab', class: 'corticoide_antibiotico_oftalmico',
233
+ onlyWhen: ['panitumumab', 'cetuximab'],
234
+ instructions: '2 gotas oftálmicas cada 12 horas por 3 días; además, valoración por oftalmología',
235
+ },
236
+ ],
237
+ },
227
238
  {
228
239
  key: 'sindrome_mano_pie',
229
240
  label: 'Xerosis / síndrome mano-pie',
@@ -425,6 +425,17 @@ async function recordReminder({ code, trace, actionType, reminderId, reminderDat
425
425
  });
426
426
  }
427
427
 
428
+ async function isReminderPending({ code, reminderId }) {
429
+ const rows = await airtableService.getRecordByFilter(
430
+ Monitoreo_ID,
431
+ 'reminder',
432
+ `AND(${fieldEquals('whatsapp_id', code)}, ${fieldEquals('schedule_id', reminderId)}, ${PENDING_ROW_FILTER})`,
433
+ null,
434
+ ['schedule_id'],
435
+ );
436
+ return rows.length > 0;
437
+ }
438
+
428
439
  async function hasPendingContingencyRow({ planId }) {
429
440
  const rows = await airtableService.getRecordByFilter(
430
441
  Monitoreo_ID,
@@ -759,6 +770,7 @@ module.exports = {
759
770
  recordClinicalIntake,
760
771
  recordReminder,
761
772
  hasPendingContingencyRow,
773
+ isReminderPending,
762
774
  hasPendingReminderForPatient,
763
775
  readPendingFollowUpsForPatient,
764
776
  readPendingReminderForPatient,
@@ -2,7 +2,7 @@ const moment = require('moment-timezone');
2
2
 
3
3
  const { isShadowRun } = require('../helpers/shadowHelper');
4
4
  const { dispatchReminder } = require('../services/reminderDispatchService');
5
- const { recordReminder, readPendingFollowUpsForPatient, cancelFollowUp, cancelPendingFollowUps } = require('../services/clinicalAirtableService');
5
+ const { recordReminder, readPendingFollowUpsForPatient, cancelFollowUp, cancelPendingFollowUps, isReminderPending } = require('../services/clinicalAirtableService');
6
6
  const { isWithinTriageProtectionWindow } = require('../services/outreachSweepService');
7
7
  const { UTILITY_BASES, sanitizeVariable } = require('../services/outreachCarrierService');
8
8
  const { logger } = require('../../utils/logger');
@@ -149,6 +149,9 @@ async function handler(args = {}, context = {}) {
149
149
  return JSON.stringify({ success: false, error: 'checkins_paused — the patient asked for fewer messages; do not schedule a seguimiento before the pause ends.', data: { paused_until: moment(pausedUntil).tz(timeZone).format('YYYY-MM-DDTHH:mm') } });
150
150
  }
151
151
  }
152
+ if (actionType === 'update' && targetId && runtime.patientCode && !await isReminderPending({ code: runtime.patientCode, reminderId: targetId })) {
153
+ return JSON.stringify({ success: false, error: 'reminder_not_active — that reminder already went out or was stood down, so it cannot be updated. If a check is still needed, create a new one.', data: { reminder_id: targetId } });
154
+ }
152
155
  if (isRoutineOutreach && actionType === 'create' && runtime.patientCode) {
153
156
  if (await botIsPaused(runtime.patientCode, { label: '[schedulePatientReminder]' })) {
154
157
  return JSON.stringify({ success: false, error: PAUSED_ERROR, data: {} });
@@ -53,7 +53,7 @@ const { MAX_NOTE_LENGTH, openCaseIds, readPatientCases, updatePatientTask } = re
53
53
  const { countMessages } = require('./messageService');
54
54
  const { getEscalationApprover, listEscalationApprovers } = require('./physicianService');
55
55
  const { getThreadInfo, switchThreadStoppedStatus } = require('./threadService');
56
- const { effectiveUrgencyOf, levelsOf, patientTimerMinutes, responseDeadlineOf, responseDeadlinePolicy } = require('./reviewDeadlineService');
56
+ const { effectiveUrgencyOf, patientTimerMinutes, responseDeadlineOf, responseDeadlinePolicy } = require('./reviewDeadlineService');
57
57
  const { caseTaskLive, scheduleCaseSync } = require('./escalationCaseTaskService');
58
58
  const { groupConfigured, sendTeamAlert, teamChannelConfigured } = require('./teamAlertService');
59
59
 
@@ -1027,12 +1027,9 @@ async function takenReason(review, since, timer, ownStart = null) {
1027
1027
  async function caseTakenReason(review, from, level) {
1028
1028
  const atOrAfter = (at) => at != null && new Date(at).getTime() >= from.getTime();
1029
1029
  if ((review.decisions ?? []).some((decision) => atOrAfter(decision.createdAt))) return 'decision';
1030
- const changes = review.urgencyReclassifications ?? [];
1031
- const levelsAt = (at) => levelsOf(currentAlarms(review).filter((alarm) => new Date(alarm.raisedAt) <= new Date(at)), changes.filter((change) => new Date(change.at) < new Date(at)), appliedLevelOf);
1032
- if (level !== 'stat' && levelsAt(new Date(8.64e15)).some((entry) => entry.level === 'stat')) return 'stat_alarm';
1033
- // Lowering the level, from what this episode's alarms were at, means someone looked at the case; a raise restarts the clock instead.
1034
- const lowered = (change) => (URGENCY_RANK[change.toLevel] || 0) < Math.max(0, ...levelsAt(change.at).map((entry) => URGENCY_RANK[entry.level] || 0));
1035
- if (changes.some((change) => atOrAfter(change.at) && lowered(change))) return 'reclassified';
1030
+ const stat = (alarm) => alarm.urgencyLevel === 'stat' || alarm.appliedLevel === 'stat';
1031
+ if (level !== 'stat' && currentAlarms(review).some(stat)) return 'stat_alarm';
1032
+ if ((review.urgencyReclassifications ?? []).some((change) => atOrAfter(change.at))) return 'reclassified';
1036
1033
  if ((review.callLogs ?? []).some((call) => call.outcome === 'contacted' && atOrAfter(call.calledAt))) return 'call_contacted';
1037
1034
  // A read error goes back to the sweep to retry; only a thread that does not exist (no turn to run
1038
1035
  // anyway) skips the prompt.
@@ -45,20 +45,17 @@ function responseDeadlinePolicy() {
45
45
  };
46
46
  }
47
47
 
48
- // Each alarm at the level the team set for it since it was raised; a raise restarts its clock, a lowering keeps it.
49
- function levelsOf(alarms, reclassifications, startLevel = (alarm) => alarm.urgencyLevel) {
50
- const changes = [...(reclassifications ?? [])].sort((a, b) => timeOf(a.at) - timeOf(b.at));
51
- return (alarms ?? []).map((alarm) => changes
48
+ function alarmLevelsOf(review) {
49
+ const reclassifications = [...(review.urgencyReclassifications ?? [])].sort((a, b) => timeOf(a.at) - timeOf(b.at));
50
+ return (review.alarms ?? []).map((alarm) => reclassifications
52
51
  .filter((change) => timeOf(alarm.raisedAt) <= timeOf(change.at))
53
52
  .reduce((entry, change) => ({
54
53
  alarm,
55
54
  level: change.toLevel,
56
55
  clockFrom: rankOf(change.toLevel) > rankOf(entry.level) ? change.at : entry.clockFrom,
57
- }), { alarm, level: startLevel(alarm), clockFrom: alarm.raisedAt }));
56
+ }), { alarm, level: alarm.urgencyLevel, clockFrom: alarm.raisedAt }));
58
57
  }
59
58
 
60
- const alarmLevelsOf = (review) => levelsOf(review.alarms, review.urgencyReclassifications);
61
-
62
59
  function effectiveUrgencyOf(review) {
63
60
  const lead = alarmLevelsOf(review).reduce((top, entry) => (
64
61
  !top || rankOf(entry.level) > rankOf(top.level)
@@ -109,7 +106,6 @@ function responseDeadlineOf(review, policy) {
109
106
  module.exports = {
110
107
  BUSINESS_HOURS_LEVELS,
111
108
  effectiveUrgencyOf,
112
- levelsOf,
113
109
  responseDeadlineOf,
114
110
  patientTimerMinutes,
115
111
  pendingWaitMinutes,
@@ -6,7 +6,7 @@ const { readGroupMessageId } = require('../clinical/services/clinicalAirtableSer
6
6
  const { escalationAutoHandoffLive, escalationPatientTimerLive, escalationUntakenAlertsLive } = require('../clinical/flags/escalationFlags');
7
7
 
8
8
  const { logPatientChange } = require('./patientService');
9
- const { BUSINESS_HOURS_LEVELS, levelsOf, responseDeadlinePolicy, untakenStagesOf } = require('./reviewDeadlineService');
9
+ const { BUSINESS_HOURS_LEVELS, responseDeadlinePolicy, untakenStagesOf } = require('./reviewDeadlineService');
10
10
  const { BOOKKEEPING, FEVER_CATEGORY, PRE_DECISION_STATUSES, appliedLevelOf, caseTakenReason, currentAlarms, teamAlertIdentity } = require('./escalationReviewService');
11
11
  const { settleCharacterization } = require('./characterizationOutcomeService');
12
12
  const { sendTeamAlert } = require('./teamAlertService');
@@ -34,37 +34,31 @@ const duration = (minutes) => {
34
34
  return rest ? `${hours} h ${rest} min` : `${hours} h`;
35
35
  };
36
36
 
37
- // The clock runs at the highest level since the last decision, its stages from the first alarm or team raise at that level.
38
- // The episode keeps the start the alarms' own levels give it, so a reclassification never re-keys its drafts or grave alerts.
39
- function episodeStartOf(alarms) {
40
- const top = alarms.reduce((level, alarm) => ((URGENCY_RANK[appliedLevelOf(alarm)] || 0) > (URGENCY_RANK[level] || 0) ? appliedLevelOf(alarm) : level), null);
41
- return new Date(Math.min(...alarms.filter((alarm) => appliedLevelOf(alarm) === top).map((alarm) => new Date(alarm.raisedAt).getTime())));
42
- }
43
-
37
+ // The clock runs at the highest level raised since the last decision, from the first alarm at that level.
44
38
  function untakenClockOf(review, policy) {
45
- const entries = levelsOf(currentAlarms(review), review.urgencyReclassifications, appliedLevelOf).filter((entry) => UNTAKEN_LEVELS.includes(entry.level));
46
- const level = entries.reduce((top, entry) => (URGENCY_RANK[entry.level] > (URGENCY_RANK[top] || 0) ? entry.level : top), null);
39
+ const alarms = currentAlarms(review).filter((alarm) => UNTAKEN_LEVELS.includes(appliedLevelOf(alarm)));
40
+ const level = alarms.reduce((top, alarm) => (
41
+ URGENCY_RANK[appliedLevelOf(alarm)] > (URGENCY_RANK[top] || 0) ? appliedLevelOf(alarm) : top
42
+ ), null);
47
43
  if (!level) return null;
48
- const atLevel = entries.filter((entry) => entry.level === level);
49
- const earliest = (dates) => new Date(Math.min(...dates.map((date) => new Date(date).getTime())));
50
- const stagesFrom = earliest(atLevel.map((entry) => entry.clockFrom));
44
+ const atLevel = alarms.filter((alarm) => appliedLevelOf(alarm) === level);
45
+ const since = new Date(atLevel[0].raisedAt);
51
46
  return {
52
47
  level,
53
- since: episodeStartOf(entries.map((entry) => entry.alarm)),
54
- stagesFrom,
55
- symptom: oneLineOf(atLevel.at(-1).alarm.symptom),
56
- emergencyRecordId: atLevel.find((entry) => entry.alarm.emergencyRecordId)?.alarm.emergencyRecordId ?? null,
57
- stages: untakenStagesOf(level, stagesFrom, policy),
48
+ since,
49
+ symptom: oneLineOf(atLevel.at(-1).symptom),
50
+ emergencyRecordId: atLevel.find((alarm) => alarm.emergencyRecordId)?.emergencyRecordId ?? null,
51
+ stages: untakenStagesOf(level, since, policy),
58
52
  };
59
53
  }
60
54
 
61
- const sameStage = (clock, stage) => ({ level: clock.level, stage: stage.stage, since: clock.stagesFrom });
55
+ const sameStage = (clock, stage) => ({ level: clock.level, stage: stage.stage, since: clock.since });
62
56
 
63
57
  function dueStageOf(review, clock, now) {
64
58
  const due = clock.stages.filter((stage) => stage.dueAt && stage.dueAt <= now).at(-1);
65
59
  if (!due || now.getTime() - due.dueAt.getTime() > STALE_MS) return null;
66
60
  const recorded = (review.untakenAlerts ?? []).some((entry) => entry.level === clock.level
67
- && entry.stage === due.stage && new Date(entry.since).getTime() === clock.stagesFrom.getTime());
61
+ && entry.stage === due.stage && new Date(entry.since).getTime() === clock.since.getTime());
68
62
  return recorded ? null : due;
69
63
  }
70
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.1.0-dev.18191",
3
+ "version": "6.1.1",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",