@peopl-health/nexus 5.13.0-dev.1164 → 5.13.0-dev.1167

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.
@@ -35,6 +35,7 @@ const ROUTING_EXT = {
35
35
  FINDING_CASE_ID: 'routing-finding-case-id',
36
36
  FINDING_REASONING: 'routing-finding-reasoning',
37
37
  FINDING_ACTION: 'routing-finding-action',
38
+ PREVIOUS_ID: 'routing-previous-id',
38
39
  };
39
40
 
40
41
  const CLUSTER_EXT = {
@@ -46,6 +47,7 @@ const CLUSTER_EXT = {
46
47
  STATUS: 'cluster-status',
47
48
  CONSULTATION_ID: 'cluster-consultation-id',
48
49
  DISSOLVE_REASON: 'cluster-dissolve-reason',
50
+ MEMBER_CASE_ID: 'cluster-member-case-id',
49
51
  };
50
52
 
51
53
  const PALLIATIVE_EXT = {
@@ -34,9 +34,20 @@ function extValues(resource, name) {
34
34
  return values;
35
35
  }
36
36
 
37
+ function referencedId(node, slug, reference) {
38
+ return extValues(node, slug)[0] || refToId(reference);
39
+ }
40
+
41
+ function referencedIds(node, slug, references) {
42
+ const values = extValues(node, slug);
43
+ return values.length ? values : references.map(refToId).filter(Boolean);
44
+ }
45
+
37
46
  module.exports = {
38
47
  extMap,
39
48
  identifierValue,
40
49
  refToId,
41
50
  extValues,
51
+ referencedId,
52
+ referencedIds,
42
53
  };
@@ -3,7 +3,7 @@ const { ZodError } = require('zod');
3
3
  const { codeSystemUrl } = require('../helpers/fhirHelper');
4
4
  const { identifier, reference, codeableConcept, extension, toIso } = require('../helpers/elementHelper');
5
5
  const { baseResource, provenance } = require('../helpers/resourceHelper');
6
- const { extMap, identifierValue, refToId } = require('../helpers/fhirReadHelper');
6
+ const { extMap, identifierValue, referencedIds } = require('../helpers/fhirReadHelper');
7
7
  const { CLUSTER_IMPRESSION_SLUG, CLUSTER_LABEL_SLUG } = require('../constants/projectionSlugs');
8
8
  const { CLUSTER_EXT } = require('../constants/extensionSlugs');
9
9
  const { ClusterImpression } = require('../../shared/dtos/ClusterImpression');
@@ -54,6 +54,7 @@ function clusterExtensions(cluster) {
54
54
  if (cluster.weakensIf.length) {
55
55
  out.push(extension(CLUSTER_EXT.WEAKENS_IF, { valueString: cluster.weakensIf.join(LIST_SEPARATOR) }));
56
56
  }
57
+ for (const caseId of cluster.memberCaseIds) out.push(extension(CLUSTER_EXT.MEMBER_CASE_ID, { valueString: caseId }));
57
58
  out.push(extension(CLUSTER_EXT.STATUS, { valueString: cluster.status }));
58
59
  if (cluster.consultationId) out.push(extension(CLUSTER_EXT.CONSULTATION_ID, { valueString: cluster.consultationId }));
59
60
  if (cluster.dissolveReason) out.push(extension(CLUSTER_EXT.DISSOLVE_REASON, { valueString: cluster.dissolveReason }));
@@ -104,7 +105,7 @@ function reconstruct(resource, patientId) {
104
105
  status: ext[CLUSTER_EXT.STATUS],
105
106
  confidence: ext[CLUSTER_EXT.CONFIDENCE],
106
107
  clinicalSignificance: ext[CLUSTER_EXT.CLINICAL_SIGNIFICANCE],
107
- memberCaseIds: (resource.problem || []).map((problemRef) => refToId(problemRef.reference)).filter(Boolean),
108
+ memberCaseIds: referencedIds(resource, CLUSTER_EXT.MEMBER_CASE_ID, (resource.problem || []).map((p) => p.reference)),
108
109
  consultationId: ext[CLUSTER_EXT.CONSULTATION_ID] || null,
109
110
  relationshipModel: resource.summary || '',
110
111
  strengthensIf: splitList(ext[CLUSTER_EXT.STRENGTHENS_IF]),
@@ -4,7 +4,7 @@ const { getOrganizationId } = require('../config/fhirConfig');
4
4
  const { fhirId } = require('../helpers/fhirHelper');
5
5
  const { patientReference, reference, codeableConcept, extension, toIso } = require('../helpers/elementHelper');
6
6
  const { baseResource, provenance } = require('../helpers/resourceHelper');
7
- const { extMap, identifierValue, refToId } = require('../helpers/fhirReadHelper');
7
+ const { extMap, identifierValue, referencedId } = require('../helpers/fhirReadHelper');
8
8
  const { CONTINGENCY_PLAN_SLUG, CONTINGENCY_STEP_SLUG } = require('../constants/projectionSlugs');
9
9
  const { ContingencySafetyNet } = require('../../shared/dtos/ContingencySafetyNet');
10
10
  const { logger } = require('../../utils/logger');
@@ -18,6 +18,8 @@ const EXT = {
18
18
  WHY_THIS_MATTERS: 'contingency-why-this-matters',
19
19
  CREATION_REASONING: 'contingency-creation-reasoning',
20
20
  RESOLVED_REASON: 'contingency-resolved-reason',
21
+ RELATED_CASE_ID: 'contingency-related-case-id',
22
+ RELATED_CLUSTER_ID: 'contingency-related-cluster-id',
21
23
  STEP_PRIORITY: 'contingency-step-priority',
22
24
  ACTION_REQUESTED: 'contingency-action-requested',
23
25
  FIRES_AFTER_SILENCE_MINUTES: 'fires-after-silence-minutes',
@@ -89,6 +91,8 @@ function carePlanPeriod(carePlan) {
89
91
 
90
92
  function carePlanExtensions(carePlan) {
91
93
  const out = [extension(EXT.STATUS, { valueString: carePlan.status })];
94
+ if (carePlan.relatedCaseId) out.push(extension(EXT.RELATED_CASE_ID, { valueString: carePlan.relatedCaseId }));
95
+ if (carePlan.relatedClusterId) out.push(extension(EXT.RELATED_CLUSTER_ID, { valueString: carePlan.relatedClusterId }));
92
96
  if (carePlan.awaitingCharacterization) out.push(extension(EXT.AWAITING_CHARACTERIZATION, { valueString: carePlan.awaitingCharacterization }));
93
97
  if (carePlan.whyThisMatters) out.push(extension(EXT.WHY_THIS_MATTERS, { valueString: carePlan.whyThisMatters }));
94
98
  if (carePlan.creationReasoning) out.push(extension(EXT.CREATION_REASONING, { valueString: carePlan.creationReasoning }));
@@ -148,8 +152,8 @@ function reconstruct(plan, requests, patientId) {
148
152
  carePlan: {
149
153
  planId,
150
154
  patientId,
151
- relatedCaseId: refToId(address && address.reference),
152
- relatedClusterId: refToId(plan.supportingInfo && plan.supportingInfo[0] && plan.supportingInfo[0].reference),
155
+ relatedCaseId: referencedId(plan, EXT.RELATED_CASE_ID, address?.reference),
156
+ relatedClusterId: referencedId(plan, EXT.RELATED_CLUSTER_ID, plan.supportingInfo?.[0]?.reference),
153
157
  concern: plan.description || '',
154
158
  awaitingCharacterization: ext[EXT.AWAITING_CHARACTERIZATION] || '',
155
159
  whyThisMatters: ext[EXT.WHY_THIS_MATTERS] || '',
@@ -4,7 +4,7 @@ const { getDeviceId } = require('../config/fhirConfig');
4
4
  const { fhirId, codeSystemUrl } = require('../helpers/fhirHelper');
5
5
  const { identifier, patientReference, reference, recipientReference, codeableConcept, extension, notes, toIso } = require('../helpers/elementHelper');
6
6
  const { baseResource, provenance } = require('../helpers/resourceHelper');
7
- const { identifierValue, refToId, extValues } = require('../helpers/fhirReadHelper');
7
+ const { identifierValue, refToId, extValues, referencedId } = require('../helpers/fhirReadHelper');
8
8
  const { INTERVENTION_SLUG, INTERVENTION_KIND_SLUG, INTERVENTION_OUTCOME_SLUG } = require('../constants/projectionSlugs');
9
9
  const { Intervention } = require('../../shared/dtos/Intervention');
10
10
  const { logger } = require('../../utils/logger');
@@ -13,6 +13,7 @@ const ACTIVITY_TEXT = 'intervention-record';
13
13
  const PROCEDURE_KINDS = new Set(['otc', 'self_care', 'other']);
14
14
 
15
15
  const EXT = {
16
+ CASE_ID: 'intervention-case-id',
16
17
  RATIONALE: 'intervention-rationale',
17
18
  OUTCOME_NOTES: 'intervention-outcome-notes',
18
19
  OUTCOME: 'intervention-outcome',
@@ -122,6 +123,7 @@ function communicationRequestResource(intervention) {
122
123
 
123
124
  function interventionExtensions(intervention, { withRecipient = false } = {}) {
124
125
  const out = [];
126
+ if (intervention.caseId) out.push(extension(EXT.CASE_ID, { valueString: intervention.caseId }));
125
127
  if (intervention.rationale) out.push(extension(EXT.RATIONALE, { valueString: intervention.rationale }));
126
128
  if (intervention.outcomeNotes) out.push(extension(EXT.OUTCOME_NOTES, { valueString: intervention.outcomeNotes }));
127
129
  if (intervention.outcome) out.push(extension(EXT.OUTCOME, { valueString: intervention.outcome }));
@@ -144,7 +146,7 @@ function reconstruct(resource, patientId) {
144
146
  const base = {
145
147
  interventionId: identifierValue(resource, INTERVENTION_SLUG),
146
148
  patientId,
147
- caseId: refToId(reasonRef && reasonRef.reference),
149
+ caseId: referencedId(resource, EXT.CASE_ID, reasonRef?.reference),
148
150
  rationale: extValues(resource, EXT.RATIONALE)[0] ?? null,
149
151
  outcomeNotes: extValues(resource, EXT.OUTCOME_NOTES)[0] ?? null,
150
152
  outcomeExt: extValues(resource, EXT.OUTCOME)[0] ?? null,
@@ -3,7 +3,7 @@ const { ZodError } = require('zod');
3
3
  const { getDeviceId } = require('../config/fhirConfig');
4
4
  const { reference, patientReference, codeableConcept, extension, toIso } = require('../helpers/elementHelper');
5
5
  const { baseResource, provenance } = require('../helpers/resourceHelper');
6
- const { extMap, extValues, identifierValue, refToId } = require('../helpers/fhirReadHelper');
6
+ const { extMap, extValues, identifierValue, refToId, referencedId } = require('../helpers/fhirReadHelper');
7
7
  const { ROUTING_ASSESSMENT_SLUG, ROUTING_DISPOSITION_SLUG } = require('../constants/projectionSlugs');
8
8
  const { ROUTING_EXT } = require('../constants/extensionSlugs');
9
9
  const { RoutingDecision } = require('../../shared/dtos/RoutingDecision');
@@ -171,6 +171,7 @@ function assessmentExtensions(assessment, { decisionId, committedAt, disposition
171
171
  if (disposition.primaryCaseId) {
172
172
  out.push(extension(ROUTING_EXT.PRIMARY_CASE_ID, { valueString: disposition.primaryCaseId }));
173
173
  }
174
+ if (assessment.previousId) out.push(extension(ROUTING_EXT.PREVIOUS_ID, { valueString: assessment.previousId }));
174
175
  for (const deferred of disposition.deferredItems) {
175
176
  out.push(
176
177
  extension(ROUTING_EXT.DEFERRED_ITEM, { valueString: deferred.item }),
@@ -240,13 +241,13 @@ function reconstructAssessment(resource, patientId, turnId) {
240
241
  patientId,
241
242
  turnId,
242
243
  performedAt: resource.effectiveDateTime,
243
- previousId: refToId(resource.previous?.reference),
244
+ previousId: referencedId(resource, ROUTING_EXT.PREVIOUS_ID, resource.previous?.reference),
244
245
  summary: resource.summary || '',
245
246
  notes: (resource.note || []).map((note) => note.text),
246
247
  findings: (resource.finding || []).map((finding) => {
247
248
  const findingExt = extMap(finding);
248
249
  return {
249
- caseId: findingExt[ROUTING_EXT.FINDING_CASE_ID] || refToId(finding.item?.reference),
250
+ caseId: referencedId(finding, ROUTING_EXT.FINDING_CASE_ID, finding.item?.reference),
250
251
  clinicalReasoning: findingExt[ROUTING_EXT.FINDING_REASONING] || '',
251
252
  decisionAction: findingExt[ROUTING_EXT.FINDING_ACTION] || '',
252
253
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.13.0-dev.1164",
3
+ "version": "5.13.0-dev.1167",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",