@peopl-health/nexus 5.71.28 → 5.71.29

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.
@@ -30,10 +30,16 @@ async function storeResources(resources, { store = null, merge = null } = {}) {
30
30
  return { stored };
31
31
  }
32
32
 
33
- // A plan rewrite reprojects its Tasks with no `output`, where the outcomes and verdicts live.
33
+ // A plan rewrite reprojects its Tasks as freshly `requested` with no `output`, where the outcomes and
34
+ // verdicts live; an outcome also moved the status, so both survive the rewrite.
34
35
  const keepTaskOutput = {
35
36
  merge: (prior, incoming) => (prior.resourceType === 'Task' && prior.output?.length
36
- ? { ...incoming, output: prior.output }
37
+ ? {
38
+ ...incoming,
39
+ output: prior.output,
40
+ status: prior.status || incoming.status,
41
+ ...(prior.lastModified ? { lastModified: prior.lastModified } : {}),
42
+ }
37
43
  : incoming),
38
44
  };
39
45
 
@@ -33,6 +33,10 @@ const { safetyGateExists } = require('./riskService');
33
33
  const { getCatalog } = require('./terminologyService');
34
34
 
35
35
  const OUTCOME_VALUES = ['improved', 'partial', 'no_relief', 'worsened', 'not_tried', 'unknown'];
36
+ // The patient tried it: the recommendation is done. not_tried / unknown leave it open. With no outcome (every
37
+ // triage record, and adherence-only chat records), adherence full/partial ("la siguió", "en parte") means it was tried.
38
+ const TRIED_OUTCOMES = new Set(['improved', 'partial', 'no_relief', 'worsened']);
39
+ const TRIED_ADHERENCE = new Set(['full', 'partial']);
36
40
  const ADHERENCE_VALUES = ['full', 'partial', 'none'];
37
41
  const CHAT_ACTIVE_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
38
42
  const SOURCE_VALUES = ['chat', 'triage'];
@@ -162,12 +166,22 @@ async function recordRecommendationOutcome({
162
166
  }
163
167
  const target = await resolveTask({ patientId, recommendationId, ctcaeTerm });
164
168
  if (!target) return { recorded: false };
165
- const output = outcomeEntry({ outcome: resolvedOutcome, adherence, notes, source, recordedAt: toIso(new Date()), eventKey });
169
+ const recordedAt = toIso(new Date());
170
+ const output = outcomeEntry({ outcome: resolvedOutcome, adherence, notes, source, recordedAt, eventKey });
166
171
  let duplicate = false;
167
172
  await storeResources([target.task], {
168
- merge: (prior, incoming) => {
173
+ merge: (prior) => {
169
174
  duplicate = Boolean(eventKey) && hasOutcomeEvent(prior, eventKey);
170
- return { ...incoming, output: duplicate ? prior.output : [...(prior.output || []), output] };
175
+ if (duplicate) return prior;
176
+ const done = prior.status === 'completed'
177
+ || TRIED_OUTCOMES.has(resolvedOutcome)
178
+ || (!outcome && TRIED_ADHERENCE.has(adherence));
179
+ return {
180
+ ...prior,
181
+ status: done ? 'completed' : 'in-progress',
182
+ lastModified: recordedAt,
183
+ output: [...(prior.output || []), output],
184
+ };
171
185
  },
172
186
  });
173
187
  return {
@@ -224,13 +238,13 @@ async function recordRecommendationReview({
224
238
  let duplicate = false;
225
239
  let retained = null;
226
240
  const write = await storeResources([target.task], {
227
- merge: (prior, incoming) => {
241
+ merge: (prior) => {
228
242
  duplicate = Boolean(key) && hasReviewEvent(prior, key);
229
243
  if (duplicate) {
230
244
  retained = reviewByEvent(prior, key);
231
- return { ...incoming, output: prior.output };
245
+ return prior;
232
246
  }
233
- return { ...incoming, output: [...(prior.output || []), output] };
247
+ return { ...prior, output: [...(prior.output || []), output] };
234
248
  },
235
249
  });
236
250
  if (write.skipped) return { recorded: false, skipped: write.skipped, recommendation_id: target.recommendationId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.71.28",
3
+ "version": "5.71.29",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",