@peopl-health/nexus 6.0.1 → 6.0.2
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.
|
@@ -117,7 +117,9 @@ async function handOff(review, clock, outcome, now) {
|
|
|
117
117
|
return true;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
// Only the first handoff reaches the group; a later update to the doctor shows in the platform.
|
|
120
121
|
async function sendHandoffNotice(review, clock, outcome) {
|
|
122
|
+
if (outcome.update) return;
|
|
121
123
|
try {
|
|
122
124
|
await postHandoffNotice(review, clock, outcome);
|
|
123
125
|
} catch (error) {
|
|
@@ -136,7 +138,8 @@ async function sendGaveUpNotice(review, clock) {
|
|
|
136
138
|
'Qué hacer: revisar el caso y pasarlo al médico a mano',
|
|
137
139
|
link,
|
|
138
140
|
].filter(Boolean).join('\n');
|
|
139
|
-
const
|
|
141
|
+
const threadBody = '⚠️ No pudo pasar solo al médico: pasarlo a mano';
|
|
142
|
+
const sent = await sendGroupNotice(body, await readGroupMessageId(clock.emergencyRecordId, review.patientCode), threadBody);
|
|
140
143
|
await audit(review, { action: 'auto_handoff_gave_up', urgencyLevel: clock.level, delivered: sent.delivered });
|
|
141
144
|
} catch (error) {
|
|
142
145
|
logger.error('[CharacterizationOutcome] The give-up notice was not sent', {
|
|
@@ -145,19 +148,19 @@ async function sendGaveUpNotice(review, clock) {
|
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
|
|
148
|
-
async function postHandoffNotice(review, clock, { note
|
|
151
|
+
async function postHandoffNotice(review, clock, { note }) {
|
|
149
152
|
const { patient, doctor, link } = await teamAlertIdentity(review);
|
|
150
153
|
const taken = await takenOf(review, clock);
|
|
151
|
-
const header =
|
|
154
|
+
const header = taken ? '📋 Pasó al médico' : '📋 Pasó al médico · todavía sin tomar';
|
|
152
155
|
const body = [
|
|
153
|
-
|
|
156
|
+
header,
|
|
154
157
|
[`${patient} (${doctor})`, clock.symptom].filter(Boolean).join(' · '),
|
|
155
158
|
note,
|
|
156
159
|
!taken && 'Qué hacer: escribir o llamar a la paciente si nadie lo ha hecho',
|
|
157
160
|
link,
|
|
158
161
|
].filter(Boolean).join('\n');
|
|
159
162
|
const quoted = await readGroupMessageId(clock.emergencyRecordId, review.patientCode);
|
|
160
|
-
const sent = await sendGroupNotice(body, quoted);
|
|
163
|
+
const sent = await sendGroupNotice(body, quoted, [header, note].filter(Boolean).join('\n'));
|
|
161
164
|
await audit(review, { action: 'handoff_notice_sent', urgencyLevel: clock.level, delivered: sent.delivered });
|
|
162
165
|
}
|
|
163
166
|
|
|
@@ -173,6 +176,7 @@ async function graveMessage(review, clock, entries) {
|
|
|
173
176
|
`Qué hacer: ${action}`,
|
|
174
177
|
link,
|
|
175
178
|
].join('\n'),
|
|
179
|
+
threadBody: `❗ Falta dato grave: ${missing}\nQué hacer: ${action}`,
|
|
176
180
|
template: { 1: `${LEVEL_LABELS[clock.level]}, falta dato grave${clock.symptom ? ` (${clock.symptom})` : ''}`, 2: patient, 3: doctor, 4: `Falta: ${missing} · ${action}`, 5: link },
|
|
177
181
|
};
|
|
178
182
|
}
|
|
@@ -205,7 +209,7 @@ async function sendDueGraveAlerts(review, clock, entries, now) {
|
|
|
205
209
|
let delivered = 0;
|
|
206
210
|
try {
|
|
207
211
|
delivered = taken
|
|
208
|
-
? Number((await sendGroupNotice(message.body, quoted)).delivered)
|
|
212
|
+
? Number((await sendGroupNotice(message.body, quoted, message.threadBody)).delivered)
|
|
209
213
|
: (await sendTeamAlert({ message, operator: OPERATOR, quoted })).delivered;
|
|
210
214
|
} catch (error) {
|
|
211
215
|
logger.error('[CharacterizationOutcome] The grave alert was not sent', {
|
|
@@ -109,10 +109,11 @@ async function postToGroup(body, quoted) {
|
|
|
109
109
|
return { delivered: false, error: `whapi responded ${res.status}` };
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
// A reply in the alarm's thread carries `threadBody`, which leaves out what the quoted alert already says.
|
|
113
|
+
async function sendToGroup(body, quoted = null, threadBody = null) {
|
|
113
114
|
if (!groupConfigured()) return { delivered: false, error: 'WHAPI_TOKEN or ESCALATION_TEAM_GROUP_ID is not configured' };
|
|
114
115
|
try {
|
|
115
|
-
const sent = await postToGroup(body, quoted);
|
|
116
|
+
const sent = await postToGroup(quoted && threadBody ? threadBody : body, quoted);
|
|
116
117
|
// A quoted message Whapi no longer knows must not cost the alert: it goes out unthreaded.
|
|
117
118
|
return sent.delivered || !quoted ? sent : await postToGroup(body, null);
|
|
118
119
|
} catch (error) {
|
|
@@ -123,7 +124,7 @@ async function sendToGroup(body, quoted = null) {
|
|
|
123
124
|
// Alerts the group and the on-call phones for `level` (all without one); one failed recipient never stops the others and nothing throws.
|
|
124
125
|
async function sendTeamAlert({ message, operator, level = null, notice = false, quoted = null }) {
|
|
125
126
|
const templateKey = notice ? NOTICE_TEMPLATE_KEY : ALERT_TEMPLATE_KEY;
|
|
126
|
-
const group = await sendToGroup(message.body, quoted);
|
|
127
|
+
const group = await sendToGroup(message.body, quoted, message.threadBody);
|
|
127
128
|
const phones = [];
|
|
128
129
|
for (const code of await teamPhones(level)) {
|
|
129
130
|
try {
|
|
@@ -102,6 +102,7 @@ async function untakenMessage(review, clock, stage, now) {
|
|
|
102
102
|
`Qué hacer: ${action}`,
|
|
103
103
|
link,
|
|
104
104
|
].filter(Boolean).join('\n'),
|
|
105
|
+
threadBody: [`⏰ ${level} sin tomar · ${deadline}`, question && `Falta saber: ${question}`, note].filter(Boolean).join('\n'),
|
|
105
106
|
template: {
|
|
106
107
|
1: `${level}, ${deadline}${clock.symptom ? ` (${clock.symptom})` : ''}`,
|
|
107
108
|
2: patient,
|