@peopl-health/nexus 5.58.0-dev.10497 → 5.58.0-dev.10499
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 {
|
|
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
|
|
129
|
+
const patientDrugs = unproposedDrugsIn(patientMessage, settled.proposal);
|
|
130
130
|
if (!settled.invalid && patientDrugs.length) {
|
|
131
|
-
settled.invalid = [`el mensaje al paciente menciona ${patientDrugs.join(', ')}
|
|
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, ...drug.drug.split('/'), ...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(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
110
|
+
unproposedDrugsIn,
|
|
106
111
|
};
|