@peopl-health/nexus 5.56.15 → 5.56.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.
- package/lib/clinical/helpers/triageCaseBaseHelper.js +11 -2
- package/lib/clinical/services/escalationQuestionsService.js +5 -4
- package/lib/fhir/helpers/compositeHelper.js +25 -4
- package/lib/fhir/helpers/terminologyHelper.js +16 -0
- package/lib/services/escalationReviewService.js +3 -0
- package/lib/shared/dtos/GradedSymptom.js +1 -0
- package/lib/utils/dateUtils.js +7 -0
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const { ladderFor, renderLadder } = require('../services/ctcaeLadderService');
|
|
2
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
itemForQuestionId, affirmative, sentinelKind, dimensionsFor, isItemDimension,
|
|
4
|
+
} = require('../../fhir/helpers/terminologyHelper');
|
|
3
5
|
const { daysSince } = require('../../utils/dateUtils');
|
|
4
6
|
const { detectSafetyFlags } = require('./safetyFlagsHelper');
|
|
5
7
|
|
|
@@ -108,8 +110,15 @@ function reportedSymptomEvidence(symptom, catalog) {
|
|
|
108
110
|
.map((dimension) => `${DIMENSION_ES[dimension] || dimension}: ${answers[dimension]}`)
|
|
109
111
|
.join(' · ')}`);
|
|
110
112
|
}
|
|
113
|
+
const setAside = Object.entries(symptom.supplementaryAnswers || {});
|
|
114
|
+
if (setAside.length) {
|
|
115
|
+
lines.push(` Preguntas complementarias de PEOPL, fuera del grado: ${setAside
|
|
116
|
+
.map(([dimension, answer]) => `${DIMENSION_ES[dimension] || dimension}: ${answer}`)
|
|
117
|
+
.join(' · ')}. Miden otra cosa que el ítem del PRO-CTCAE; no confirman ni descartan el síntoma.`);
|
|
118
|
+
}
|
|
111
119
|
if (Array.isArray(catalog?.symptoms?.[symptom.term]?.dimensions)) {
|
|
112
|
-
const missing = dimensionsFor(catalog, symptom.term)
|
|
120
|
+
const missing = dimensionsFor(catalog, symptom.term)
|
|
121
|
+
.filter((dimension) => isItemDimension(catalog, symptom.term, dimension) && !answered.includes(dimension));
|
|
113
122
|
if (missing.length) {
|
|
114
123
|
lines.push(` Atributos que este ítem del PRO-CTCAE no preguntó: ${missing
|
|
115
124
|
.map((dimension) => DIMENSION_ES[dimension] || dimension).join(', ')}. No preguntado no es `
|
|
@@ -5,6 +5,7 @@ const { createLLMProvider } = require('../providers/createLLMProvider');
|
|
|
5
5
|
|
|
6
6
|
const { getEscalationContext } = require('../../services/escalationContextService');
|
|
7
7
|
|
|
8
|
+
const { mexicoDay } = require('../../utils/dateUtils');
|
|
8
9
|
const { logger } = require('../../utils/logger');
|
|
9
10
|
const { safeParse } = require('../../utils/jsonUtils');
|
|
10
11
|
const { withTiming } = require('../../utils/tracingDecorator');
|
|
@@ -17,10 +18,9 @@ const MAX_RED_FLAGS = 4;
|
|
|
17
18
|
const GRADED_FROM = 2;
|
|
18
19
|
|
|
19
20
|
const trimmed = (value) => String(value ?? '').trim();
|
|
20
|
-
const dayOf = (value) => (value ? String(value).slice(0, 10) : null);
|
|
21
21
|
|
|
22
22
|
function gradedSymptoms(triages, now) {
|
|
23
|
-
const today =
|
|
23
|
+
const today = mexicoDay(now);
|
|
24
24
|
return (Array.isArray(triages) ? triages : [])
|
|
25
25
|
.flatMap((triage) => (triage?.symptoms ?? []).map((symptom) => {
|
|
26
26
|
const grade = Math.max(symptom?.gradeNum ?? 0, symptom?.compositeGrade ?? 0);
|
|
@@ -31,7 +31,7 @@ function gradedSymptoms(triages, now) {
|
|
|
31
31
|
attributes: symptom?.attributes ?? null,
|
|
32
32
|
patientNote: symptom?.patientNote ?? null,
|
|
33
33
|
triagedAt: triage?.created ?? null,
|
|
34
|
-
isToday:
|
|
34
|
+
isToday: today !== null && mexicoDay(triage?.created) === today,
|
|
35
35
|
};
|
|
36
36
|
}))
|
|
37
37
|
.filter((symptom) => symptom.grade >= GRADED_FROM)
|
|
@@ -74,7 +74,8 @@ function questionsProvider() {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const shortList = (value, limit) => (Array.isArray(value) ? value : [])
|
|
77
|
-
.
|
|
77
|
+
.filter((entry) => typeof entry === 'string')
|
|
78
|
+
.map((entry) => entry.trim())
|
|
78
79
|
.filter(Boolean)
|
|
79
80
|
.slice(0, limit);
|
|
80
81
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const { logger } = require('../../utils/logger');
|
|
2
2
|
const {
|
|
3
3
|
itemForQuestionId,
|
|
4
|
+
isSupplementaryQuestion,
|
|
5
|
+
isItemDimension,
|
|
4
6
|
canonicalAnswer,
|
|
5
7
|
affirmative,
|
|
6
8
|
standardOrdinal,
|
|
@@ -18,15 +20,19 @@ function gradeComposites(catalog, input) {
|
|
|
18
20
|
const item = itemForQuestionId(catalog, questionId);
|
|
19
21
|
if (!item) continue;
|
|
20
22
|
const [term, dimension] = item;
|
|
21
|
-
if (!answersByTerm.has(term)) answersByTerm.set(term, {});
|
|
22
|
-
|
|
23
|
+
if (!answersByTerm.has(term)) answersByTerm.set(term, { own: {}, supplementary: {} });
|
|
24
|
+
const lane = isSupplementaryQuestion(catalog, questionId) ? 'supplementary' : 'own';
|
|
25
|
+
answersByTerm.get(term)[lane][dimension] = { label: String(canonicalAnswer(catalog, questionId, label)), raw: String(label) };
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
const pain = painDimensionAnswers(catalog, input.pain, input.triageId);
|
|
26
|
-
|
|
29
|
+
const lanes = [...answersByTerm]
|
|
30
|
+
.filter(([term]) => !(pain && term === PAIN_TERM))
|
|
31
|
+
.map(([term, answers]) => [term, splitSupplementary(catalog, term, answers)]);
|
|
32
|
+
if (pain) lanes.push([PAIN_TERM, { dimensionAnswers: pain, setAside: {} }]);
|
|
27
33
|
|
|
28
34
|
const graded = [];
|
|
29
|
-
for (const [term, dimensionAnswers] of
|
|
35
|
+
for (const [term, { dimensionAnswers, setAside }] of lanes) {
|
|
30
36
|
const ordinals = {};
|
|
31
37
|
for (const [dimension, label] of Object.entries(dimensionAnswers)) {
|
|
32
38
|
const ordinal = dimension === 'presence' ? presenceOrdinal(catalog, label) : standardOrdinal(catalog, dimension, label);
|
|
@@ -73,12 +79,27 @@ function gradeComposites(catalog, input) {
|
|
|
73
79
|
effective: input.authored || null,
|
|
74
80
|
triageId: input.triageId,
|
|
75
81
|
dimensionAnswers: dimensionAnswers,
|
|
82
|
+
...(Object.keys(setAside).length ? { supplementaryAnswers: setAside } : {}),
|
|
76
83
|
source: 'triage',
|
|
77
84
|
});
|
|
78
85
|
}
|
|
79
86
|
return graded;
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
function splitSupplementary(catalog, term, { own, supplementary }) {
|
|
90
|
+
const dimensionAnswers = Object.fromEntries(Object.entries(own).map(([dimension, { label }]) => [dimension, label]));
|
|
91
|
+
const hasOwn = Object.keys(own).length > 0;
|
|
92
|
+
const setAside = {};
|
|
93
|
+
for (const [dimension, { label, raw }] of Object.entries(supplementary)) {
|
|
94
|
+
if (dimensionAnswers[dimension] == null && (isItemDimension(catalog, term, dimension) || !hasOwn)) {
|
|
95
|
+
dimensionAnswers[dimension] = label;
|
|
96
|
+
} else {
|
|
97
|
+
setAside[dimension] = raw;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { dimensionAnswers, setAside };
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
function presenceOrdinal(catalog, label) {
|
|
83
104
|
const ordinal = standardOrdinal(catalog, 'presence', label);
|
|
84
105
|
if (ordinal !== null) return ordinal;
|
|
@@ -18,10 +18,12 @@ const DIMENSION_SCALES = {
|
|
|
18
18
|
const DIMENSION_ORDER = ['presence', 'frequency', 'intensity', 'interference', 'amount'];
|
|
19
19
|
|
|
20
20
|
const CANONICAL_SOURCE = 'original';
|
|
21
|
+
const SUPPLEMENTARY_SOURCE = 'extra-question';
|
|
21
22
|
|
|
22
23
|
function buildCatalog(items, composites = [], source = null) {
|
|
23
24
|
const symptoms = {};
|
|
24
25
|
const questionIndex = {};
|
|
26
|
+
const questionSource = {};
|
|
25
27
|
const answerMap = {};
|
|
26
28
|
const itemIndex = {};
|
|
27
29
|
|
|
@@ -57,6 +59,7 @@ function buildCatalog(items, composites = [], source = null) {
|
|
|
57
59
|
if (questionId != null && dimension) {
|
|
58
60
|
if (gradeableOnScale(dimension, options, map)) {
|
|
59
61
|
questionIndex[String(questionId)] = [term, dimension];
|
|
62
|
+
questionSource[String(questionId)] = row.source ?? null;
|
|
60
63
|
} else {
|
|
61
64
|
logger.warn('[buildCatalog] question not indexed: no answer option grades on its dimension scale', {
|
|
62
65
|
questionId,
|
|
@@ -86,6 +89,7 @@ function buildCatalog(items, composites = [], source = null) {
|
|
|
86
89
|
},
|
|
87
90
|
symptoms,
|
|
88
91
|
question_index: questionIndex,
|
|
92
|
+
question_source: questionSource,
|
|
89
93
|
item_index: itemIndex,
|
|
90
94
|
answer_map: answerMap,
|
|
91
95
|
composite_grades: compositeGrades,
|
|
@@ -169,6 +173,16 @@ function itemForQuestionId(catalog, questionId) {
|
|
|
169
173
|
return Array.isArray(entry) && entry.length >= 2 ? [entry[0], entry[1]] : null;
|
|
170
174
|
}
|
|
171
175
|
|
|
176
|
+
function isSupplementaryQuestion(catalog, questionId) {
|
|
177
|
+
return (catalog.question_source || {})[String(questionId).trim()] === SUPPLEMENTARY_SOURCE;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isItemDimension(catalog, term, dimension) {
|
|
181
|
+
const rec = getSymptom(catalog, term);
|
|
182
|
+
return (rec ? rec.dimensions : [])
|
|
183
|
+
.some((d) => d.dimension === dimension && d.source !== SUPPLEMENTARY_SOURCE);
|
|
184
|
+
}
|
|
185
|
+
|
|
172
186
|
function termForItem(catalog, item) {
|
|
173
187
|
return catalog.item_index[String(item ?? '').trim()] || null;
|
|
174
188
|
}
|
|
@@ -313,6 +327,8 @@ module.exports = {
|
|
|
313
327
|
allTerms,
|
|
314
328
|
compositeTableHash,
|
|
315
329
|
itemForQuestionId,
|
|
330
|
+
isSupplementaryQuestion,
|
|
331
|
+
isItemDimension,
|
|
316
332
|
termForItem,
|
|
317
333
|
getSymptom,
|
|
318
334
|
canonicalAnswer,
|
|
@@ -740,6 +740,9 @@ async function suggestKeyQuestions({ id, requestedBy, requestId = null } = {}) {
|
|
|
740
740
|
}
|
|
741
741
|
if (!generated.completed) throw httpError(generated.configured === false ? 503 : 502, generated.reason);
|
|
742
742
|
|
|
743
|
+
const settled = await loadReview(reviewId);
|
|
744
|
+
if (!DOCUMENTING_STATUSES.includes(settled.status)) throw httpError(409, STATUS_CONFLICT);
|
|
745
|
+
|
|
743
746
|
return generated;
|
|
744
747
|
}
|
|
745
748
|
|
|
@@ -14,6 +14,7 @@ const schema = z.strictObject({
|
|
|
14
14
|
effective: dateTime.nullable().default(null),
|
|
15
15
|
triageId: z.string(),
|
|
16
16
|
dimensionAnswers: z.record(z.string(), z.string()).default({}),
|
|
17
|
+
supplementaryAnswers: z.record(z.string(), z.string()).optional(),
|
|
17
18
|
source: z.string().default('triage'),
|
|
18
19
|
});
|
|
19
20
|
|
package/lib/utils/dateUtils.js
CHANGED
|
@@ -36,6 +36,12 @@ const ageInYears = (birthDate) => {
|
|
|
36
36
|
|
|
37
37
|
const isoDay = (value) => (typeof value === 'string' && value.length >= 10 ? value.slice(0, 10) : null);
|
|
38
38
|
|
|
39
|
+
const mexicoDay = (value) => {
|
|
40
|
+
if (value === null || value === undefined || value === '') return null;
|
|
41
|
+
const at = moment.tz(value, MEXICO_TZ);
|
|
42
|
+
return at.isValid() ? at.format('YYYY-MM-DD') : null;
|
|
43
|
+
};
|
|
44
|
+
|
|
39
45
|
const daysSince = (from, now = Date.now()) => {
|
|
40
46
|
const at = Date.parse(from);
|
|
41
47
|
return Number.isNaN(at) ? null : Math.max(0, Math.floor((now - at) / 86400000));
|
|
@@ -48,5 +54,6 @@ module.exports = {
|
|
|
48
54
|
toIsoInstant,
|
|
49
55
|
ageInYears,
|
|
50
56
|
isoDay,
|
|
57
|
+
mexicoDay,
|
|
51
58
|
daysSince
|
|
52
59
|
};
|