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.
Files changed (154) hide show
  1. package/README.md +18 -0
  2. package/dist/claims/claims-helpers-allergy-intolerance.d.ts +8 -0
  3. package/dist/claims/claims-helpers-allergy-intolerance.js +30 -12
  4. package/dist/claims/claims-helpers-condition.d.ts +8 -0
  5. package/dist/claims/claims-helpers-condition.js +30 -12
  6. package/dist/claims/claims-helpers-consent.d.ts +4 -0
  7. package/dist/claims/claims-helpers-consent.js +15 -1
  8. package/dist/claims/claims-helpers-diagnostic-report.d.ts +4 -0
  9. package/dist/claims/claims-helpers-diagnostic-report.js +17 -2
  10. package/dist/claims/claims-helpers-medication-statement.d.ts +10 -2
  11. package/dist/claims/claims-helpers-medication-statement.js +32 -14
  12. package/dist/constants/didcomm.d.ts +22 -0
  13. package/dist/constants/didcomm.js +22 -0
  14. package/dist/constants/fhir-resource-types.d.ts +2 -0
  15. package/dist/constants/fhir-resource-types.js +1 -0
  16. package/dist/constants/index.d.ts +1 -0
  17. package/dist/constants/index.js +1 -0
  18. package/dist/constants/lifecycle.d.ts +2 -0
  19. package/dist/constants/lifecycle.js +2 -0
  20. package/dist/constants/verifiable-credentials.d.ts +9 -0
  21. package/dist/constants/verifiable-credentials.js +9 -0
  22. package/dist/examples/bundle-didcomm-payload.js +4 -2
  23. package/dist/examples/communication-attached-bundle-session.js +27 -27
  24. package/dist/examples/communication-didcomm-payload.d.ts +8 -4
  25. package/dist/examples/communication-didcomm-payload.js +17 -11
  26. package/dist/examples/consent-access.js +2 -1
  27. package/dist/examples/employee.d.ts +21 -0
  28. package/dist/examples/employee.js +21 -0
  29. package/dist/examples/individual-controller.d.ts +27 -0
  30. package/dist/examples/individual-controller.js +28 -1
  31. package/dist/examples/inter-tenant-access-contract.js +3 -2
  32. package/dist/examples/ips-bundle.js +17 -16
  33. package/dist/examples/lifecycle.js +13 -11
  34. package/dist/examples/profile-manager-mem.js +2 -1
  35. package/dist/examples/related-person.d.ts +14 -0
  36. package/dist/examples/related-person.js +18 -4
  37. package/dist/examples/shared.d.ts +12 -3
  38. package/dist/examples/shared.js +13 -4
  39. package/dist/examples/vital-signs.js +1 -1
  40. package/dist/examples/wallet-mem.js +4 -2
  41. package/dist/models/authority-resolution.d.ts +56 -0
  42. package/dist/models/authority-resolution.js +2 -0
  43. package/dist/models/bundle-editor-types.d.ts +89 -0
  44. package/dist/models/bundle-editor-types.js +45 -0
  45. package/dist/models/bundle.d.ts +5 -0
  46. package/dist/models/communication-attached-bundle-session.d.ts +6 -4
  47. package/dist/models/communication-attached-bundle-session.js +6 -4
  48. package/dist/models/confidential-storage.d.ts +2 -1
  49. package/dist/models/consent-rule.d.ts +11 -1
  50. package/dist/models/consent-rule.js +9 -1
  51. package/dist/models/index.d.ts +2 -0
  52. package/dist/models/index.js +2 -0
  53. package/dist/models/individual-onboarding.d.ts +18 -0
  54. package/dist/models/interoperable-claims/allergy-intolerance-claims.d.ts +12 -1
  55. package/dist/models/interoperable-claims/allergy-intolerance-claims.js +12 -1
  56. package/dist/models/interoperable-claims/condition-claims.d.ts +12 -1
  57. package/dist/models/interoperable-claims/condition-claims.js +12 -1
  58. package/dist/models/interoperable-claims/diagnostic-report-claims.d.ts +13 -2
  59. package/dist/models/interoperable-claims/diagnostic-report-claims.js +12 -1
  60. package/dist/models/interoperable-claims/document-reference-claims.d.ts +1 -0
  61. package/dist/models/interoperable-claims/document-reference-claims.js +3 -0
  62. package/dist/models/interoperable-claims/medication-statement-claims.d.ts +17 -0
  63. package/dist/models/interoperable-claims/medication-statement-claims.js +17 -0
  64. package/dist/utils/allergy-intolerance-entry-editor.d.ts +51 -0
  65. package/dist/utils/allergy-intolerance-entry-editor.js +55 -0
  66. package/dist/utils/authority-resolution.d.ts +37 -0
  67. package/dist/utils/authority-resolution.js +112 -0
  68. package/dist/utils/backend-message-manager-mem.d.ts +11 -0
  69. package/dist/utils/backend-message-manager-mem.js +11 -0
  70. package/dist/utils/bundle-didcomm-payload.js +3 -2
  71. package/dist/utils/bundle-document-builder.d.ts +1 -0
  72. package/dist/utils/bundle-document-builder.js +134 -14
  73. package/dist/utils/bundle-editor-core.d.ts +181 -0
  74. package/dist/utils/bundle-editor-core.js +467 -0
  75. package/dist/utils/bundle-editor-helpers.d.ts +53 -0
  76. package/dist/utils/bundle-editor-helpers.js +146 -0
  77. package/dist/utils/bundle-editor-registry.d.ts +6 -0
  78. package/dist/utils/bundle-editor-registry.js +14 -0
  79. package/dist/utils/bundle-editor.d.ts +21 -722
  80. package/dist/utils/bundle-editor.js +21 -1601
  81. package/dist/utils/bundle-entry-editor.d.ts +96 -0
  82. package/dist/utils/bundle-entry-editor.js +305 -0
  83. package/dist/utils/bundle-query.d.ts +1 -0
  84. package/dist/utils/bundle-query.js +12 -3
  85. package/dist/utils/bundle-reader.d.ts +48 -0
  86. package/dist/utils/bundle-reader.js +175 -1
  87. package/dist/utils/care-plan-entry-editor.d.ts +43 -0
  88. package/dist/utils/care-plan-entry-editor.js +47 -0
  89. package/dist/utils/client-assertion.d.ts +38 -0
  90. package/dist/utils/client-assertion.js +113 -0
  91. package/dist/utils/clinical-impression-entry-editor.d.ts +43 -0
  92. package/dist/utils/clinical-impression-entry-editor.js +47 -0
  93. package/dist/utils/clinical-resource-entry-editor.d.ts +123 -0
  94. package/dist/utils/clinical-resource-entry-editor.js +296 -0
  95. package/dist/utils/communication-attached-bundle-session-helpers.js +8 -6
  96. package/dist/utils/communication-attached-bundle-session.d.ts +29 -3
  97. package/dist/utils/communication-attached-bundle-session.js +62 -3
  98. package/dist/utils/communication-didcomm-payload.d.ts +5 -0
  99. package/dist/utils/communication-didcomm-payload.js +28 -18
  100. package/dist/utils/communication-document-reference.d.ts +23 -0
  101. package/dist/utils/communication-document-reference.js +89 -0
  102. package/dist/utils/communication-editor.d.ts +53 -0
  103. package/dist/utils/communication-editor.js +97 -0
  104. package/dist/utils/condition-entry-editor.d.ts +30 -0
  105. package/dist/utils/condition-entry-editor.js +34 -0
  106. package/dist/utils/consent-claim-helpers.d.ts +4 -0
  107. package/dist/utils/consent-claim-helpers.js +15 -1
  108. package/dist/utils/coverage-entry-editor.d.ts +51 -0
  109. package/dist/utils/coverage-entry-editor.js +55 -0
  110. package/dist/utils/device-entry-editor.d.ts +59 -0
  111. package/dist/utils/device-entry-editor.js +63 -0
  112. package/dist/utils/device-use-statement-entry-editor.d.ts +43 -0
  113. package/dist/utils/device-use-statement-entry-editor.js +47 -0
  114. package/dist/utils/diagnostic-report-entry-editor.d.ts +74 -0
  115. package/dist/utils/diagnostic-report-entry-editor.js +136 -0
  116. package/dist/utils/did.d.ts +8 -0
  117. package/dist/utils/did.js +22 -0
  118. package/dist/utils/document-reference-entry-editor.d.ts +62 -0
  119. package/dist/utils/document-reference-entry-editor.js +66 -0
  120. package/dist/utils/employee-entry-editor.d.ts +36 -0
  121. package/dist/utils/employee-entry-editor.js +88 -0
  122. package/dist/utils/employee.d.ts +1 -0
  123. package/dist/utils/employee.js +2 -1
  124. package/dist/utils/encounter-entry-editor.d.ts +51 -0
  125. package/dist/utils/encounter-entry-editor.js +55 -0
  126. package/dist/utils/flag-entry-editor.d.ts +47 -0
  127. package/dist/utils/flag-entry-editor.js +51 -0
  128. package/dist/utils/immunization-entry-editor.d.ts +87 -0
  129. package/dist/utils/immunization-entry-editor.js +169 -0
  130. package/dist/utils/index.d.ts +7 -0
  131. package/dist/utils/index.js +7 -0
  132. package/dist/utils/individual-onboarding-acceptance-credential.d.ts +35 -0
  133. package/dist/utils/individual-onboarding-acceptance-credential.js +55 -0
  134. package/dist/utils/individual-smart.d.ts +59 -0
  135. package/dist/utils/individual-smart.js +135 -0
  136. package/dist/utils/medication-statement-entry-editor.d.ts +90 -0
  137. package/dist/utils/medication-statement-entry-editor.js +94 -0
  138. package/dist/utils/observation-component-entry-editor.d.ts +57 -0
  139. package/dist/utils/observation-component-entry-editor.js +105 -0
  140. package/dist/utils/observation-entry-editor.d.ts +29 -0
  141. package/dist/utils/observation-entry-editor.js +68 -0
  142. package/dist/utils/procedure-entry-editor.d.ts +71 -0
  143. package/dist/utils/procedure-entry-editor.js +75 -0
  144. package/dist/utils/professional-smart.d.ts +87 -0
  145. package/dist/utils/professional-smart.js +118 -4
  146. package/dist/utils/same-as.d.ts +40 -0
  147. package/dist/utils/same-as.js +72 -0
  148. package/dist/utils/unified-health-id.d.ts +51 -0
  149. package/dist/utils/unified-health-id.js +92 -0
  150. package/dist/utils/vital-sign-day-batch.d.ts +25 -0
  151. package/dist/utils/vital-sign-day-batch.js +115 -0
  152. package/dist/utils/vital-sign-entry-editor.d.ts +61 -0
  153. package/dist/utils/vital-sign-entry-editor.js +152 -0
  154. package/package.json +2 -1
@@ -0,0 +1,123 @@
1
+ import { AllowedResourceType, type ResourceTypeEntryEditor } from '../models/bundle-editor-types';
2
+ import { BundleEntryEditor } from './bundle-entry-editor';
3
+ export declare class ClinicalResourceEntryEditor extends BundleEntryEditor {
4
+ /**
5
+ * Returns the best current identifier for the resource:
6
+ * - public `<ResourceType>.identifier` claim first
7
+ * - otherwise internal `resource.id`
8
+ * - otherwise `fullUrl`
9
+ *
10
+ * This fallback order matters because the editor may stage one new entry
11
+ * before the public identifier claim has been synchronized.
12
+ */
13
+ protected getIdentifierValue(claimKey: string): string | undefined;
14
+ protected setIdentifierValue(claimKey: string, identifier?: string | null): this;
15
+ /** Writes the same subject value into both subject-style claim slots used by this resource family. */
16
+ protected setSubjectClaims(subjectClaimKey: string, patientClaimKey: string, subject?: string | null): this;
17
+ /** Reads the normalized subject value from the supported subject/patient claim aliases. */
18
+ protected getSubjectClaims(subjectClaimKey: string, patientClaimKey: string): string | undefined;
19
+ /** Writes one trimmed string claim and removes the key when the value is blank. */
20
+ protected setScalarClaim(claimKey: string, value?: string | null): this;
21
+ /** Reads one string claim using the shared blank-to-undefined normalization rule. */
22
+ protected getScalarClaim(claimKey: string): string | undefined;
23
+ /** Stores one numeric claim through the flat-claims string representation used by the bundle editors. */
24
+ protected setNumberClaim(claimKey: string, value?: number | null): this;
25
+ /** Reads one numeric flat claim and converts it back to a finite number when possible. */
26
+ protected getNumberClaim(claimKey: string): number | undefined;
27
+ /** Stores one boolean claim and removes it when the caller wants to clear the field. */
28
+ protected setBooleanClaim(claimKey: string, value?: boolean | null): this;
29
+ /** Reads one boolean claim while tolerating both real booleans and serialized `'true'` / `'false'` values. */
30
+ protected getBooleanClaim(claimKey: string): boolean | undefined;
31
+ /** Stores one multi-value flat claim using the shared CSV serialization helper. */
32
+ protected setCsvClaimList(claimKey: string, values: readonly string[]): this;
33
+ /** Reads one CSV-backed flat claim as a normalized string list. */
34
+ protected getCsvClaimList(claimKey: string): string[];
35
+ /**
36
+ * Ensures one canonical identifier across:
37
+ * - public identifier claim
38
+ * - `resource.id`
39
+ * - `fullUrl`
40
+ *
41
+ * This is the preferred onboarding path after `newEntryAs(...)` /
42
+ * `newContainedResourceAs(...)` when the entry was created without an
43
+ * explicit id.
44
+ */
45
+ protected ensureIdentifierValue(claimKey: string): string;
46
+ /** Resolves which claim stores the CSV list of linked/contained resource references for this resource type. */
47
+ protected getContainedReferenceListClaimKey(): string;
48
+ /** Builds one resource-scoped claim key such as `MedicationStatement.language`. */
49
+ protected getResourceScopedClaimKey(suffix: string): string;
50
+ /** Returns the canonical `ResourceType/<identifier>` reference for the current staged entry. */
51
+ protected getEntryReference(): string;
52
+ /** Replaces the linked child-resource reference list on the current parent resource. */
53
+ setContainedResourceReferenceList(references: readonly string[]): this;
54
+ /** Returns the normalized linked child-resource reference list for the current parent resource. */
55
+ getContainedResourceReferenceList(): string[];
56
+ /** Adds one child-resource reference to the parent list, deduplicating exact matches. */
57
+ addContainedResourceReference(reference: string): this;
58
+ /** Removes one child-resource reference from the parent list without touching any staged child entry. */
59
+ removeContainedResourceReference(reference: string): this;
60
+ /**
61
+ * Creates one linked child entry, then seeds it from an already prepared claims object.
62
+ *
63
+ * Keep this as a plumbing/import helper. The 101 path should prefer
64
+ * `newContainedResourceAs(...)` so the front edits the child through the
65
+ * typed editor surface instead of raw claim objects.
66
+ */
67
+ addContainedResourceByClaims(resourceType: AllowedResourceType, claims: Record<string, unknown>, resourceIdOrReference?: string, options?: Readonly<{
68
+ contained?: boolean;
69
+ }>): BundleEntryEditor;
70
+ /**
71
+ * Opens one linked child/sibling resource through the same `BundleEditor`.
72
+ *
73
+ * Default path:
74
+ * - create one visible sibling resource
75
+ * - link it from the parent CSV reference list
76
+ *
77
+ * Advanced path:
78
+ * - pass `{ contained: true }` only when the FHIR export must rebuild the
79
+ * resource under `parent.contained[]`.
80
+ */
81
+ /**
82
+ * Creates one linked child entry through the same bundle editor.
83
+ *
84
+ * Default behavior:
85
+ * - create one visible sibling entry
86
+ * - add its canonical `ResourceType/<id>` reference to the parent list
87
+ *
88
+ * Advanced behavior:
89
+ * - `{ contained: true }` also marks the child so FHIR export can rebuild it
90
+ * under `parent.contained[]` instead of showing it as a normal top-level
91
+ * clinical resource entry.
92
+ */
93
+ newContainedResource(resourceType: AllowedResourceType, resourceIdOrReference?: string, options?: Readonly<{
94
+ contained?: boolean;
95
+ }>): BundleEntryEditor;
96
+ /** Creates one linked child entry and immediately returns the typed editor for that child resource type. */
97
+ newContainedResourceAs<T extends AllowedResourceType>(resourceType: T, resourceIdOrReference?: string, options?: Readonly<{
98
+ contained?: boolean;
99
+ }>): ResourceTypeEntryEditor<T>;
100
+ /** @deprecated Use `newContainedResource(...)`. */
101
+ addContainedResourceEntry(resourceType: AllowedResourceType, resourceIdOrReference?: string, options?: Readonly<{
102
+ contained?: boolean;
103
+ }>): BundleEntryEditor;
104
+ /**
105
+ * Removes one linked child reference and, when the child was marked as
106
+ * contained under this exact parent, also removes the staged child entry.
107
+ */
108
+ removeContainedResourceByReference(reference: string): this;
109
+ /** Stores the generic `<ResourceType>.language` flat claim used by multilingual resource payloads. */
110
+ setLanguage(value?: string | null): this;
111
+ /** Returns the generic `<ResourceType>.language` flat claim when present. */
112
+ getLanguage(): string | undefined;
113
+ /** Stores the generic `<ResourceType>.user-selected` flag used by self-managed user flows. */
114
+ setUserSelected(value?: boolean | null): this;
115
+ /** Returns the generic `<ResourceType>.user-selected` flag when present. */
116
+ getUserSelected(): boolean | undefined;
117
+ }
118
+ /**
119
+ * Reduced Observation component-style editor surface.
120
+ *
121
+ * This base layer owns the reusable code/value authoring helpers shared by
122
+ * Vital Signs and broader Observation entry editors.
123
+ */
@@ -0,0 +1,296 @@
1
+ import { cloneClaimValue, createCanonicalIdentifierUrn, normalizeContainedReference, normalizeOptionalIdentifier, resolveContainedFlagClaimKey, resolveContainedParentReferenceClaimKey, resolveContainedReferenceListClaimKey, } from './bundle-editor-helpers.js';
2
+ import { BundleEntryEditor } from './bundle-entry-editor.js';
3
+ import { getClaimValues, setClaimValues } from '../claims/claim-list-helpers.js';
4
+ export class ClinicalResourceEntryEditor extends BundleEntryEditor {
5
+ /**
6
+ * Returns the best current identifier for the resource:
7
+ * - public `<ResourceType>.identifier` claim first
8
+ * - otherwise internal `resource.id`
9
+ * - otherwise `fullUrl`
10
+ *
11
+ * This fallback order matters because the editor may stage one new entry
12
+ * before the public identifier claim has been synchronized.
13
+ */
14
+ getIdentifierValue(claimKey) {
15
+ return normalizeOptionalIdentifier(this.getClaim(claimKey)
16
+ || this.getResourceId()
17
+ || this.getFullUrl());
18
+ }
19
+ setIdentifierValue(claimKey, identifier) {
20
+ const normalized = normalizeOptionalIdentifier(identifier);
21
+ if (!normalized) {
22
+ this.removeClaim(claimKey);
23
+ this.setResourceId(undefined);
24
+ this.setFullUrl(undefined);
25
+ return this;
26
+ }
27
+ this.setClaim(claimKey, normalized);
28
+ this.setResourceId(normalized);
29
+ this.setFullUrl(normalized);
30
+ return this;
31
+ }
32
+ /** Writes the same subject value into both subject-style claim slots used by this resource family. */
33
+ setSubjectClaims(subjectClaimKey, patientClaimKey, subject) {
34
+ const normalized = normalizeOptionalIdentifier(subject);
35
+ if (!normalized) {
36
+ this.removeClaim(subjectClaimKey);
37
+ this.removeClaim(patientClaimKey);
38
+ return this;
39
+ }
40
+ this.setClaim(subjectClaimKey, normalized);
41
+ this.setClaim(patientClaimKey, normalized);
42
+ return this;
43
+ }
44
+ /** Reads the normalized subject value from the supported subject/patient claim aliases. */
45
+ getSubjectClaims(subjectClaimKey, patientClaimKey) {
46
+ return normalizeOptionalIdentifier(this.getClaim(subjectClaimKey)
47
+ || this.getClaim(patientClaimKey));
48
+ }
49
+ /** Writes one trimmed string claim and removes the key when the value is blank. */
50
+ setScalarClaim(claimKey, value) {
51
+ const normalized = normalizeOptionalIdentifier(value);
52
+ if (!normalized) {
53
+ this.removeClaim(claimKey);
54
+ return this;
55
+ }
56
+ return this.setClaim(claimKey, normalized);
57
+ }
58
+ /** Reads one string claim using the shared blank-to-undefined normalization rule. */
59
+ getScalarClaim(claimKey) {
60
+ return normalizeOptionalIdentifier(this.getClaim(claimKey));
61
+ }
62
+ /** Stores one numeric claim through the flat-claims string representation used by the bundle editors. */
63
+ setNumberClaim(claimKey, value) {
64
+ if (value === undefined || value === null || Number.isNaN(value)) {
65
+ this.removeClaim(claimKey);
66
+ return this;
67
+ }
68
+ return this.setClaim(claimKey, String(value));
69
+ }
70
+ /** Reads one numeric flat claim and converts it back to a finite number when possible. */
71
+ getNumberClaim(claimKey) {
72
+ const raw = this.getClaim(claimKey);
73
+ if (raw === undefined || raw === null || raw === '')
74
+ return undefined;
75
+ const numeric = Number(raw);
76
+ return Number.isFinite(numeric) ? numeric : undefined;
77
+ }
78
+ /** Stores one boolean claim and removes it when the caller wants to clear the field. */
79
+ setBooleanClaim(claimKey, value) {
80
+ if (value === undefined || value === null) {
81
+ this.removeClaim(claimKey);
82
+ return this;
83
+ }
84
+ return this.setClaim(claimKey, value);
85
+ }
86
+ /** Reads one boolean claim while tolerating both real booleans and serialized `'true'` / `'false'` values. */
87
+ getBooleanClaim(claimKey) {
88
+ const raw = this.getClaim(claimKey);
89
+ if (typeof raw === 'boolean')
90
+ return raw;
91
+ if (raw === 'true')
92
+ return true;
93
+ if (raw === 'false')
94
+ return false;
95
+ return undefined;
96
+ }
97
+ /** Stores one multi-value flat claim using the shared CSV serialization helper. */
98
+ setCsvClaimList(claimKey, values) {
99
+ const next = setClaimValues({}, claimKey, values);
100
+ const normalized = normalizeOptionalIdentifier(next[claimKey]);
101
+ if (!normalized) {
102
+ this.removeClaim(claimKey);
103
+ return this;
104
+ }
105
+ return this.setClaim(claimKey, normalized);
106
+ }
107
+ /** Reads one CSV-backed flat claim as a normalized string list. */
108
+ getCsvClaimList(claimKey) {
109
+ return getClaimValues(this.getClaims(), claimKey);
110
+ }
111
+ /**
112
+ * Ensures one canonical identifier across:
113
+ * - public identifier claim
114
+ * - `resource.id`
115
+ * - `fullUrl`
116
+ *
117
+ * This is the preferred onboarding path after `newEntryAs(...)` /
118
+ * `newContainedResourceAs(...)` when the entry was created without an
119
+ * explicit id.
120
+ */
121
+ ensureIdentifierValue(claimKey) {
122
+ const existingClaim = normalizeOptionalIdentifier(this.getClaim(claimKey));
123
+ if (existingClaim)
124
+ return existingClaim;
125
+ const existingResourceIdentifier = normalizeOptionalIdentifier(this.getResourceId() || this.getFullUrl());
126
+ if (existingResourceIdentifier) {
127
+ this.setIdentifierValue(claimKey, existingResourceIdentifier);
128
+ return existingResourceIdentifier;
129
+ }
130
+ const generated = createCanonicalIdentifierUrn();
131
+ this.setIdentifierValue(claimKey, generated);
132
+ return generated;
133
+ }
134
+ /** Resolves which claim stores the CSV list of linked/contained resource references for this resource type. */
135
+ getContainedReferenceListClaimKey() {
136
+ const resourceType = String(this.getMutableEntry().resource?.resourceType || '').trim();
137
+ const claimKey = resolveContainedReferenceListClaimKey(resourceType);
138
+ if (!claimKey) {
139
+ throw new Error(`Contained-reference linking is not supported for resource type: ${resourceType || '(unknown)'}`);
140
+ }
141
+ return claimKey;
142
+ }
143
+ /** Builds one resource-scoped claim key such as `MedicationStatement.language`. */
144
+ getResourceScopedClaimKey(suffix) {
145
+ const resourceType = String(this.getMutableEntry().resource?.resourceType || '').trim();
146
+ if (!resourceType) {
147
+ throw new Error('Resource-scoped claim access requires one concrete resource type.');
148
+ }
149
+ return `${resourceType}.${String(suffix || '').trim()}`;
150
+ }
151
+ /** Returns the canonical `ResourceType/<identifier>` reference for the current staged entry. */
152
+ getEntryReference() {
153
+ const resourceType = String(this.getMutableEntry().resource?.resourceType || '').trim();
154
+ const identifier = normalizeOptionalIdentifier(this.getResourceId() || this.getFullUrl());
155
+ if (!resourceType || !identifier) {
156
+ throw new Error('Contained-resource linking requires the parent entry to have a concrete resource type and identifier.');
157
+ }
158
+ return `${resourceType}/${identifier}`;
159
+ }
160
+ /** Replaces the linked child-resource reference list on the current parent resource. */
161
+ setContainedResourceReferenceList(references) {
162
+ return this.setCsvClaimList(this.getContainedReferenceListClaimKey(), references);
163
+ }
164
+ /** Returns the normalized linked child-resource reference list for the current parent resource. */
165
+ getContainedResourceReferenceList() {
166
+ return this.getCsvClaimList(this.getContainedReferenceListClaimKey());
167
+ }
168
+ /** Adds one child-resource reference to the parent list, deduplicating exact matches. */
169
+ addContainedResourceReference(reference) {
170
+ const next = [...this.getContainedResourceReferenceList(), String(reference || '').trim()]
171
+ .filter(Boolean);
172
+ return this.setContainedResourceReferenceList([...new Set(next)]);
173
+ }
174
+ /** Removes one child-resource reference from the parent list without touching any staged child entry. */
175
+ removeContainedResourceReference(reference) {
176
+ const normalized = String(reference || '').trim();
177
+ if (!normalized) {
178
+ return this;
179
+ }
180
+ return this.setContainedResourceReferenceList(this.getContainedResourceReferenceList().filter((item) => item !== normalized));
181
+ }
182
+ /**
183
+ * Creates one linked child entry, then seeds it from an already prepared claims object.
184
+ *
185
+ * Keep this as a plumbing/import helper. The 101 path should prefer
186
+ * `newContainedResourceAs(...)` so the front edits the child through the
187
+ * typed editor surface instead of raw claim objects.
188
+ */
189
+ addContainedResourceByClaims(resourceType, claims, resourceIdOrReference, options) {
190
+ const seededIdentifier = normalizeOptionalIdentifier(resourceIdOrReference)
191
+ || normalizeOptionalIdentifier(claims[`${resourceType}.identifier`])
192
+ || createCanonicalIdentifierUrn();
193
+ const containedEntry = this.addContainedResourceEntry(resourceType, seededIdentifier, options);
194
+ Object.entries(claims || {}).forEach(([key, value]) => {
195
+ containedEntry.setClaim(key, cloneClaimValue(value));
196
+ });
197
+ return containedEntry;
198
+ }
199
+ /**
200
+ * Opens one linked child/sibling resource through the same `BundleEditor`.
201
+ *
202
+ * Default path:
203
+ * - create one visible sibling resource
204
+ * - link it from the parent CSV reference list
205
+ *
206
+ * Advanced path:
207
+ * - pass `{ contained: true }` only when the FHIR export must rebuild the
208
+ * resource under `parent.contained[]`.
209
+ */
210
+ /**
211
+ * Creates one linked child entry through the same bundle editor.
212
+ *
213
+ * Default behavior:
214
+ * - create one visible sibling entry
215
+ * - add its canonical `ResourceType/<id>` reference to the parent list
216
+ *
217
+ * Advanced behavior:
218
+ * - `{ contained: true }` also marks the child so FHIR export can rebuild it
219
+ * under `parent.contained[]` instead of showing it as a normal top-level
220
+ * clinical resource entry.
221
+ */
222
+ newContainedResource(resourceType, resourceIdOrReference, options) {
223
+ const parentReference = this.getEntryReference();
224
+ const seededIdentifier = normalizeOptionalIdentifier(resourceIdOrReference) || createCanonicalIdentifierUrn();
225
+ const normalizedContained = normalizeContainedReference(resourceType, seededIdentifier);
226
+ const containedEntry = this.bundleEditor.newEntryAs(resourceType, normalizedContained.identifier);
227
+ containedEntry
228
+ .setResourceId(normalizedContained.identifier)
229
+ .setFullUrl(normalizedContained.identifier)
230
+ .setClaim(`${resourceType}.identifier`, normalizedContained.identifier);
231
+ if (options?.contained) {
232
+ containedEntry
233
+ .setClaim(resolveContainedFlagClaimKey(resourceType), true)
234
+ .setClaim(resolveContainedParentReferenceClaimKey(resourceType), parentReference);
235
+ }
236
+ this.addContainedResourceReference(normalizedContained.reference);
237
+ return containedEntry;
238
+ }
239
+ /** Creates one linked child entry and immediately returns the typed editor for that child resource type. */
240
+ newContainedResourceAs(resourceType, resourceIdOrReference, options) {
241
+ return this.newContainedResource(resourceType, resourceIdOrReference, options).asResourceType(resourceType);
242
+ }
243
+ /** @deprecated Use `newContainedResource(...)`. */
244
+ addContainedResourceEntry(resourceType, resourceIdOrReference, options) {
245
+ return this.newContainedResource(resourceType, resourceIdOrReference, options);
246
+ }
247
+ /**
248
+ * Removes one linked child reference and, when the child was marked as
249
+ * contained under this exact parent, also removes the staged child entry.
250
+ */
251
+ removeContainedResourceByReference(reference) {
252
+ const parentReference = this.getEntryReference();
253
+ const normalizedContained = normalizeContainedReference(String(reference || '').includes('/') ? String(reference || '').split('/')[0] : '', String(reference || ''));
254
+ const normalizedReference = normalizedContained.reference || String(reference || '').trim();
255
+ const normalizedIdentifier = normalizedContained.identifier || normalizedReference.split('/').pop() || '';
256
+ this.removeContainedResourceReference(normalizedReference);
257
+ const childEntryIndex = this.bundleEditor.findEntryIndexByIdentifierOrFullUrl(normalizedIdentifier);
258
+ if (childEntryIndex < 0) {
259
+ return this;
260
+ }
261
+ const childEntry = this.bundleEditor.getMutableEntry(childEntryIndex);
262
+ const childClaims = childEntry.resource?.meta?.claims || {};
263
+ const childResourceType = String(childEntry.resource?.resourceType || '').trim();
264
+ const childContainedFlagClaimKey = resolveContainedFlagClaimKey(childResourceType);
265
+ const childContainedParentReferenceClaimKey = resolveContainedParentReferenceClaimKey(childResourceType);
266
+ const isContainedChild = childClaims[childContainedFlagClaimKey] === true
267
+ || childClaims[childContainedFlagClaimKey] === 'true';
268
+ const childParentReference = normalizeOptionalIdentifier(childClaims[childContainedParentReferenceClaimKey]);
269
+ if (isContainedChild && childParentReference === parentReference) {
270
+ this.bundleEditor.removeMutableEntry(childEntryIndex);
271
+ }
272
+ return this;
273
+ }
274
+ /** Stores the generic `<ResourceType>.language` flat claim used by multilingual resource payloads. */
275
+ setLanguage(value) {
276
+ return this.setScalarClaim(this.getResourceScopedClaimKey('language'), value);
277
+ }
278
+ /** Returns the generic `<ResourceType>.language` flat claim when present. */
279
+ getLanguage() {
280
+ return this.getScalarClaim(this.getResourceScopedClaimKey('language'));
281
+ }
282
+ /** Stores the generic `<ResourceType>.user-selected` flag used by self-managed user flows. */
283
+ setUserSelected(value) {
284
+ return this.setBooleanClaim(this.getResourceScopedClaimKey('user-selected'), value);
285
+ }
286
+ /** Returns the generic `<ResourceType>.user-selected` flag when present. */
287
+ getUserSelected() {
288
+ return this.getBooleanClaim(this.getResourceScopedClaimKey('user-selected'));
289
+ }
290
+ }
291
+ /**
292
+ * Reduced Observation component-style editor surface.
293
+ *
294
+ * This base layer owns the reusable code/value authoring helpers shared by
295
+ * Vital Signs and broader Observation entry editors.
296
+ */
@@ -39,7 +39,9 @@ export function ensureEntryResource(entry, mode) {
39
39
  throw new Error('Active entry does not contain a valid resource object.');
40
40
  }
41
41
  export function validateBundleLike(bundle, mode) {
42
- const looksLikeBundle = bundle && bundle.resourceType === ResourceTypesFhirR4.Bundle && Array.isArray(bundle.data);
42
+ const looksLikeBundle = bundle
43
+ && bundle.resourceType === ResourceTypesFhirR4.Bundle
44
+ && (Array.isArray(bundle.data) || Array.isArray(bundle.entry));
43
45
  if (looksLikeBundle || mode === 'normalize') {
44
46
  return;
45
47
  }
@@ -75,19 +77,19 @@ export function asTrimmedString(value) {
75
77
  }
76
78
  export function resolveContainedDocumentsClaimKey(resourceType) {
77
79
  if (resourceType === ResourceTypesFhirR4.Consent) {
78
- return ClaimConsent.containedDocuments;
80
+ return ClaimConsent.containedReferenceList;
79
81
  }
80
82
  if (resourceType === ResourceTypesFhirR4.MedicationStatement) {
81
- return MedicationStatementClaim.ContainedDocuments;
83
+ return MedicationStatementClaim.ContainedReferenceList;
82
84
  }
83
85
  if (resourceType === ResourceTypesFhirR4.Condition) {
84
- return ConditionClaim.ContainedDocuments;
86
+ return ConditionClaim.ContainedReferenceList;
85
87
  }
86
88
  if (resourceType === ResourceTypesFhirR4.AllergyIntolerance) {
87
- return AllergyIntoleranceClaim.ContainedDocuments;
89
+ return AllergyIntoleranceClaim.ContainedReferenceList;
88
90
  }
89
91
  if (resourceType === ResourceTypesFhirR4.DiagnosticReport) {
90
- return DiagnosticReportClaim.ContainedDocuments;
92
+ return DiagnosticReportClaim.ContainedReferenceList;
91
93
  }
92
94
  return '';
93
95
  }
@@ -2,7 +2,7 @@ import { BundleEntry, BundleJsonApi } from '../models/bundle';
2
2
  import { type ActiveEntrySelection, type AddContainedDocumentToActiveEntryInput, type CommunicationAttachedBundleSessionOptions, type UpsertClaimsResourceEntryInput, type UpsertEntryInput } from '../models/communication-attached-bundle-session';
3
3
  import { type BundleResourceIdFilters } from './bundle-query';
4
4
  import type { MedicationStatementClaimsFlat } from '../models/interoperable-claims/medication-statement-claims';
5
- export { BundleEntryClaimsContext, CommunicationAttachmentClaimsContext, ConsentEditorScopeCodes, ConsentEditorTargetKinds, } from '../models/communication-attached-bundle-session';
5
+ export { BundleEntryClaimsContext, CommunicationClaimsContext, CommunicationAttachmentClaimsContext, ConsentEditorScopeCodes, ConsentEditorTargetKinds, } from '../models/communication-attached-bundle-session';
6
6
  export type { ActiveEntrySelection, AddContainedDocumentToActiveEntryInput, CommunicationAttachedBundleSessionMode, CommunicationAttachedBundleSessionOptions, ConsentEditorClassifiedActors, ConsentEditorClassifiedPurpose, ConsentEditorClassifiedRole, ConsentEditorClassifiedRoles, ConsentEditorClassifiedTarget, ConsentEditorScopeCode, ConsentEditorTargetKind, ConsentViewModel, UpsertClaimsResourceEntryInput, UpsertEntryInput, } from '../models/communication-attached-bundle-session';
7
7
  /**
8
8
  * Communication editing session with bundle-in-memory as source of truth.
@@ -24,8 +24,32 @@ export declare class CommunicationAttachedBundleSession {
24
24
  constructor(options?: CommunicationAttachedBundleSessionOptions);
25
25
  /** Returns a deep copy of communication claims. */
26
26
  getCommunicationClaims(): Record<string, unknown>;
27
+ /** Returns the canonical outer Communication identifier. */
28
+ getCommunicationIdentifier(): string;
29
+ /** Sets the canonical outer Communication identifier. */
30
+ setCommunicationIdentifier(value: unknown): this;
31
+ /** Returns the canonical outer Communication subject. */
32
+ getCommunicationSubject(): string;
33
+ /** Sets the canonical outer Communication subject. */
34
+ setCommunicationSubject(value: unknown): this;
35
+ /** Returns the canonical outer Communication categories. */
36
+ getCommunicationCategoryList(): string[];
37
+ /** Replaces the canonical outer Communication categories. */
38
+ setCommunicationCategory(value: string | readonly string[]): this;
39
+ /** Returns the canonical outer Communication topic. */
40
+ getCommunicationTopic(): string;
41
+ /** Sets the canonical outer Communication topic. */
42
+ setCommunicationTopic(value: unknown): this;
43
+ /** Returns the canonical outer Communication text. */
44
+ getCommunicationText(): string;
45
+ /** Sets the canonical outer Communication text. */
46
+ setCommunicationText(value: unknown): this;
27
47
  /** Returns a deep copy of the current in-memory bundle. */
28
48
  getBundleInMemory(): BundleJsonApi<BundleEntry>;
49
+ /** Replaces the attached clinical bundle and resyncs the outer Communication attachment. */
50
+ setAttachedBundle(bundle: BundleJsonApi<BundleEntry>): this;
51
+ /** Alias of `getBundleInMemory()` with communication wording. */
52
+ getAttachedBundle(): BundleJsonApi<BundleEntry>;
29
53
  /** Returns the active entry index, or null when no entry is selected. */
30
54
  getActiveEntryIndex(): number | null;
31
55
  /** Returns the active entry position, or null when no entry is selected. */
@@ -86,7 +110,8 @@ export declare class CommunicationAttachedBundleSession {
86
110
  upsertActiveMedicationStatementEntry(input: UpsertClaimsResourceEntryInput<MedicationStatementClaimsFlat | Record<string, unknown>>): this;
87
111
  /**
88
112
  * DocumentReference helper for bundle-contained attachments linked from
89
- * other clinical resources through `*.contained-documents`.
113
+ * other clinical resources through `*.contained-reference-list`
114
+ * (with `*.contained-documents` kept as legacy compatibility alias).
90
115
  */
91
116
  upsertActiveDocumentReferenceEntry(input: UpsertClaimsResourceEntryInput<Record<string, unknown>>): this;
92
117
  /**
@@ -145,7 +170,8 @@ export declare class CommunicationAttachedBundleSession {
145
170
  upsertActiveRelatedPersonEntry(input: UpsertClaimsResourceEntryInput<Record<string, unknown>>): this;
146
171
  /**
147
172
  * Creates or updates a linked `DocumentReference` entry and stores its
148
- * identifier under the active resource `*.contained-documents` claim.
173
+ * identifier/reference under the active resource
174
+ * `*.contained-reference-list` claim.
149
175
  */
150
176
  addContainedDocumentToActiveEntry(input: AddContainedDocumentToActiveEntryInput): this;
151
177
  /**
@@ -6,8 +6,9 @@ import { DocumentReferenceClaim } from '../models/interoperable-claims/document-
6
6
  import { BundleEntryClaimsContext, } from '../models/communication-attached-bundle-session.js';
7
7
  import { BundleQuery } from './bundle-query.js';
8
8
  import { addClaimValues } from '../claims/claim-list-helpers.js';
9
+ import { getCommunicationCategoryList, getCommunicationIdentifier, getCommunicationSubject, getCommunicationText, getCommunicationTopic, setCommunicationCategory, setCommunicationIdentifier, setCommunicationSubject, setCommunicationText, setCommunicationTopic, } from '../claims/claims-helpers-communication.js';
9
10
  import { asTrimmedString, cloneBundle, cloneEntry, cloneUnknownValue, createEmptyBundle, encodeBundleToBase64, ensureEntryResource, resolveBundleEntryCanonicalIdValue, resolveBundleEntryIdentifier, resolveContainedDocumentsClaimKey, resolveSubjectFromClaims, runtimeUuid, setIfMissing, validateBundleLike, } from './communication-attached-bundle-session-helpers.js';
10
- export { BundleEntryClaimsContext, CommunicationAttachmentClaimsContext, ConsentEditorScopeCodes, ConsentEditorTargetKinds, } from '../models/communication-attached-bundle-session.js';
11
+ export { BundleEntryClaimsContext, CommunicationClaimsContext, CommunicationAttachmentClaimsContext, ConsentEditorScopeCodes, ConsentEditorTargetKinds, } from '../models/communication-attached-bundle-session.js';
11
12
  /**
12
13
  * Communication editing session with bundle-in-memory as source of truth.
13
14
  *
@@ -41,10 +42,66 @@ export class CommunicationAttachedBundleSession {
41
42
  ...this.communicationClaims,
42
43
  };
43
44
  }
45
+ /** Returns the canonical outer Communication identifier. */
46
+ getCommunicationIdentifier() {
47
+ return getCommunicationIdentifier(this.communicationClaims);
48
+ }
49
+ /** Sets the canonical outer Communication identifier. */
50
+ setCommunicationIdentifier(value) {
51
+ this.communicationClaims = setCommunicationIdentifier(this.communicationClaims, value);
52
+ return this;
53
+ }
54
+ /** Returns the canonical outer Communication subject. */
55
+ getCommunicationSubject() {
56
+ return getCommunicationSubject(this.communicationClaims);
57
+ }
58
+ /** Sets the canonical outer Communication subject. */
59
+ setCommunicationSubject(value) {
60
+ this.communicationClaims = setCommunicationSubject(this.communicationClaims, value);
61
+ return this;
62
+ }
63
+ /** Returns the canonical outer Communication categories. */
64
+ getCommunicationCategoryList() {
65
+ return getCommunicationCategoryList(this.communicationClaims);
66
+ }
67
+ /** Replaces the canonical outer Communication categories. */
68
+ setCommunicationCategory(value) {
69
+ this.communicationClaims = setCommunicationCategory(this.communicationClaims, value);
70
+ return this;
71
+ }
72
+ /** Returns the canonical outer Communication topic. */
73
+ getCommunicationTopic() {
74
+ return getCommunicationTopic(this.communicationClaims);
75
+ }
76
+ /** Sets the canonical outer Communication topic. */
77
+ setCommunicationTopic(value) {
78
+ this.communicationClaims = setCommunicationTopic(this.communicationClaims, value);
79
+ return this;
80
+ }
81
+ /** Returns the canonical outer Communication text. */
82
+ getCommunicationText() {
83
+ return getCommunicationText(this.communicationClaims);
84
+ }
85
+ /** Sets the canonical outer Communication text. */
86
+ setCommunicationText(value) {
87
+ this.communicationClaims = setCommunicationText(this.communicationClaims, value);
88
+ return this;
89
+ }
44
90
  /** Returns a deep copy of the current in-memory bundle. */
45
91
  getBundleInMemory() {
46
92
  return cloneBundle(this.bundleInMemory);
47
93
  }
94
+ /** Replaces the attached clinical bundle and resyncs the outer Communication attachment. */
95
+ setAttachedBundle(bundle) {
96
+ validateBundleLike(bundle, this.mode);
97
+ this.bundleInMemory = cloneBundle(bundle);
98
+ this.syncAttachmentFromBundle();
99
+ return this;
100
+ }
101
+ /** Alias of `getBundleInMemory()` with communication wording. */
102
+ getAttachedBundle() {
103
+ return this.getBundleInMemory();
104
+ }
48
105
  /** Returns the active entry index, or null when no entry is selected. */
49
106
  getActiveEntryIndex() {
50
107
  return this.activeEntryIndex;
@@ -230,7 +287,8 @@ export class CommunicationAttachedBundleSession {
230
287
  }
231
288
  /**
232
289
  * DocumentReference helper for bundle-contained attachments linked from
233
- * other clinical resources through `*.contained-documents`.
290
+ * other clinical resources through `*.contained-reference-list`
291
+ * (with `*.contained-documents` kept as legacy compatibility alias).
234
292
  */
235
293
  upsertActiveDocumentReferenceEntry(input) {
236
294
  return this.upsertActiveClaimsResourceEntry(ResourceTypesFhirR4.DocumentReference, input);
@@ -329,7 +387,8 @@ export class CommunicationAttachedBundleSession {
329
387
  }
330
388
  /**
331
389
  * Creates or updates a linked `DocumentReference` entry and stores its
332
- * identifier under the active resource `*.contained-documents` claim.
390
+ * identifier/reference under the active resource
391
+ * `*.contained-reference-list` claim.
333
392
  */
334
393
  addContainedDocumentToActiveEntry(input) {
335
394
  if (this.activeEntryIndex === null) {
@@ -27,6 +27,11 @@ export declare function buildDidcommPayloadFromCommunicationClaims(input: BuildD
27
27
  * one DIDComm-style payload.
28
28
  */
29
29
  export declare function getFirstCommunicationClaimsFromDidcommPayload(payload: IDecodedDidcommPayload): Record<string, unknown>;
30
+ /**
31
+ * Reads canonical communication claims from every `body.data[]` entry of one
32
+ * DIDComm-style payload.
33
+ */
34
+ export declare function getCommunicationClaimsListFromDidcommPayload(payload: IDecodedDidcommPayload): Record<string, unknown>[];
30
35
  /**
31
36
  * Decodes the attached bundle carried in `Communication.content-attachment-data`.
32
37
  */