@peopl-health/nexus 6.4.16 → 6.4.17

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,10 @@ 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 durationTextOf = (item) => (!item.duration || item.duration === 'days' ? `por ${daysText(item.days)}` : DURATION_TEXTS[item.duration]);
12
+ const itemLine = (item) => `${[item.drug, item.strength].filter(Boolean).join(' ')}: ${[item.dose, item.frequency, durationTextOf(item)].filter(Boolean).join(' ')}.`;
11
13
  const studyLine = (study) => `${study.name}${study.instructions ? `: ${study.instructions}` : ''}.`;
12
14
  // The defaults for the plan_instructions rows of the Config base; {horas} is filled with the follow-up hours.
13
15
  const PLAN_TEXTS = Object.freeze({
@@ -54,12 +56,21 @@ function prescriptionText(plan) {
54
56
  return lines.join('\n');
55
57
  }
56
58
 
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
+
57
67
  // The formulary's own fields; a drug it no longer lists keeps its old text as the dose, for the doctor to split.
58
68
  function dosingOf(item, formularyKey) {
59
69
  const entry = formularyFor(formularyKey);
60
70
  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 };
71
+ 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 };
63
74
  }
64
75
 
65
76
  // What the formulary adds after the dosing («además, valoración por oftalmología») goes to the note.
@@ -80,7 +91,7 @@ function proposedPlanOf(draft) {
80
91
 
81
92
  // The note and home care count, so what the doctor wrote anywhere in the plan is never flagged.
82
93
  const plannedTextOf = (plan) => [
83
- ...plan.items.flatMap((item) => [item.drug, item.strength, item.dose, item.frequency, item.days && `por ${item.days} dias`]),
94
+ ...plan.items.flatMap((item) => [item.drug, item.strength, item.dose, item.frequency, durationTextOf(item)]),
84
95
  ...plan.studies.flatMap((study) => [study.name, study.instructions]),
85
96
  ...plan.homeCare,
86
97
  plan.note,
@@ -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
+ 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
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.17",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",