@peopl-health/nexus 6.5.0 → 6.5.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.
@@ -9,7 +9,7 @@ const { MapCache } = require('../../utils/MapCache');
9
9
  const PLAN_TEXTS_TABLE = 'plan_instructions';
10
10
  const CACHE_TTL = 5 * 60 * 1000;
11
11
  const CACHE_KEY = 'planTexts';
12
- const NEEDS_HOURS = ['FOLLOW_UP_CHECK_IN', 'FOLLOW_UP_VIGILANCIA'];
12
+ const PLACEHOLDERS = { FOLLOW_UP_CHECK_IN: '{horas}', FOLLOW_UP_VIGILANCIA: '{horas}', PRESCRIBER: '{medico}' };
13
13
 
14
14
  const cache = new MapCache({ maxSize: 1, ttl: CACHE_TTL });
15
15
 
@@ -28,8 +28,8 @@ async function getPlanTexts() {
28
28
  const texts = Object.fromEntries(Object.entries(PLAN_TEXTS).map(([key, fallback]) => {
29
29
  const value = byKey[key];
30
30
  if (!value) return [key, fallback];
31
- if (NEEDS_HOURS.includes(key) && !value.includes('{horas}')) {
32
- logger.error('[planTextsConfig] follow-up text lacks {horas}; using the default', { key });
31
+ if (PLACEHOLDERS[key] && !value.includes(PLACEHOLDERS[key])) {
32
+ logger.error('[planTextsConfig] text lacks its placeholder; using the default', { key, placeholder: PLACEHOLDERS[key] });
33
33
  return [key, fallback];
34
34
  }
35
35
  return [key, value];
@@ -15,7 +15,7 @@ const durationTextOf = (item) => {
15
15
  };
16
16
  const itemLine = (item) => `${[item.drug, item.strength].filter(Boolean).join(' ')}: ${[item.dose, item.frequency, durationTextOf(item)].filter(Boolean).join(' ')}.`;
17
17
  const studyLine = (study) => `${study.name}${study.instructions ? `: ${study.instructions}` : ''}.`;
18
- // The defaults for the plan_instructions rows of the Config base; {horas} is filled with the follow-up hours.
18
+ // The defaults for the plan_instructions rows of the Config base; {horas} is filled with the follow-up hours, {medico} with the prescriber.
19
19
  const PLAN_TEXTS = Object.freeze({
20
20
  INTRO: 'Transmítele al paciente lo que indicó el médico, con tus palabras: no agregues medicamentos ni estudios que el médico no indicó, ni avisos de urgencia que no dio.',
21
21
  MEDS_HEADER: 'Medicamentos (no cambies dosis, frecuencia ni días; escríbelos con números, como vienen aquí, sin repetirlos con letra):',
@@ -23,6 +23,9 @@ const PLAN_TEXTS = Object.freeze({
23
23
  COMPLEMENTARY: 'Indicaciones complementarias: además de lo anterior, por cada síntoma que contó dale de 2 a 4 cuidados en casa concretos, accionables y de alto valor, diciendo qué hacer y cómo hacerlo, aunque el médico no los haya escrito. Escríbelos con palabras, sin números, cantidades ni frecuencias y sin avisos de urgencia, para que no se confundan con lo que indicó el médico. Solo medidas estándar de enfermería oncológica: sin medicamentos, suplementos, remedios caseros ni dietas restrictivas.',
24
24
  FOLLOW_UP_CHECK_IN: 'Seguimiento: le escribiremos en unas {horas} horas para ver cómo va.',
25
25
  FOLLOW_UP_VIGILANCIA: 'Seguimiento: queda en vigilancia las próximas {horas} horas; le escribiremos para ver cómo va.',
26
+ // The assistant otherwise names the treating oncologist from the patient's context.
27
+ PRESCRIBER: 'Quién lo indicó: {medico}. Si dices quién lo indicó, nombra a {medico} y a ningún otro médico.',
28
+ NO_PRESCRIBER: 'Quién lo indicó: el equipo médico del programa de acompañamiento. Si dices quién lo indicó, di eso y no nombres a ningún médico.',
26
29
  });
27
30
 
28
31
  const FOLLOW_UP_KEYS = { auto: 'FOLLOW_UP_CHECK_IN', check_in: 'FOLLOW_UP_CHECK_IN', vigilancia: 'FOLLOW_UP_VIGILANCIA' };
@@ -44,6 +47,11 @@ function planInstructions(plan, texts = PLAN_TEXTS) {
44
47
  return lines.join('\n');
45
48
  }
46
49
 
50
+ const prescriberLineOf = (plan, texts = PLAN_TEXTS) => {
51
+ const name = oneLineOf(plan.prescriber?.name);
52
+ return name ? texts.PRESCRIBER.replaceAll('{medico}', () => name) : texts.NO_PRESCRIBER;
53
+ };
54
+
47
55
  function planSummary(plan) {
48
56
  const lines = [...plan.items.map(itemLine), ...plan.studies.map((study) => `Estudio: ${studyLine(study)}`)];
49
57
  if (plan.homeCare.length) lines.push(`Cuidados en casa: ${plan.homeCare.join('; ')}.`);
@@ -101,6 +109,7 @@ module.exports = {
101
109
  planInstructions,
102
110
  planSummary,
103
111
  plannedTextOf,
112
+ prescriberLineOf,
104
113
  prescriptionText,
105
114
  proposedPlanOf,
106
115
  };
@@ -224,7 +224,8 @@ function briefCaseLine(identity, entry, alarmSymptom) {
224
224
  const graded = [1, 2, 3, 4, 5].includes(entry?.grade) && !/\bG[1-5]\b/i.test(label) ? `${label} G${entry.grade}` : label;
225
225
  const patient = identity.age ? `${titleCased(oneLineOf(identity.patientName))}, ${identity.age}` : titleCased(oneLineOf(identity.patientName));
226
226
  const doctor = titleCased(oneLineOf(identity.treatingDoctor));
227
- return doctor ? `${patient} · ${graded} (${withTitle(doctor)})` : `${patient} · ${graded}`;
227
+ // The name alone: «Dr./Dra.» stands in for an unknown gender and only adds noise to a short line.
228
+ return doctor ? `${patient} · ${graded} (${doctor})` : `${patient} · ${graded}`;
228
229
  }
229
230
 
230
231
  // The four lines of the doctor's alert; each is a template variable, so none may be empty.
@@ -36,7 +36,7 @@ const { drugsNamedIn } = require('../clinical/services/treatmentProposalService'
36
36
  const { characterizationSeedOf } = require('../clinical/helpers/reviewUpdateHelper');
37
37
  const { getPlanTexts } = require('../clinical/config/planTextsConfig');
38
38
  const { retireSilenceNets } = require('../clinical/services/contingencyDispatchService');
39
- const { DEFAULT_FOLLOW_UP_HOURS, needsPrescriber, planInstructions, planSummary, prescriptionText, proposedPlanOf } = require('../clinical/helpers/doctorPlanHelper');
39
+ const { DEFAULT_FOLLOW_UP_HOURS, needsPrescriber, planInstructions, planSummary, prescriberLineOf, prescriptionText, proposedPlanOf } = require('../clinical/helpers/doctorPlanHelper');
40
40
  const { approvedInstructions, planOf, replyIssues } = require('../clinical/services/doctorPlanService');
41
41
  const { readNoteFacts, assertionOf } = require('../clinical/services/escalationNoteFactsService');
42
42
  const { humanReplyFilter } = require('../clinical/config/safetyNetConfig');
@@ -2270,7 +2270,7 @@ async function sendPlanThroughAssistant({ claimed, claim, decisionNumber, plan,
2270
2270
  try {
2271
2271
  if (needsPrescriber(plan) && !prescriberEmail) throw httpError(409, 'This plan names no doctor to sign the receta; record the plan again');
2272
2272
  ({ delivery = null, sendThrew = false, reply = null } = await getMessaging().processSystemMessage(
2273
- claimed.patientCode, [plan.instructions], 'system', { reply: true, triggeredBy: operator },
2273
+ claimed.patientCode, [`${plan.instructions}\n${prescriberLineOf(plan, await getPlanTexts())}`], 'system', { reply: true, triggeredBy: operator },
2274
2274
  ) ?? {});
2275
2275
  } catch (error) {
2276
2276
  // A turn refused by a deploy's drain never ran; any other failure after the instructions were stored may have answered.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.5.0",
3
+ "version": "6.5.2",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",