@peopl-health/nexus 6.4.16 → 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.
@@ -6,8 +6,14 @@ const DEFAULT_FOLLOW_UP_HOURS = Object.freeze({ auto: 24, check_in: 24, vigilanc
6
6
 
7
7
  const needsPrescriber = (plan) => plan.items.length > 0 || plan.studies.length > 0;
8
8
 
9
+ const DURATION_TEXTS = Object.freeze({ as_needed: 'solo si lo necesita', continuous: 'de forma continua, hasta nuevo aviso', unspecified: null });
9
10
  const daysText = (days) => (days === 1 ? '1 día' : `${days} días`);
10
- const itemLine = (item) => `${[item.drug, item.strength].filter(Boolean).join(' ')}: ${item.dose} ${item.frequency} por ${daysText(item.days)}.`;
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
+ };
16
+ const itemLine = (item) => `${[item.drug, item.strength].filter(Boolean).join(' ')}: ${[item.dose, item.frequency, durationTextOf(item)].filter(Boolean).join(' ')}.`;
11
17
  const studyLine = (study) => `${study.name}${study.instructions ? `: ${study.instructions}` : ''}.`;
12
18
  // The defaults for the plan_instructions rows of the Config base; {horas} is filled with the follow-up hours.
13
19
  const PLAN_TEXTS = Object.freeze({
@@ -58,8 +64,9 @@ function prescriptionText(plan) {
58
64
  function dosingOf(item, formularyKey) {
59
65
  const entry = formularyFor(formularyKey);
60
66
  const dosing = entry && findDrug(entry, item)?.dosing;
61
- if (!dosing) return { dose: oneLineOf(item.instructions) || null, frequency: null, days: null, note: null };
62
- return { dose: dosing.dose ?? null, frequency: dosing.frequency ?? null, days: dosing.days ?? null, note: dosing.note ?? null };
67
+ if (!dosing) return { dose: oneLineOf(item.instructions) || null, frequency: null, duration: 'days', days: null, 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 };
63
70
  }
64
71
 
65
72
  // What the formulary adds after the dosing («además, valoración por oftalmología») goes to the note.
@@ -80,7 +87,7 @@ function proposedPlanOf(draft) {
80
87
 
81
88
  // The note and home care count, so what the doctor wrote anywhere in the plan is never flagged.
82
89
  const plannedTextOf = (plan) => [
83
- ...plan.items.flatMap((item) => [item.drug, item.strength, item.dose, item.frequency, item.days && `por ${item.days} dias`]),
90
+ ...plan.items.flatMap((item) => [item.drug, item.strength, item.dose, item.frequency, durationTextOf(item)]),
84
91
  ...plan.studies.flatMap((study) => [study.name, study.instructions]),
85
92
  ...plan.homeCare,
86
93
  plan.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 },
@@ -2,7 +2,7 @@ const { DEFAULT_FOLLOW_UP_HOURS, planInstructions, plannedTextOf } = require('..
2
2
  const { allNumbersOf, dosingFactsOf, isDosingSentence, looseNumbersOf, urgencyWordsIn } = require('../helpers/planTextHelper');
3
3
  const { httpError } = require('../../utils/httpErrorUtils');
4
4
  const { oneLineOf } = require('../../utils/coercionUtils');
5
- const { PLAN_FOLLOW_UPS } = require('../../models/escalationReviewModel');
5
+ const { PLAN_DURATIONS, PLAN_FOLLOW_UPS } = require('../../models/escalationReviewModel');
6
6
  const { normalizeForAnchor } = require('../../utils/textMatchUtils');
7
7
  const { drugsNamedIn, isDrugNamed, unplannedDrugsIn } = require('./treatmentProposalService');
8
8
 
@@ -48,12 +48,16 @@ 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
+ 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';
51
54
  return {
52
55
  drug: neededText(item?.drug, `${name}.drug`),
53
56
  strength: textOf(item?.strength, `${name}.strength`),
54
57
  dose: neededText(item?.dose, `${name}.dose`),
55
58
  frequency: neededText(item?.frequency, `${name}.frequency`),
56
- days: wholeNumber(item?.days, `${name}.days`, MAX_DAYS),
59
+ duration,
60
+ days: duration === 'days' ? wholeNumber(item?.days, `${name}.days`, MAX_DAYS) : null,
57
61
  position,
58
62
  reason,
59
63
  formularyKey: textOf(item?.formularyKey, `${name}.formularyKey`),
@@ -14,6 +14,7 @@ const CANCELLABLE_AFTER_HANDOFF_STATUSES = ['awaiting_doctor', 'approved', 'retu
14
14
  const CANCELLABLE_STATUSES = ['open', 'documenting', 'draft_ready', ...CANCELLABLE_AFTER_HANDOFF_STATUSES];
15
15
  const DOCTOR_DECISIONS = ['approved', 'edited_approved', 'plan_approved', 'needs_intervention', 'returned', 'monitor', 'direct_chat'];
16
16
  const PLAN_FOLLOW_UPS = ['none', 'auto', 'check_in', 'vigilancia'];
17
+ const PLAN_DURATIONS = Object.freeze(['days', 'as_needed', 'continuous', 'unspecified']);
17
18
  const DECISION_SOURCES = ['platform', 'registered_by_navigator', 'chat'];
18
19
  const RETURN_REASONS = ['llamar', 'falta_dato', 'no_requiere'];
19
20
 
@@ -210,7 +211,8 @@ const planItemSchema = new mongoose.Schema({
210
211
  strength: { type: String, default: null },
211
212
  dose: { type: String, required: true },
212
213
  frequency: { type: String, required: true },
213
- days: { type: Number, required: true },
214
+ duration: { type: String, enum: PLAN_DURATIONS, default: 'days' },
215
+ days: { type: Number, default: null },
214
216
  position: { type: String, default: null },
215
217
  reason: { type: String, default: null },
216
218
  formularyKey: { type: String, default: null },
@@ -443,6 +445,7 @@ module.exports = {
443
445
  DOCTOR_DECISIONS,
444
446
  HANDOFF_MODES,
445
447
  INTERRUPTED_STATUSES,
448
+ PLAN_DURATIONS,
446
449
  PLAN_FOLLOW_UPS,
447
450
  FOLLOWUP_STATUSES,
448
451
  RETURN_REASONS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.4.16",
3
+ "version": "6.4.18",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",