@peopl-health/nexus 5.71.26 → 5.71.27

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.
@@ -1,5 +1,7 @@
1
1
  const { fhirId, identifierSystem, extensionUrl } = require('./fhirHelper');
2
2
 
3
+ const EXTENSION_KEYS = new Set(['extension', 'modifierExtension']);
4
+
3
5
  function identifier(slug, value) {
4
6
  return { system: identifierSystem(slug), value };
5
7
  }
@@ -46,6 +48,25 @@ function toIso(value) {
46
48
  return `${s}Z`;
47
49
  }
48
50
 
51
+ // FHIR ele-1/ext-1: no element may be empty or null, and an extension needs a value or child extensions.
52
+ function pruneEmptyElements(resource) {
53
+ const prune = (value, parentKey) => {
54
+ if (value === null || value === undefined || value === '') return undefined;
55
+ if (Array.isArray(value)) {
56
+ const items = value.map((item) => prune(item, parentKey)).filter((item) => item !== undefined);
57
+ return items.length ? items : undefined;
58
+ }
59
+ if (typeof value !== 'object') return value;
60
+ const entries = Object.entries(value)
61
+ .map(([key, child]) => [key, prune(child, key)])
62
+ .filter(([, child]) => child !== undefined);
63
+ if (!entries.length) return undefined;
64
+ if (EXTENSION_KEYS.has(parentKey) && entries.every(([key]) => key === 'url')) return undefined;
65
+ return Object.fromEntries(entries);
66
+ };
67
+ return prune(resource, null) ?? {};
68
+ }
69
+
49
70
  module.exports = {
50
71
  identifier,
51
72
  reference,
@@ -56,4 +77,5 @@ module.exports = {
56
77
  notes,
57
78
  toInstant,
58
79
  toIso,
80
+ pruneEmptyElements,
59
81
  };
@@ -264,12 +264,12 @@ function reconstructDisposition(resource, assessment, patientId) {
264
264
  patientId,
265
265
  kind,
266
266
  primaryAction: codec.actionOf(resource),
267
- primaryReason: codec.reasonOf(resource),
267
+ primaryReason: codec.reasonOf(resource) || '',
268
268
  primaryCaseId: extMap(assessment)[ROUTING_EXT.PRIMARY_CASE_ID] || null,
269
269
  secondaryActions: (resource.action || []).slice(1).map((action) => {
270
270
  const description = action.description || '';
271
271
  return {
272
- action: action.title,
272
+ action: action.title || '',
273
273
  composeAs: description.startsWith(COMPOSE_AS_PREFIX) ? description.slice(COMPOSE_AS_PREFIX.length) : description,
274
274
  };
275
275
  }),
@@ -182,7 +182,7 @@ function reconstructDisease(prediction) {
182
182
  function reconstructComorbidity(prediction) {
183
183
  return {
184
184
  comorbidity: outcomeText(prediction),
185
- interaction: prediction.rationale,
185
+ interaction: prediction.rationale ?? '',
186
186
  clinicalNote: extValues(prediction, RISK_EXT.COMORBIDITY_CLINICAL_NOTE)[0] || null,
187
187
  };
188
188
  }
@@ -6,6 +6,7 @@ const { getCatalog } = require('../config/catalogConfig');
6
6
  const { envelopeSchema } = require('../models/envelopeModel');
7
7
  const { historySchema } = require('../models/historyModel');
8
8
 
9
+ const { pruneEmptyElements } = require('../helpers/elementHelper');
9
10
  const { identifierSystem } = require('../helpers/fhirHelper');
10
11
 
11
12
  const FHIR_VIEW = 'fhirResourceView';
@@ -131,7 +132,7 @@ class FhirStore {
131
132
  }
132
133
 
133
134
  _toStoredResource(resource) {
134
- return JSON.parse(JSON.stringify(resource));
135
+ return pruneEmptyElements(JSON.parse(JSON.stringify(resource)));
135
136
  }
136
137
 
137
138
  _entryFor(resourceType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.71.26",
3
+ "version": "5.71.27",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",