@peopl-health/nexus 5.71.25 → 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
|
};
|
|
@@ -14,6 +14,9 @@ const COMPOSE_AS_PREFIX = 'compose_as: ';
|
|
|
14
14
|
|
|
15
15
|
const ccText = (concept) => concept?.text || null;
|
|
16
16
|
const caseReason = (caseId) => [{ reference: reference('Condition', caseId) }];
|
|
17
|
+
// Older rows hold a flat Reference; R5 types finding.item as CodeableReference.
|
|
18
|
+
const findingItemReference = (item) =>
|
|
19
|
+
(typeof item?.reference === 'string' ? item.reference : item?.reference?.reference);
|
|
17
20
|
|
|
18
21
|
function dispositionBase(resourceType, disposition) {
|
|
19
22
|
return baseResource(resourceType, disposition.dispositionId, ROUTING_DISPOSITION_SLUG, disposition.patientId);
|
|
@@ -141,7 +144,7 @@ function assessmentResource(assessment, { decisionId, committedAt, disposition }
|
|
|
141
144
|
const entry = {};
|
|
142
145
|
const extensions = [];
|
|
143
146
|
if (finding.caseId) {
|
|
144
|
-
entry.item = reference('Condition', finding.caseId);
|
|
147
|
+
entry.item = { reference: reference('Condition', finding.caseId) };
|
|
145
148
|
extensions.push(extension(ROUTING_EXT.FINDING_CASE_ID, { valueString: finding.caseId }));
|
|
146
149
|
}
|
|
147
150
|
extensions.push(
|
|
@@ -244,7 +247,7 @@ function reconstructAssessment(resource, patientId, turnId) {
|
|
|
244
247
|
findings: (resource.finding || []).map((finding) => {
|
|
245
248
|
const findingExt = extMap(finding);
|
|
246
249
|
return {
|
|
247
|
-
caseId: referencedId(finding, ROUTING_EXT.FINDING_CASE_ID, finding.item
|
|
250
|
+
caseId: referencedId(finding, ROUTING_EXT.FINDING_CASE_ID, findingItemReference(finding.item)),
|
|
248
251
|
clinicalReasoning: findingExt[ROUTING_EXT.FINDING_REASONING] || '',
|
|
249
252
|
decisionAction: findingExt[ROUTING_EXT.FINDING_ACTION] || '',
|
|
250
253
|
};
|
|
@@ -261,12 +264,12 @@ function reconstructDisposition(resource, assessment, patientId) {
|
|
|
261
264
|
patientId,
|
|
262
265
|
kind,
|
|
263
266
|
primaryAction: codec.actionOf(resource),
|
|
264
|
-
primaryReason: codec.reasonOf(resource),
|
|
267
|
+
primaryReason: codec.reasonOf(resource) || '',
|
|
265
268
|
primaryCaseId: extMap(assessment)[ROUTING_EXT.PRIMARY_CASE_ID] || null,
|
|
266
269
|
secondaryActions: (resource.action || []).slice(1).map((action) => {
|
|
267
270
|
const description = action.description || '';
|
|
268
271
|
return {
|
|
269
|
-
action: action.title,
|
|
272
|
+
action: action.title || '',
|
|
270
273
|
composeAs: description.startsWith(COMPOSE_AS_PREFIX) ? description.slice(COMPOSE_AS_PREFIX.length) : description,
|
|
271
274
|
};
|
|
272
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) {
|