@peopl-health/nexus 5.71.27 → 5.71.28

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/fhir/index.js CHANGED
@@ -15,7 +15,7 @@ const {
15
15
  recordRecommendationReview,
16
16
  } = require('./services/recommendationService');
17
17
  const { storeContingency, readContingencies } = require('./services/contingencyService');
18
- const { readDispatchedEscalations, storeEscalationCase } = require('./services/escalationService');
18
+ const { readDispatchedEscalations, readEscalationCases, storeEscalationCase } = require('./services/escalationService');
19
19
  const { storeIntervention, readInterventions } = require('./services/interventionService');
20
20
  const { storeCluster, readClusters } = require('./services/clusterService');
21
21
  const { storeRoutingDecision, readRoutingDecisions } = require('./services/routingService');
@@ -71,6 +71,7 @@ module.exports = {
71
71
  readContingencies,
72
72
  readDispatchedEscalations,
73
73
  storeEscalationCase,
74
+ readEscalationCases,
74
75
  storeIntervention,
75
76
  readInterventions,
76
77
  storeCluster,
@@ -13,6 +13,7 @@ const {
13
13
  ESCALATION_CASE_SLUG,
14
14
  ESCALATION_CASE_STATUS_SLUG,
15
15
  ESCALATION_DECISION_SLUG,
16
+ SYMPTOM_CASE_SLUG,
16
17
  } = require('../constants/projectionSlugs');
17
18
  const { SEVERITY_TO_PRIORITY } = require('../constants/severityPriority');
18
19
  const { caseStatusOf } = require('../constants/escalationCaseStatus');
@@ -74,7 +75,12 @@ class Task {
74
75
  requester: reference('Device', deviceId),
75
76
  executionPeriod: { start: toIso(review.createdAt), ...(review.closedAt ? { end: toIso(review.closedAt) } : {}) },
76
77
  };
77
- if (conditionIds.length) payload.reason = conditionIds.map((id) => ({ reference: reference('Condition', id) }));
78
+ if (conditionIds.length) {
79
+ payload.reason = conditionIds.map((id) => {
80
+ const symptom = { ...reference('Condition', id), type: 'Condition', identifier: identifier(SYMPTOM_CASE_SLUG, id) };
81
+ return { reference: symptom };
82
+ });
83
+ }
78
84
  // Only a code reaches FHIR: the operator's cancellation note is free text.
79
85
  if (review.status === 'cancelled') {
80
86
  const reasonCode = String(review.cancellationReason ?? '').startsWith('no_requiere') ? 'no_requiere' : 'cancelado_por_equipo';
@@ -1,6 +1,7 @@
1
1
  const { getDeviceId } = require('../config/fhirConfig');
2
2
  const { fhirId } = require('../helpers/fhirHelper');
3
- const { ESCALATION_SLUG } = require('../constants/projectionSlugs');
3
+ const { identifierValue } = require('../helpers/fhirReadHelper');
4
+ const { ESCALATION_SLUG, ESCALATION_CASE_SLUG } = require('../constants/projectionSlugs');
4
5
  const { getFhirStore } = require('../stores/fhirStore');
5
6
  const { fromFhir } = require('../projections/dispatchedEscalationProjection');
6
7
  const { Task } = require('../resources/Task');
@@ -43,7 +44,42 @@ async function storeEscalationCase({ review, priority, conditionIds }) {
43
44
  return { ids: stored };
44
45
  }
45
46
 
47
+ const CLOSED_CASE_STATUSES = ['completed', 'cancelled'];
48
+
49
+ function caseFromTask(task) {
50
+ return {
51
+ reviewId: identifierValue(task, ESCALATION_CASE_SLUG),
52
+ status: task.status,
53
+ businessStatus: task.businessStatus?.coding?.[0]?.code ?? null,
54
+ label: task.businessStatus?.text ?? null,
55
+ isOpen: !CLOSED_CASE_STATUSES.includes(task.status),
56
+ priority: task.priority ?? null,
57
+ // Only references that carry the original symptom case id; a Task written before they did reads as none.
58
+ conditionIds: (task.reason ?? []).map((reason) => reason.reference?.identifier?.value).filter(Boolean),
59
+ decision: task.output?.find((output) => output.type?.text === 'decision')?.valueCodeableConcept?.coding?.[0]?.code ?? null,
60
+ statusReason: task.statusReason?.concept?.text ?? null,
61
+ openedAt: task.authoredOn ?? null,
62
+ lastModified: task.lastModified ?? null,
63
+ closedAt: task.executionPeriod?.end ?? null,
64
+ };
65
+ }
66
+
67
+ // A patient's escalation cases, newest first; `openOnly` keeps the ones whose Task is not completed or cancelled.
68
+ async function readEscalationCases({ patientId, openOnly = false }) {
69
+ if (typeof patientId !== 'string' || !patientId.trim()) {
70
+ throw new Error('readEscalationCases requires a non-empty patientId');
71
+ }
72
+ const found = await getFhirStore().find({
73
+ patient: `Patient/${fhirId(patientId)}`,
74
+ resourceType: 'Task',
75
+ identifierSlug: ESCALATION_CASE_SLUG,
76
+ });
77
+ const cases = found.map(caseFromTask);
78
+ return openOnly ? cases.filter((escalationCase) => escalationCase.isOpen) : cases;
79
+ }
80
+
46
81
  module.exports = {
47
82
  readDispatchedEscalations,
83
+ readEscalationCases,
48
84
  storeEscalationCase,
49
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.71.27",
3
+ "version": "5.71.28",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",