@peopl-health/nexus 6.4.17 → 6.4.18

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.
@@ -8,7 +8,11 @@ const needsPrescriber = (plan) => plan.items.length > 0 || plan.studies.length >
8
8
 
9
9
  const DURATION_TEXTS = Object.freeze({ as_needed: 'solo si lo necesita', continuous: 'de forma continua, hasta nuevo aviso', unspecified: null });
10
10
  const daysText = (days) => (days === 1 ? '1 día' : `${days} días`);
11
- const durationTextOf = (item) => (!item.duration || item.duration === 'days' ? `por ${daysText(item.days)}` : DURATION_TEXTS[item.duration]);
11
+ const SAID_DURATION = Object.freeze({ as_needed: /raz[oó]n necesaria|si lo necesita/i, continuous: /forma continua/i });
12
+ const durationTextOf = (item) => {
13
+ if (!item.duration || item.duration === 'days') return `por ${daysText(item.days)}`;
14
+ return SAID_DURATION[item.duration]?.test(`${item.dose ?? ''} ${item.frequency ?? ''}`) ? null : DURATION_TEXTS[item.duration];
15
+ };
12
16
  const itemLine = (item) => `${[item.drug, item.strength].filter(Boolean).join(' ')}: ${[item.dose, item.frequency, durationTextOf(item)].filter(Boolean).join(' ')}.`;
13
17
  const studyLine = (study) => `${study.name}${study.instructions ? `: ${study.instructions}` : ''}.`;
14
18
  // The defaults for the plan_instructions rows of the Config base; {horas} is filled with the follow-up hours.
@@ -56,21 +60,13 @@ function prescriptionText(plan) {
56
60
  return lines.join('\n');
57
61
  }
58
62
 
59
- const FREQUENCY_DURATIONS = Object.freeze([[/\s*por raz[oó]n necesaria$/i, 'as_needed'], [/\s*de forma continua$/i, 'continuous']]);
60
-
61
- // A formulary frequency that already names the duration gives it up, so the line does not say it twice.
62
- function frequencyDurationOf(frequency) {
63
- const [pattern, duration] = FREQUENCY_DURATIONS.find(([candidate]) => candidate.test(frequency ?? '')) ?? [];
64
- return duration ? { frequency: frequency.replace(pattern, ''), duration } : { frequency, duration: 'days' };
65
- }
66
-
67
63
  // The formulary's own fields; a drug it no longer lists keeps its old text as the dose, for the doctor to split.
68
64
  function dosingOf(item, formularyKey) {
69
65
  const entry = formularyFor(formularyKey);
70
66
  const dosing = entry && findDrug(entry, item)?.dosing;
71
67
  if (!dosing) return { dose: oneLineOf(item.instructions) || null, frequency: null, duration: 'days', days: null, note: null };
72
- const { frequency, duration } = frequencyDurationOf(dosing.frequency ?? null);
73
- return { dose: dosing.dose ?? null, frequency, duration, days: duration === 'days' ? dosing.days ?? null : null, note: dosing.note ?? null };
68
+ const duration = dosing.duration ?? 'days';
69
+ return { dose: dosing.dose ?? null, frequency: dosing.frequency ?? null, duration, days: duration === 'days' ? dosing.days ?? null : null, note: dosing.note ?? null };
74
70
  }
75
71
 
76
72
  // What the formulary adds after the dosing («además, valoración por oftalmología») goes to the note.
@@ -96,7 +96,7 @@ const TREATMENT_FORMULARY = deepFreeze([
96
96
  {
97
97
  drug: 'Butilhioscina/metamizol', brand: 'BUSCAPINA COMPUESTA', strength: '10/250 mg', position: 'ALT', tableLabel: 'Coadyuvante', class: 'antiespasmodico',
98
98
  instructions: '1 tableta cada 8 a 12 horas por razón necesaria',
99
- dosing: { dose: '1 tableta', frequency: 'cada 8 a 12 horas por razón necesaria' },
99
+ dosing: { dose: '1 tableta', frequency: 'cada 8 a 12 horas por razón necesaria', duration: 'as_needed' },
100
100
  contextNote: 'Coadyuvante para cólico, no tratamiento de la diarrea',
101
101
  },
102
102
  ],
@@ -256,12 +256,12 @@ const TREATMENT_FORMULARY = deepFreeze([
256
256
  {
257
257
  drug: 'Urea', brand: 'NUTRAPLUS', strength: '10%', position: '1L', tableLabel: '1L, especialmente HFS/hiperqueratosis', class: 'queratolitico',
258
258
  instructions: 'capa fina cada 12 horas de forma continua',
259
- dosing: { dose: 'capa fina', frequency: 'cada 12 horas de forma continua' },
259
+ dosing: { dose: 'capa fina', frequency: 'cada 12 horas de forma continua', duration: 'continuous' },
260
260
  },
261
261
  {
262
262
  drug: 'Ceramidas', brand: 'CERAVE', strength: null, position: '1L', tableLabel: '1L emoliente', class: 'emoliente',
263
263
  instructions: '2 a 3 veces al día de forma continua',
264
- dosing: { dose: '2 a 3 veces al día de forma continua' }, isPharmacological: false,
264
+ dosing: { dose: '2 a 3 veces al día de forma continua', duration: 'continuous' }, isPharmacological: false,
265
265
  },
266
266
  { drug: 'Emoliente', brand: 'EUCERIN', strength: null, position: '1L', tableLabel: '1L emoliente', class: 'emoliente', isPharmacological: false },
267
267
  { drug: 'Vaselina/petrolato', strength: null, position: '1L', tableLabel: '1L barrera', class: 'barrera_cutanea', isPharmacological: false },
@@ -48,9 +48,9 @@ function itemOf(item, index) {
48
48
  const position = textOf(item?.position, `${name}.position`)?.toUpperCase() ?? null;
49
49
  const reason = textOf(item?.reason, `${name}.reason`);
50
50
  if (position && position !== FIRST_LINE && !reason) throw httpError(400, `${name}.reason is required for a drug that is not first line`);
51
- const duration = item?.duration ?? 'days';
52
- if (!PLAN_DURATIONS.includes(duration)) throw httpError(400, `${name}.duration must be one of: ${PLAN_DURATIONS.join(', ')}`);
53
- if (duration !== 'days' && item?.days != null) throw httpError(400, `${name}.days must be empty when the duration is ${duration}`);
51
+ if (item?.duration != null && !PLAN_DURATIONS.includes(item.duration)) throw httpError(400, `${name}.duration must be one of: ${PLAN_DURATIONS.join(', ')}`);
52
+ // Typed days win: a client that predates the duration field sends the proposal's duration back beside them.
53
+ const duration = item?.days != null ? 'days' : item?.duration ?? 'days';
54
54
  return {
55
55
  drug: neededText(item?.drug, `${name}.drug`),
56
56
  strength: textOf(item?.strength, `${name}.strength`),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.4.17",
3
+ "version": "6.4.18",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",