@peopl-health/nexus 5.58.0-dev.10497 → 5.58.0-dev.10498

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.
@@ -13,7 +13,7 @@ const { logger } = require('../../utils/logger');
13
13
  const { safeParse } = require('../../utils/jsonUtils');
14
14
  const { withTiming } = require('../../utils/tracingDecorator');
15
15
 
16
- const { drugsNamedIn, validateProposal } = require('./treatmentProposalService');
16
+ const { unproposedDrugsIn, validateProposal } = require('./treatmentProposalService');
17
17
 
18
18
  const CONVERSATION_TURNS = 40;
19
19
  const TRIAGE_LIMIT = 3;
@@ -126,9 +126,9 @@ async function generateEscalationDraft({ code, callLogs = [], alarms = [], provi
126
126
  }
127
127
  const settled = settleProposal(parsed);
128
128
 
129
- const patientDrugs = settled.proposal ? [] : drugsNamedIn(patientMessage);
129
+ const patientDrugs = unproposedDrugsIn(patientMessage, settled.proposal);
130
130
  if (!settled.invalid && patientDrugs.length) {
131
- settled.invalid = [`el mensaje al paciente menciona ${patientDrugs.join(', ')} aunque no hay propuesta de tratamiento`];
131
+ settled.invalid = [`el mensaje al paciente menciona ${patientDrugs.join(', ')}, que no está en la propuesta de tratamiento`];
132
132
  }
133
133
 
134
134
  if (settled.invalid) {
@@ -88,19 +88,24 @@ function validateProposal(proposal, context = {}) {
88
88
  return { valid: issues.length === 0, issues, activeModifiers, pendingRuleOut, alwaysEscalate: entry.alwaysEscalate ?? null };
89
89
  }
90
90
 
91
+ const namesOf = (drug) => [drug.drug, ...String(drug.brand ?? '').split('/')].map(key).filter((name) => name.length >= 4);
92
+
91
93
  const DRUG_NAMES = [...new Set(TREATMENT_FORMULARY
92
94
  .flatMap((entry) => entry.drugs)
93
95
  .filter((drug) => drug.isPharmacological !== false)
94
- .flatMap((drug) => [drug.drug, ...String(drug.brand ?? '').split('/')])
95
- .map(key)
96
- .filter((name) => name.length >= 4))];
97
-
98
- function drugsNamedIn(text) {
96
+ .flatMap(namesOf))];
97
+
98
+ function unproposedDrugsIn(text, proposal) {
99
+ const entry = proposal ? formularyFor(proposal.symptom) : null;
100
+ const proposed = new Set((entry ? proposal.items : [])
101
+ .map((item) => findDrug(entry, item))
102
+ .filter(Boolean)
103
+ .flatMap(namesOf));
99
104
  const padded = ` ${key(text)} `;
100
- return DRUG_NAMES.filter((name) => padded.includes(` ${name} `));
105
+ return DRUG_NAMES.filter((name) => !proposed.has(name) && padded.includes(` ${name} `));
101
106
  }
102
107
 
103
108
  module.exports = {
104
109
  validateProposal,
105
- drugsNamedIn,
110
+ unproposedDrugsIn,
106
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.58.0-dev.10497",
3
+ "version": "5.58.0-dev.10498",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",