gdc-common-utils-ts 2.0.18 → 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 (185) hide show
  1. package/README.md +18 -1
  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.d.ts +11 -0
  23. package/dist/examples/bundle-didcomm-payload.js +15 -0
  24. package/dist/examples/communication-attached-bundle-session.js +28 -27
  25. package/dist/examples/communication-didcomm-payload.d.ts +39 -0
  26. package/dist/examples/communication-didcomm-payload.js +44 -0
  27. package/dist/examples/consent-access.js +2 -1
  28. package/dist/examples/employee.d.ts +21 -0
  29. package/dist/examples/employee.js +21 -0
  30. package/dist/examples/index.d.ts +4 -0
  31. package/dist/examples/index.js +4 -0
  32. package/dist/examples/individual-controller.d.ts +27 -0
  33. package/dist/examples/individual-controller.js +28 -1
  34. package/dist/examples/inter-tenant-access-contract.js +3 -2
  35. package/dist/examples/ips-bundle.js +17 -16
  36. package/dist/examples/lifecycle.js +13 -11
  37. package/dist/examples/profile-manager-mem.d.ts +45 -0
  38. package/dist/examples/profile-manager-mem.js +30 -0
  39. package/dist/examples/related-person.d.ts +14 -0
  40. package/dist/examples/related-person.js +18 -4
  41. package/dist/examples/shared.d.ts +13 -3
  42. package/dist/examples/shared.js +14 -4
  43. package/dist/examples/vital-signs.js +1 -1
  44. package/dist/examples/wallet-mem.d.ts +38 -0
  45. package/dist/examples/wallet-mem.js +42 -0
  46. package/dist/index.d.ts +1 -0
  47. package/dist/index.js +1 -0
  48. package/dist/interfaces/IProfileOutboxRepository.d.ts +36 -0
  49. package/dist/interfaces/IProfileOutboxRepository.js +2 -0
  50. package/dist/interfaces/IWallet.d.ts +74 -0
  51. package/dist/interfaces/IWallet.js +2 -0
  52. package/dist/interfaces/IWalletQueue.d.ts +30 -0
  53. package/dist/interfaces/IWalletQueue.js +2 -0
  54. package/dist/interfaces/index.d.ts +8 -0
  55. package/dist/interfaces/index.js +8 -0
  56. package/dist/models/authority-resolution.d.ts +56 -0
  57. package/dist/models/authority-resolution.js +2 -0
  58. package/dist/models/bundle-editor-types.d.ts +89 -0
  59. package/dist/models/bundle-editor-types.js +45 -0
  60. package/dist/models/bundle.d.ts +5 -0
  61. package/dist/models/communication-attached-bundle-session.d.ts +195 -0
  62. package/dist/models/communication-attached-bundle-session.js +36 -0
  63. package/dist/models/confidential-storage.d.ts +2 -1
  64. package/dist/models/consent-rule.d.ts +11 -1
  65. package/dist/models/consent-rule.js +9 -1
  66. package/dist/models/index.d.ts +5 -0
  67. package/dist/models/index.js +5 -0
  68. package/dist/models/individual-onboarding.d.ts +18 -0
  69. package/dist/models/interoperable-claims/allergy-intolerance-claims.d.ts +12 -1
  70. package/dist/models/interoperable-claims/allergy-intolerance-claims.js +12 -1
  71. package/dist/models/interoperable-claims/condition-claims.d.ts +12 -1
  72. package/dist/models/interoperable-claims/condition-claims.js +12 -1
  73. package/dist/models/interoperable-claims/diagnostic-report-claims.d.ts +14 -4
  74. package/dist/models/interoperable-claims/diagnostic-report-claims.js +13 -3
  75. package/dist/models/interoperable-claims/document-reference-claims.d.ts +1 -0
  76. package/dist/models/interoperable-claims/document-reference-claims.js +3 -0
  77. package/dist/models/interoperable-claims/medication-statement-claims.d.ts +17 -0
  78. package/dist/models/interoperable-claims/medication-statement-claims.js +17 -0
  79. package/dist/models/profile-manager.d.ts +85 -0
  80. package/dist/models/profile-manager.js +2 -0
  81. package/dist/models/wallet.d.ts +59 -0
  82. package/dist/models/wallet.js +22 -0
  83. package/dist/utils/allergy-intolerance-entry-editor.d.ts +51 -0
  84. package/dist/utils/allergy-intolerance-entry-editor.js +55 -0
  85. package/dist/utils/authority-resolution.d.ts +37 -0
  86. package/dist/utils/authority-resolution.js +112 -0
  87. package/dist/utils/backend-message-manager-mem.d.ts +78 -0
  88. package/dist/utils/backend-message-manager-mem.js +238 -0
  89. package/dist/utils/bundle-didcomm-payload.d.ts +29 -0
  90. package/dist/utils/bundle-didcomm-payload.js +49 -0
  91. package/dist/utils/bundle-document-builder.d.ts +1 -0
  92. package/dist/utils/bundle-document-builder.js +134 -14
  93. package/dist/utils/bundle-editor-core.d.ts +181 -0
  94. package/dist/utils/bundle-editor-core.js +467 -0
  95. package/dist/utils/bundle-editor-helpers.d.ts +53 -0
  96. package/dist/utils/bundle-editor-helpers.js +146 -0
  97. package/dist/utils/bundle-editor-registry.d.ts +6 -0
  98. package/dist/utils/bundle-editor-registry.js +14 -0
  99. package/dist/utils/bundle-editor.d.ts +21 -722
  100. package/dist/utils/bundle-editor.js +21 -1601
  101. package/dist/utils/bundle-entry-editor.d.ts +96 -0
  102. package/dist/utils/bundle-entry-editor.js +305 -0
  103. package/dist/utils/bundle-query.d.ts +1 -0
  104. package/dist/utils/bundle-query.js +12 -3
  105. package/dist/utils/bundle-reader.d.ts +48 -0
  106. package/dist/utils/bundle-reader.js +175 -1
  107. package/dist/utils/care-plan-entry-editor.d.ts +43 -0
  108. package/dist/utils/care-plan-entry-editor.js +47 -0
  109. package/dist/utils/client-assertion.d.ts +38 -0
  110. package/dist/utils/client-assertion.js +113 -0
  111. package/dist/utils/clinical-impression-entry-editor.d.ts +43 -0
  112. package/dist/utils/clinical-impression-entry-editor.js +47 -0
  113. package/dist/utils/clinical-resource-entry-editor.d.ts +123 -0
  114. package/dist/utils/clinical-resource-entry-editor.js +296 -0
  115. package/dist/utils/communication-attached-bundle-session-helpers.d.ts +54 -0
  116. package/dist/utils/communication-attached-bundle-session-helpers.js +519 -0
  117. package/dist/utils/communication-attached-bundle-session.d.ts +87 -304
  118. package/dist/utils/communication-attached-bundle-session.js +175 -841
  119. package/dist/utils/communication-consent-access-editor.d.ts +85 -0
  120. package/dist/utils/communication-consent-access-editor.js +244 -0
  121. package/dist/utils/communication-didcomm-payload.d.ts +38 -0
  122. package/dist/utils/communication-didcomm-payload.js +85 -0
  123. package/dist/utils/communication-document-reference.d.ts +23 -0
  124. package/dist/utils/communication-document-reference.js +89 -0
  125. package/dist/utils/communication-editor.d.ts +53 -0
  126. package/dist/utils/communication-editor.js +97 -0
  127. package/dist/utils/condition-entry-editor.d.ts +30 -0
  128. package/dist/utils/condition-entry-editor.js +34 -0
  129. package/dist/utils/consent-claim-helpers.d.ts +4 -0
  130. package/dist/utils/consent-claim-helpers.js +15 -1
  131. package/dist/utils/coverage-entry-editor.d.ts +51 -0
  132. package/dist/utils/coverage-entry-editor.js +55 -0
  133. package/dist/utils/device-entry-editor.d.ts +59 -0
  134. package/dist/utils/device-entry-editor.js +63 -0
  135. package/dist/utils/device-use-statement-entry-editor.d.ts +43 -0
  136. package/dist/utils/device-use-statement-entry-editor.js +47 -0
  137. package/dist/utils/diagnostic-report-entry-editor.d.ts +74 -0
  138. package/dist/utils/diagnostic-report-entry-editor.js +136 -0
  139. package/dist/utils/did.d.ts +8 -0
  140. package/dist/utils/did.js +22 -0
  141. package/dist/utils/document-reference-entry-editor.d.ts +62 -0
  142. package/dist/utils/document-reference-entry-editor.js +66 -0
  143. package/dist/utils/employee-entry-editor.d.ts +36 -0
  144. package/dist/utils/employee-entry-editor.js +88 -0
  145. package/dist/utils/employee.d.ts +1 -0
  146. package/dist/utils/employee.js +2 -1
  147. package/dist/utils/encounter-entry-editor.d.ts +51 -0
  148. package/dist/utils/encounter-entry-editor.js +55 -0
  149. package/dist/utils/flag-entry-editor.d.ts +47 -0
  150. package/dist/utils/flag-entry-editor.js +51 -0
  151. package/dist/utils/immunization-entry-editor.d.ts +87 -0
  152. package/dist/utils/immunization-entry-editor.js +169 -0
  153. package/dist/utils/index.d.ts +15 -0
  154. package/dist/utils/index.js +15 -0
  155. package/dist/utils/individual-onboarding-acceptance-credential.d.ts +35 -0
  156. package/dist/utils/individual-onboarding-acceptance-credential.js +55 -0
  157. package/dist/utils/individual-smart.d.ts +59 -0
  158. package/dist/utils/individual-smart.js +135 -0
  159. package/dist/utils/medication-statement-entry-editor.d.ts +90 -0
  160. package/dist/utils/medication-statement-entry-editor.js +94 -0
  161. package/dist/utils/observation-component-entry-editor.d.ts +57 -0
  162. package/dist/utils/observation-component-entry-editor.js +105 -0
  163. package/dist/utils/observation-entry-editor.d.ts +29 -0
  164. package/dist/utils/observation-entry-editor.js +68 -0
  165. package/dist/utils/procedure-entry-editor.d.ts +71 -0
  166. package/dist/utils/procedure-entry-editor.js +75 -0
  167. package/dist/utils/professional-smart.d.ts +87 -0
  168. package/dist/utils/professional-smart.js +118 -4
  169. package/dist/utils/profile-manager-mem.d.ts +69 -0
  170. package/dist/utils/profile-manager-mem.js +79 -0
  171. package/dist/utils/profile-outbox-memory-repository.d.ts +34 -0
  172. package/dist/utils/profile-outbox-memory-repository.js +57 -0
  173. package/dist/utils/same-as.d.ts +40 -0
  174. package/dist/utils/same-as.js +72 -0
  175. package/dist/utils/unified-health-id.d.ts +51 -0
  176. package/dist/utils/unified-health-id.js +92 -0
  177. package/dist/utils/vital-sign-day-batch.d.ts +25 -0
  178. package/dist/utils/vital-sign-day-batch.js +115 -0
  179. package/dist/utils/vital-sign-entry-editor.d.ts +61 -0
  180. package/dist/utils/vital-sign-entry-editor.js +152 -0
  181. package/dist/utils/wallet-mem.d.ts +93 -0
  182. package/dist/utils/wallet-mem.js +277 -0
  183. package/dist/utils/wallet-memory-queue.d.ts +32 -0
  184. package/dist/utils/wallet-memory-queue.js +82 -0
  185. 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
+ */
@@ -0,0 +1,54 @@
1
+ import { type HealthcareCanonicalSectionFamily } from '../constants/healthcare';
2
+ import type { BundleEntry, BundleEntryResource, BundleJsonApi } from '../models/bundle';
3
+ import type { CommunicationAttachedBundleSessionMode, ConsentEditorClassifiedActorRole, ConsentEditorClassifiedActors, ConsentEditorClassifiedOrganization, ConsentEditorClassifiedPurpose, ConsentEditorClassifiedRole, ConsentEditorClassifiedRoles, ConsentEditorClassifiedTarget, ConsentViewModel, ConsentEditorScopeCode, ConsentEditorTargetKind } from '../models/communication-attached-bundle-session';
4
+ export declare const CSV_SEPARATOR = ",";
5
+ export declare function ensureEntryResource(entry: BundleEntry, mode: CommunicationAttachedBundleSessionMode): BundleEntryResource;
6
+ export declare function validateBundleLike(bundle: BundleJsonApi<BundleEntry>, mode: CommunicationAttachedBundleSessionMode): void;
7
+ export declare function createEmptyBundle(): BundleJsonApi<BundleEntry>;
8
+ export declare function encodeBundleToBase64(bundle: BundleJsonApi<BundleEntry>): string;
9
+ export declare function cloneBundle(bundle: BundleJsonApi<BundleEntry>): BundleJsonApi<BundleEntry>;
10
+ export declare function cloneEntry(entry: BundleEntry): BundleEntry;
11
+ export declare function cloneUnknownValue<T>(value: T): T;
12
+ export declare function asTrimmedString(value: unknown): string;
13
+ export declare function resolveContainedDocumentsClaimKey(resourceType: string): string;
14
+ export declare function resolveSubjectFromClaims(claims: Record<string, unknown>): string;
15
+ /**
16
+ * Resolves the canonical resource-scoped identifier used for upsert matching.
17
+ */
18
+ export declare function resolveBundleEntryIdentifier(claims: Record<string, unknown>): string;
19
+ /**
20
+ * Resolves the stable entry id value stored in `BundleEntry.id`.
21
+ */
22
+ export declare function resolveBundleEntryCanonicalIdValue(claims: Record<string, unknown>): string;
23
+ export declare function setIfMissing(target: Record<string, unknown>, key: string, value: unknown): void;
24
+ export declare function runtimeUuid(prefix: string): string;
25
+ export declare function splitCsv(value: unknown): string[];
26
+ export declare function normalizeCsvValues(values: readonly unknown[]): string[];
27
+ export declare function buildClassifiedConsentTarget(kind: ConsentEditorTargetKind, code: string, scopeCodes: readonly ConsentEditorScopeCode[], sectionFamily?: HealthcareCanonicalSectionFamily): ConsentEditorClassifiedTarget;
28
+ export declare function buildSectionCatalogOptions(sectionKind: HealthcareCanonicalSectionFamily): ConsentEditorClassifiedTarget[];
29
+ export declare function normalizeScopeCodes(scopeCodes: readonly ConsentEditorScopeCode[]): ConsentEditorScopeCode[];
30
+ export declare function normalizeClassifiedTargets(targets: readonly ConsentEditorClassifiedTarget[]): ConsentEditorClassifiedTarget[];
31
+ export declare function resolveConsentTargetDisplay(kind: ConsentEditorTargetKind, code: string): string | undefined;
32
+ export declare function resolveConsentScopeDisplay(scopeCode: ConsentEditorScopeCode): string;
33
+ export declare function resolveConsentPurposeDisplay(code: string): string;
34
+ export declare function looksLikeEmailToken(value: string): boolean;
35
+ export declare function looksLikePhoneToken(value: string): boolean;
36
+ export declare function looksLikeJurisdictionToken(value: string): boolean;
37
+ export declare function parseDidWebOrganizationToken(value: string): ConsentEditorClassifiedOrganization | undefined;
38
+ export declare function parseConsentActorRole(value: string): ConsentEditorClassifiedActorRole | undefined;
39
+ export declare function flattenClassifiedActors(classifiedActors: ConsentEditorClassifiedActors): string[];
40
+ export declare function serializeClassifiedOrganization(organization: ConsentEditorClassifiedOrganization): string;
41
+ export declare function flattenClassifiedRoles(classifiedRoles: ConsentEditorClassifiedRoles): string[];
42
+ export declare function serializeClassifiedRole(role: ConsentEditorClassifiedRole): string;
43
+ export declare function flattenClassifiedTargets(classifiedTargets: readonly ConsentEditorClassifiedTarget[]): Readonly<{
44
+ coreSections: readonly string[];
45
+ kindOfDocuments: readonly string[];
46
+ typeOfServices: readonly string[];
47
+ subjectMatterDomains: readonly string[];
48
+ resourceTypes: readonly string[];
49
+ }>;
50
+ export declare function classifyConsentTargetsFromClaims(claims: Record<string, unknown>): ConsentEditorClassifiedTarget[];
51
+ export declare function classifyConsentPurposes(purposeCodes: readonly string[]): ConsentEditorClassifiedPurpose[];
52
+ export declare function classifyConsentRoles(roleTokens: readonly string[]): ConsentEditorClassifiedRoles;
53
+ export declare function classifyConsentActors(actorTokens: readonly string[], actorRoleToken?: string): ConsentEditorClassifiedActors;
54
+ export declare function buildConsentViewModel(activeEntry: BundleEntry | null, decision: string, classifiedActors: ConsentEditorClassifiedActors, classifiedRoles: ConsentEditorClassifiedRoles, classifiedPurposes: readonly ConsentEditorClassifiedPurpose[], classifiedTargets: readonly ConsentEditorClassifiedTarget[]): ConsentViewModel;