gdc-common-utils-ts 2.1.0 → 2.2.2
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/README.md +18 -0
- package/dist/claims/claims-helpers-allergy-intolerance.d.ts +8 -0
- package/dist/claims/claims-helpers-allergy-intolerance.js +30 -12
- package/dist/claims/claims-helpers-condition.d.ts +8 -0
- package/dist/claims/claims-helpers-condition.js +30 -12
- package/dist/claims/claims-helpers-consent.d.ts +4 -0
- package/dist/claims/claims-helpers-consent.js +15 -1
- package/dist/claims/claims-helpers-diagnostic-report.d.ts +4 -0
- package/dist/claims/claims-helpers-diagnostic-report.js +17 -2
- package/dist/claims/claims-helpers-medication-statement.d.ts +10 -2
- package/dist/claims/claims-helpers-medication-statement.js +32 -14
- package/dist/constants/didcomm.d.ts +22 -0
- package/dist/constants/didcomm.js +22 -0
- package/dist/constants/fhir-resource-types.d.ts +2 -0
- package/dist/constants/fhir-resource-types.js +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/lifecycle.d.ts +2 -0
- package/dist/constants/lifecycle.js +2 -0
- package/dist/constants/verifiable-credentials.d.ts +9 -0
- package/dist/constants/verifiable-credentials.js +9 -0
- package/dist/examples/bundle-didcomm-payload.js +4 -2
- package/dist/examples/communication-attached-bundle-session.js +27 -27
- package/dist/examples/communication-didcomm-payload.d.ts +8 -4
- package/dist/examples/communication-didcomm-payload.js +17 -11
- package/dist/examples/consent-access.js +2 -1
- package/dist/examples/employee.d.ts +21 -0
- package/dist/examples/employee.js +21 -0
- package/dist/examples/individual-controller.d.ts +27 -0
- package/dist/examples/individual-controller.js +28 -1
- package/dist/examples/inter-tenant-access-contract.js +3 -2
- package/dist/examples/ips-bundle.js +17 -16
- package/dist/examples/lifecycle.js +13 -11
- package/dist/examples/profile-manager-mem.js +2 -1
- package/dist/examples/related-person.d.ts +14 -0
- package/dist/examples/related-person.js +18 -4
- package/dist/examples/shared.d.ts +12 -3
- package/dist/examples/shared.js +13 -4
- package/dist/examples/vital-signs.js +1 -1
- package/dist/examples/wallet-mem.js +4 -2
- package/dist/models/authority-resolution.d.ts +56 -0
- package/dist/models/authority-resolution.js +2 -0
- package/dist/models/bundle-editor-types.d.ts +89 -0
- package/dist/models/bundle-editor-types.js +45 -0
- package/dist/models/bundle.d.ts +5 -0
- package/dist/models/communication-attached-bundle-session.d.ts +6 -4
- package/dist/models/communication-attached-bundle-session.js +6 -4
- package/dist/models/confidential-storage.d.ts +2 -1
- package/dist/models/consent-rule.d.ts +11 -1
- package/dist/models/consent-rule.js +9 -1
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +2 -0
- package/dist/models/individual-onboarding.d.ts +18 -0
- package/dist/models/interoperable-claims/allergy-intolerance-claims.d.ts +12 -1
- package/dist/models/interoperable-claims/allergy-intolerance-claims.js +12 -1
- package/dist/models/interoperable-claims/condition-claims.d.ts +12 -1
- package/dist/models/interoperable-claims/condition-claims.js +12 -1
- package/dist/models/interoperable-claims/diagnostic-report-claims.d.ts +13 -2
- package/dist/models/interoperable-claims/diagnostic-report-claims.js +12 -1
- package/dist/models/interoperable-claims/document-reference-claims.d.ts +1 -0
- package/dist/models/interoperable-claims/document-reference-claims.js +3 -0
- package/dist/models/interoperable-claims/medication-statement-claims.d.ts +17 -0
- package/dist/models/interoperable-claims/medication-statement-claims.js +17 -0
- package/dist/utils/allergy-intolerance-entry-editor.d.ts +51 -0
- package/dist/utils/allergy-intolerance-entry-editor.js +55 -0
- package/dist/utils/authority-resolution.d.ts +37 -0
- package/dist/utils/authority-resolution.js +112 -0
- package/dist/utils/backend-message-manager-mem.d.ts +11 -0
- package/dist/utils/backend-message-manager-mem.js +11 -0
- package/dist/utils/bundle-didcomm-payload.js +3 -2
- package/dist/utils/bundle-document-builder.d.ts +1 -0
- package/dist/utils/bundle-document-builder.js +134 -14
- package/dist/utils/bundle-editor-core.d.ts +181 -0
- package/dist/utils/bundle-editor-core.js +467 -0
- package/dist/utils/bundle-editor-helpers.d.ts +53 -0
- package/dist/utils/bundle-editor-helpers.js +146 -0
- package/dist/utils/bundle-editor-registry.d.ts +6 -0
- package/dist/utils/bundle-editor-registry.js +14 -0
- package/dist/utils/bundle-editor.d.ts +21 -722
- package/dist/utils/bundle-editor.js +21 -1601
- package/dist/utils/bundle-entry-editor.d.ts +96 -0
- package/dist/utils/bundle-entry-editor.js +305 -0
- package/dist/utils/bundle-query.d.ts +1 -0
- package/dist/utils/bundle-query.js +12 -3
- package/dist/utils/bundle-reader.d.ts +48 -0
- package/dist/utils/bundle-reader.js +175 -1
- package/dist/utils/care-plan-entry-editor.d.ts +43 -0
- package/dist/utils/care-plan-entry-editor.js +47 -0
- package/dist/utils/client-assertion.d.ts +38 -0
- package/dist/utils/client-assertion.js +113 -0
- package/dist/utils/clinical-impression-entry-editor.d.ts +43 -0
- package/dist/utils/clinical-impression-entry-editor.js +47 -0
- package/dist/utils/clinical-resource-entry-editor.d.ts +123 -0
- package/dist/utils/clinical-resource-entry-editor.js +296 -0
- package/dist/utils/communication-attached-bundle-session-helpers.js +8 -6
- package/dist/utils/communication-attached-bundle-session.d.ts +29 -3
- package/dist/utils/communication-attached-bundle-session.js +62 -3
- package/dist/utils/communication-didcomm-payload.d.ts +5 -0
- package/dist/utils/communication-didcomm-payload.js +28 -18
- package/dist/utils/communication-document-reference.d.ts +23 -0
- package/dist/utils/communication-document-reference.js +89 -0
- package/dist/utils/communication-editor.d.ts +53 -0
- package/dist/utils/communication-editor.js +97 -0
- package/dist/utils/condition-entry-editor.d.ts +30 -0
- package/dist/utils/condition-entry-editor.js +34 -0
- package/dist/utils/consent-claim-helpers.d.ts +4 -0
- package/dist/utils/consent-claim-helpers.js +15 -1
- package/dist/utils/coverage-entry-editor.d.ts +51 -0
- package/dist/utils/coverage-entry-editor.js +55 -0
- package/dist/utils/device-entry-editor.d.ts +59 -0
- package/dist/utils/device-entry-editor.js +63 -0
- package/dist/utils/device-use-statement-entry-editor.d.ts +43 -0
- package/dist/utils/device-use-statement-entry-editor.js +47 -0
- package/dist/utils/diagnostic-report-entry-editor.d.ts +74 -0
- package/dist/utils/diagnostic-report-entry-editor.js +136 -0
- package/dist/utils/did.d.ts +8 -0
- package/dist/utils/did.js +22 -0
- package/dist/utils/document-reference-entry-editor.d.ts +62 -0
- package/dist/utils/document-reference-entry-editor.js +66 -0
- package/dist/utils/employee-entry-editor.d.ts +36 -0
- package/dist/utils/employee-entry-editor.js +88 -0
- package/dist/utils/employee.d.ts +1 -0
- package/dist/utils/employee.js +2 -1
- package/dist/utils/encounter-entry-editor.d.ts +51 -0
- package/dist/utils/encounter-entry-editor.js +55 -0
- package/dist/utils/flag-entry-editor.d.ts +47 -0
- package/dist/utils/flag-entry-editor.js +51 -0
- package/dist/utils/immunization-entry-editor.d.ts +87 -0
- package/dist/utils/immunization-entry-editor.js +169 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/individual-onboarding-acceptance-credential.d.ts +35 -0
- package/dist/utils/individual-onboarding-acceptance-credential.js +55 -0
- package/dist/utils/individual-smart.d.ts +59 -0
- package/dist/utils/individual-smart.js +135 -0
- package/dist/utils/medication-statement-entry-editor.d.ts +90 -0
- package/dist/utils/medication-statement-entry-editor.js +94 -0
- package/dist/utils/observation-component-entry-editor.d.ts +57 -0
- package/dist/utils/observation-component-entry-editor.js +105 -0
- package/dist/utils/observation-entry-editor.d.ts +29 -0
- package/dist/utils/observation-entry-editor.js +68 -0
- package/dist/utils/procedure-entry-editor.d.ts +71 -0
- package/dist/utils/procedure-entry-editor.js +75 -0
- package/dist/utils/professional-smart.d.ts +87 -0
- package/dist/utils/professional-smart.js +118 -4
- package/dist/utils/same-as.d.ts +40 -0
- package/dist/utils/same-as.js +72 -0
- package/dist/utils/unified-health-id.d.ts +51 -0
- package/dist/utils/unified-health-id.js +92 -0
- package/dist/utils/vital-sign-day-batch.d.ts +25 -0
- package/dist/utils/vital-sign-day-batch.js +115 -0
- package/dist/utils/vital-sign-entry-editor.d.ts +61 -0
- package/dist/utils/vital-sign-entry-editor.js +152 -0
- package/package.json +2 -1
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { ResourceTypesFhirR4 } from '../constants/fhir-resource-types.js';
|
|
2
|
+
import { AllergyIntoleranceClaim } from '../models/interoperable-claims/allergy-intolerance-claims.js';
|
|
3
|
+
import { CompositionClaim } from '../models/interoperable-claims/composition-claims.js';
|
|
4
|
+
import { ConditionClaim } from '../models/interoperable-claims/condition-claims.js';
|
|
5
|
+
import { DiagnosticReportClaim } from '../models/interoperable-claims/diagnostic-report-claims.js';
|
|
6
|
+
import { MedicationStatementClaim } from '../models/interoperable-claims/medication-statement-claims.js';
|
|
7
|
+
import { ClaimConsent } from '../models/consent-rule.js';
|
|
2
8
|
import { allergyIntoleranceFlatToFhirR4, appointmentFlatToFhirR4, carePlanFlatToFhirR4, clinicalImpressionFlatToFhirR4, compositionFlatToFhirR4, conditionFlatToFhirR4, convertFhirResourceToClaims, coverageFlatToFhirR4, deviceFlatToFhirR4, documentReferenceFlatToFhirR4, diagnosticReportFlatToFhirR4, encounterFlatToFhirR4, flagFlatToFhirR4, flatClaimsToFhirResource, immunizationFlatToFhirR4, locationFlatToFhirR4, medicationStatementFlatToFhirR4, observationFromFlatToFhirR4, organizationFlatToFhirR4, procedureFlatToFhirR4, relatedPersonFlatToFhirR4, } from './clinical-resource-converters.js';
|
|
3
9
|
function asTrimmedString(value) {
|
|
4
10
|
if (value === undefined || value === null)
|
|
@@ -93,6 +99,43 @@ function normalizeSectionCode(value) {
|
|
|
93
99
|
return { code: system };
|
|
94
100
|
return { system, code };
|
|
95
101
|
}
|
|
102
|
+
function resolveContainedReferenceListClaimKey(resourceType) {
|
|
103
|
+
switch (resourceType) {
|
|
104
|
+
case ResourceTypesFhirR4.MedicationStatement:
|
|
105
|
+
return MedicationStatementClaim.ContainedReferenceList;
|
|
106
|
+
case ResourceTypesFhirR4.AllergyIntolerance:
|
|
107
|
+
return AllergyIntoleranceClaim.ContainedReferenceList;
|
|
108
|
+
case ResourceTypesFhirR4.Condition:
|
|
109
|
+
return ConditionClaim.ContainedReferenceList;
|
|
110
|
+
case ResourceTypesFhirR4.DiagnosticReport:
|
|
111
|
+
return DiagnosticReportClaim.ContainedReferenceList;
|
|
112
|
+
case ResourceTypesFhirR4.Consent:
|
|
113
|
+
return ClaimConsent.containedReferenceList;
|
|
114
|
+
default:
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function resolveContainedFlagClaimKey(resourceType) {
|
|
119
|
+
const normalized = asTrimmedString(resourceType);
|
|
120
|
+
return normalized ? `${normalized}.is-contained` : undefined;
|
|
121
|
+
}
|
|
122
|
+
function resolveContainedParentReferenceClaimKey(resourceType) {
|
|
123
|
+
const normalized = asTrimmedString(resourceType);
|
|
124
|
+
return normalized ? `${normalized}.contained-parent-reference` : undefined;
|
|
125
|
+
}
|
|
126
|
+
function mergeContainedResourceReferenceList(claims, references) {
|
|
127
|
+
const resourceType = detectClaimsResourceType(claims);
|
|
128
|
+
const claimKey = resourceType ? resolveContainedReferenceListClaimKey(resourceType) : undefined;
|
|
129
|
+
if (!claimKey || references.length === 0) {
|
|
130
|
+
return claims;
|
|
131
|
+
}
|
|
132
|
+
const current = splitCsv(claims[claimKey]);
|
|
133
|
+
const next = Array.from(new Set([...current, ...references].map((item) => asTrimmedString(item)).filter(Boolean)));
|
|
134
|
+
return {
|
|
135
|
+
...claims,
|
|
136
|
+
[claimKey]: next.join(','),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
96
139
|
export function detectClaimsResourceType(claims) {
|
|
97
140
|
const keys = Object.keys(claims || {});
|
|
98
141
|
if (keys.some((key) => key.startsWith('MedicationStatement.')))
|
|
@@ -181,12 +224,47 @@ export function extractBundleDocumentClaimsList(bundle, context = 'org.hl7.fhir.
|
|
|
181
224
|
.map((entry) => entry?.resource)
|
|
182
225
|
.filter((resource) => resource && typeof resource === 'object')
|
|
183
226
|
.filter((resource) => !ignoredResourceTypes.has(String(resource.resourceType || '')))
|
|
184
|
-
.
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
227
|
+
.flatMap((resource) => {
|
|
228
|
+
const resourceRecord = resource;
|
|
229
|
+
const resourceReference = `${asTrimmedString(resourceRecord.resourceType)}/${asTrimmedString(resourceRecord.id)}`;
|
|
230
|
+
const metaClaims = resourceRecord?.meta?.claims;
|
|
231
|
+
const baseClaims = metaClaims && typeof metaClaims === 'object' && !Array.isArray(metaClaims)
|
|
232
|
+
? ensureClaimsIdentifier({ ...metaClaims }, resourceRecord)
|
|
233
|
+
: ensureClaimsIdentifier(convertFhirResourceToClaims(resourceRecord, context), resourceRecord);
|
|
234
|
+
const containedResources = Array.isArray(resourceRecord.contained)
|
|
235
|
+
? resourceRecord.contained
|
|
236
|
+
: [];
|
|
237
|
+
const containedClaimsList = containedResources.map((containedResource, index) => {
|
|
238
|
+
const containedMetaClaims = (containedResource?.meta?.claims);
|
|
239
|
+
const containedClaims = containedMetaClaims && typeof containedMetaClaims === 'object' && !Array.isArray(containedMetaClaims)
|
|
240
|
+
? ensureClaimsIdentifier({ ...containedMetaClaims }, containedResource)
|
|
241
|
+
: ensureClaimsIdentifier(convertFhirResourceToClaims(containedResource, context), containedResource);
|
|
242
|
+
const containedResourceType = asTrimmedString(containedResource.resourceType);
|
|
243
|
+
const containedFlagClaimKey = resolveContainedFlagClaimKey(containedResourceType);
|
|
244
|
+
const containedParentReferenceClaimKey = resolveContainedParentReferenceClaimKey(containedResourceType);
|
|
245
|
+
return {
|
|
246
|
+
...containedClaims,
|
|
247
|
+
...(containedFlagClaimKey ? { [containedFlagClaimKey]: true } : {}),
|
|
248
|
+
...(containedParentReferenceClaimKey ? { [containedParentReferenceClaimKey]: resourceReference } : {}),
|
|
249
|
+
...(asTrimmedString(containedResource.id) ? {} : {
|
|
250
|
+
[`${containedResource.resourceType}.identifier`]: `${resourceReference}#contained-${index + 1}`,
|
|
251
|
+
}),
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
const containedReferences = containedResources
|
|
255
|
+
.map((containedResource, index) => {
|
|
256
|
+
const containedType = asTrimmedString(containedResource.resourceType);
|
|
257
|
+
const containedId = asTrimmedString(containedResource.id) || `${resourceReference}#contained-${index + 1}`;
|
|
258
|
+
if (!containedType || !containedId) {
|
|
259
|
+
return '';
|
|
260
|
+
}
|
|
261
|
+
return `${containedType}/${containedId}`;
|
|
262
|
+
})
|
|
263
|
+
.filter(Boolean);
|
|
264
|
+
return [
|
|
265
|
+
mergeContainedResourceReferenceList(baseClaims, containedReferences),
|
|
266
|
+
...containedClaimsList,
|
|
267
|
+
];
|
|
190
268
|
});
|
|
191
269
|
}
|
|
192
270
|
export function resolveClaimsSectionList(claims) {
|
|
@@ -202,9 +280,17 @@ export function resolveClaimsSectionList(claims) {
|
|
|
202
280
|
return Array.from(new Set(values));
|
|
203
281
|
}
|
|
204
282
|
export function buildBundleDocumentFromClaims(input) {
|
|
205
|
-
const
|
|
283
|
+
const compositionClaims = { ...(input.compositionClaims || {}) };
|
|
284
|
+
const compositionType = asTrimmedString(input.compositionType || compositionClaims[CompositionClaim.Type]) || 'http://loinc.org|60591-5';
|
|
285
|
+
const compositionSubject = asTrimmedString(input.subjectDid || compositionClaims[CompositionClaim.Subject]);
|
|
286
|
+
const compositionIdentifier = asTrimmedString(compositionClaims[CompositionClaim.Identifier]);
|
|
287
|
+
const compositionTitle = asTrimmedString(compositionClaims[CompositionClaim.Title]);
|
|
288
|
+
const compositionDate = asTrimmedString(compositionClaims[CompositionClaim.Date]);
|
|
289
|
+
const compositionAuthorList = splitCsv(compositionClaims[CompositionClaim.Author]);
|
|
206
290
|
const compositionSections = new Map();
|
|
207
|
-
const
|
|
291
|
+
const visibleEntries = [];
|
|
292
|
+
const resourceByReference = new Map();
|
|
293
|
+
const containedChildrenByParentReference = new Map();
|
|
208
294
|
input.claimsList.forEach((claims, index) => {
|
|
209
295
|
const resource = convertClaimsToFhirResource(claims);
|
|
210
296
|
resource.meta = {
|
|
@@ -212,8 +298,23 @@ export function buildBundleDocumentFromClaims(input) {
|
|
|
212
298
|
claims: { ...claims },
|
|
213
299
|
};
|
|
214
300
|
ensureResourceIdentifier(resource, claims, index);
|
|
215
|
-
|
|
216
|
-
const
|
|
301
|
+
const resourceReference = `${resource.resourceType}/${asTrimmedString(resource.id)}`;
|
|
302
|
+
const containedFlagClaimKey = resolveContainedFlagClaimKey(resource.resourceType);
|
|
303
|
+
const containedParentReferenceClaimKey = resolveContainedParentReferenceClaimKey(resource.resourceType);
|
|
304
|
+
const isContained = containedFlagClaimKey
|
|
305
|
+
? (claims[containedFlagClaimKey] === true || claims[containedFlagClaimKey] === 'true')
|
|
306
|
+
: false;
|
|
307
|
+
const containedParentReference = containedParentReferenceClaimKey
|
|
308
|
+
? asTrimmedString(claims[containedParentReferenceClaimKey])
|
|
309
|
+
: '';
|
|
310
|
+
if (isContained && containedParentReference) {
|
|
311
|
+
const currentChildren = containedChildrenByParentReference.get(containedParentReference) || [];
|
|
312
|
+
containedChildrenByParentReference.set(containedParentReference, [...currentChildren, resource]);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
visibleEntries.push({ resource });
|
|
316
|
+
resourceByReference.set(resourceReference, resource);
|
|
317
|
+
const resourceRef = resourceReference;
|
|
217
318
|
resolveClaimsSectionList(claims).forEach((sectionValue) => {
|
|
218
319
|
const normalizedSection = asTrimmedString(sectionValue);
|
|
219
320
|
if (!normalizedSection)
|
|
@@ -230,6 +331,13 @@ export function buildBundleDocumentFromClaims(input) {
|
|
|
230
331
|
compositionSections.set(normalizedSection, section);
|
|
231
332
|
});
|
|
232
333
|
});
|
|
334
|
+
containedChildrenByParentReference.forEach((children, parentReference) => {
|
|
335
|
+
const parent = resourceByReference.get(parentReference);
|
|
336
|
+
if (!parent) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
parent.contained = [...(Array.isArray(parent.contained) ? parent.contained : []), ...children];
|
|
340
|
+
});
|
|
233
341
|
const [compositionSystem, compositionCode] = compositionType.split('|');
|
|
234
342
|
return {
|
|
235
343
|
resourceType: ResourceTypesFhirR4.Bundle,
|
|
@@ -238,8 +346,14 @@ export function buildBundleDocumentFromClaims(input) {
|
|
|
238
346
|
{
|
|
239
347
|
resource: {
|
|
240
348
|
resourceType: ResourceTypesFhirR4.Composition,
|
|
349
|
+
...(compositionIdentifier ? { id: compositionIdentifier } : {}),
|
|
241
350
|
status: 'final',
|
|
242
|
-
|
|
351
|
+
...(compositionIdentifier ? {
|
|
352
|
+
identifier: [{ value: compositionIdentifier }],
|
|
353
|
+
} : {}),
|
|
354
|
+
...(compositionSubject ? {
|
|
355
|
+
subject: { reference: compositionSubject },
|
|
356
|
+
} : {}),
|
|
243
357
|
type: {
|
|
244
358
|
coding: [
|
|
245
359
|
compositionCode
|
|
@@ -247,18 +361,24 @@ export function buildBundleDocumentFromClaims(input) {
|
|
|
247
361
|
: { code: compositionSystem },
|
|
248
362
|
],
|
|
249
363
|
},
|
|
364
|
+
...(compositionTitle ? { title: compositionTitle } : {}),
|
|
365
|
+
...(compositionDate ? { date: compositionDate } : {}),
|
|
366
|
+
...(compositionAuthorList.length > 0 ? {
|
|
367
|
+
author: compositionAuthorList.map((reference) => ({ reference })),
|
|
368
|
+
} : {}),
|
|
369
|
+
meta: { claims: compositionClaims },
|
|
250
370
|
section: Array.from(compositionSections.values()),
|
|
251
371
|
},
|
|
252
372
|
},
|
|
253
|
-
...(
|
|
373
|
+
...(compositionSubject
|
|
254
374
|
? [{
|
|
255
375
|
resource: {
|
|
256
376
|
resourceType: 'Patient',
|
|
257
|
-
id:
|
|
377
|
+
id: compositionSubject,
|
|
258
378
|
},
|
|
259
379
|
}]
|
|
260
380
|
: []),
|
|
261
|
-
...
|
|
381
|
+
...visibleEntries,
|
|
262
382
|
],
|
|
263
383
|
};
|
|
264
384
|
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { BundleEntry, BundleJsonApi } from '../models/bundle';
|
|
2
|
+
import { AllowedResourceType, BundleType, type BuiltBundleEntry, type BundleOperation, type ResourceTypeEntryEditor } from '../models/bundle-editor-types';
|
|
3
|
+
import { type ValidateBundleDocumentResult } from './bundle-document-builder';
|
|
4
|
+
import { buildEmployeePurgeBundle, buildEmployeeSearchBundle } from './employee';
|
|
5
|
+
import { BundleEntryEditor } from './bundle-entry-editor';
|
|
6
|
+
export declare class BundleEditor {
|
|
7
|
+
private bundleOperation;
|
|
8
|
+
private allowedResourceType;
|
|
9
|
+
private bundleType;
|
|
10
|
+
private compositionClaims;
|
|
11
|
+
private readonly entries;
|
|
12
|
+
/**
|
|
13
|
+
* Declares which business action this in-memory bundle is staging.
|
|
14
|
+
*
|
|
15
|
+
* Important distinction:
|
|
16
|
+
* - this is **not** the same concept as FHIR `Bundle.entry.request.method`
|
|
17
|
+
* - this is the higher-level action the editor is helping to assemble, for
|
|
18
|
+
* example `create`, `search`, `disable`, or `purge`
|
|
19
|
+
* - the lower-level transport/request method may later be derived from that
|
|
20
|
+
* action, and may differ by backend contract
|
|
21
|
+
*
|
|
22
|
+
* Example:
|
|
23
|
+
* - bundle operation `disable`
|
|
24
|
+
* - current employee GW contract -> inner `entry.request.method = DELETE`
|
|
25
|
+
* - current individual organization GW contract -> explicit `/_disable`
|
|
26
|
+
* route with inner `entry.request.method = POST`
|
|
27
|
+
*/
|
|
28
|
+
setBundleOperation(operation: BundleOperation): this;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the current high-level business action assigned to the bundle.
|
|
31
|
+
*
|
|
32
|
+
* Read this as:
|
|
33
|
+
* - "what am I trying to do?"
|
|
34
|
+
*
|
|
35
|
+
* not as:
|
|
36
|
+
* - "which HTTP/FHIR request method will the final entry use?"
|
|
37
|
+
*/
|
|
38
|
+
getBundleOperation(): BundleOperation | null;
|
|
39
|
+
/**
|
|
40
|
+
* Restricts the bundle to one resource type.
|
|
41
|
+
*
|
|
42
|
+
* For employee batch bundles this should be fixed to
|
|
43
|
+
* `EmployeeResourceTypes.employee` so the editor cannot mix unrelated
|
|
44
|
+
* resource kinds.
|
|
45
|
+
*/
|
|
46
|
+
setAllowedResourceType(resourceType: AllowedResourceType): this;
|
|
47
|
+
/** Returns the bundle resource type restriction when already declared. */
|
|
48
|
+
getAllowedResourceType(): AllowedResourceType | null;
|
|
49
|
+
/** Declares which FHIR bundle shape the editor should materialize. */
|
|
50
|
+
setBundleType(type: BundleType): this;
|
|
51
|
+
/** Returns the declared target bundle shape. */
|
|
52
|
+
getBundleType(): BundleType;
|
|
53
|
+
setCompositionIdentifier(identifier?: string | null): this;
|
|
54
|
+
/** Returns the normalized `Composition.identifier` staged for the future document root. */
|
|
55
|
+
getCompositionIdentifier(): string | undefined;
|
|
56
|
+
setCompositionSubject(subject?: string | null): this;
|
|
57
|
+
/** Returns the normalized `Composition.subject` staged for the future document root. */
|
|
58
|
+
getCompositionSubject(): string | undefined;
|
|
59
|
+
setCompositionType(type?: string | null): this;
|
|
60
|
+
/** Returns the normalized `Composition.type` staged for the future document root. */
|
|
61
|
+
getCompositionType(): string | undefined;
|
|
62
|
+
setCompositionTitle(title?: string | null): this;
|
|
63
|
+
/** Returns the normalized `Composition.title` staged for the future document root. */
|
|
64
|
+
getCompositionTitle(): string | undefined;
|
|
65
|
+
setCompositionDate(date?: string | null): this;
|
|
66
|
+
/** Returns the normalized `Composition.date` staged for the future document root. */
|
|
67
|
+
getCompositionDate(): string | undefined;
|
|
68
|
+
setCompositionAuthorList(references: readonly string[]): this;
|
|
69
|
+
/** Returns the normalized `Composition.author` reference list staged for the future document root. */
|
|
70
|
+
getCompositionAuthorList(): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Opens one new entry and returns a generic entry editor for that slot.
|
|
73
|
+
*
|
|
74
|
+
* The entry editor can later expose resource-specific semantics through
|
|
75
|
+
* methods such as `asEmployee()`.
|
|
76
|
+
*/
|
|
77
|
+
newEntry(resourceId?: string, resourceTypeOverride?: AllowedResourceType): BundleEntryEditor;
|
|
78
|
+
/** Opens one new entry with an explicit resource type, mainly for document bundles. */
|
|
79
|
+
newEntryAs<T extends AllowedResourceType>(resourceType: T, resourceId?: string): ResourceTypeEntryEditor<T>;
|
|
80
|
+
/** Reopens one existing entry by `resource.id` or `fullUrl`. */
|
|
81
|
+
openEntry(resourceIdOrFullUrl: string): BundleEntryEditor;
|
|
82
|
+
/** Returns cloned staged entries for inspection or debugging. */
|
|
83
|
+
getEntries(): readonly BuiltBundleEntry[];
|
|
84
|
+
/** Returns the current Composition-level claims used when building a document bundle. */
|
|
85
|
+
getCompositionClaims(): Readonly<Record<string, unknown>>;
|
|
86
|
+
/**
|
|
87
|
+
* Validates whether the current editor state is sufficient to build one
|
|
88
|
+
* clinical `Bundle.type=document`.
|
|
89
|
+
*/
|
|
90
|
+
validateDocumentAuthoring(): ValidateBundleDocumentResult;
|
|
91
|
+
/** Builds one Composition-first document bundle from the staged resource entries. */
|
|
92
|
+
buildDocument(): Record<string, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Materializes the final bundle payload from the editor state.
|
|
95
|
+
*
|
|
96
|
+
* `build()` does not send, sign, or wrap the payload. It only returns the
|
|
97
|
+
* final bundle object for the declared operation and staged entries.
|
|
98
|
+
*/
|
|
99
|
+
build(): ReturnType<typeof buildEmployeePurgeBundle> | ReturnType<typeof buildEmployeeSearchBundle> | {
|
|
100
|
+
resourceType: 'Bundle';
|
|
101
|
+
type: BundleType;
|
|
102
|
+
entry: BuiltBundleEntry[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Materializes the staged entries as the `BundleJsonApi` shape used by
|
|
106
|
+
* `CommunicationAttachedBundleSession` and `ConsentAccessEditor`.
|
|
107
|
+
*
|
|
108
|
+
* Use this when the next layer edits bundle entries in-memory before another
|
|
109
|
+
* runtime wraps or sends the bundle.
|
|
110
|
+
*/
|
|
111
|
+
buildJsonApi(): BundleJsonApi<BundleEntry>;
|
|
112
|
+
/** @internal */
|
|
113
|
+
getMutableEntry(entryIndex: number): BuiltBundleEntry;
|
|
114
|
+
/** @internal */
|
|
115
|
+
removeMutableEntry(entryIndex: number): void;
|
|
116
|
+
/** @internal */
|
|
117
|
+
findEntryIndexByIdentifierOrFullUrl(resourceIdOrFullUrl: string): number;
|
|
118
|
+
/**
|
|
119
|
+
* Creates the mutable entry state that will later be wrapped by one entry editor.
|
|
120
|
+
*
|
|
121
|
+
* The draft seeds bundle-owned defaults such as:
|
|
122
|
+
* - canonical internal identifier (`resource.id` / `fullUrl`)
|
|
123
|
+
* - request method derived from the high-level bundle operation
|
|
124
|
+
* - generic entry type string
|
|
125
|
+
*
|
|
126
|
+
* It does not yet imply that the public `<ResourceType>.identifier` claim was
|
|
127
|
+
* written; the entry editor decides when that claim must be synchronized.
|
|
128
|
+
*/
|
|
129
|
+
private createEntryDraft;
|
|
130
|
+
/**
|
|
131
|
+
* Resolves which resource type one new entry should use.
|
|
132
|
+
*
|
|
133
|
+
* Non-document bundles stay homogeneous once an allowed resource type was
|
|
134
|
+
* declared. Document bundles may stage multiple resource types and therefore
|
|
135
|
+
* can use the override path repeatedly.
|
|
136
|
+
*/
|
|
137
|
+
private resolveEntryResourceType;
|
|
138
|
+
/**
|
|
139
|
+
* Normalizes one single-entry search bundle into a plain claims object.
|
|
140
|
+
*
|
|
141
|
+
* Keep this internal because it is specific to the current search serialization
|
|
142
|
+
* contract and should not become the public reader/editor story.
|
|
143
|
+
*/
|
|
144
|
+
private getSingleSearchClaims;
|
|
145
|
+
/** Returns the declared bundle operation or throws one onboarding-grade error. */
|
|
146
|
+
private requireBundleOperation;
|
|
147
|
+
/** Returns the allowed resource type or throws when the editor was not initialized correctly. */
|
|
148
|
+
private requireAllowedResourceType;
|
|
149
|
+
/**
|
|
150
|
+
* Stores one Composition scalar claim in the staged document metadata.
|
|
151
|
+
*
|
|
152
|
+
* Callers should use semantic wrappers such as `setCompositionTitle(...)`
|
|
153
|
+
* instead of touching claim keys directly.
|
|
154
|
+
*/
|
|
155
|
+
private setCompositionScalarClaim;
|
|
156
|
+
/**
|
|
157
|
+
* Reads one normalized Composition scalar claim.
|
|
158
|
+
*
|
|
159
|
+
* This internal helper explains the otherwise opaque `getComposition...()`
|
|
160
|
+
* implementations: they all delegate to the same normalized metadata store.
|
|
161
|
+
*/
|
|
162
|
+
private getCompositionScalarClaim;
|
|
163
|
+
/**
|
|
164
|
+
* Stores one CSV-backed Composition claim list such as `Composition.author`.
|
|
165
|
+
*
|
|
166
|
+
* The editor keeps the flattened storage representation internal while the
|
|
167
|
+
* public API exposes simple `string[]` setters/getters.
|
|
168
|
+
*/
|
|
169
|
+
private setCompositionCsvClaimList;
|
|
170
|
+
/** Reads one CSV-backed Composition claim list as a normalized string array. */
|
|
171
|
+
private getCompositionCsvClaimList;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Generic editor for one staged bundle entry.
|
|
175
|
+
*
|
|
176
|
+
* This class only knows generic entry concerns such as:
|
|
177
|
+
* - resource id
|
|
178
|
+
* - fullUrl
|
|
179
|
+
* - meta claims
|
|
180
|
+
* - conversion to one resource-specific entry editor
|
|
181
|
+
*/
|