@the-cascade-protocol/sdk 1.0.0

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 (131) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +164 -0
  3. package/dist/consent/consent-filter.d.ts +21 -0
  4. package/dist/consent/consent-filter.d.ts.map +1 -0
  5. package/dist/consent/consent-filter.js +71 -0
  6. package/dist/consent/consent-filter.js.map +1 -0
  7. package/dist/consent/index.d.ts +2 -0
  8. package/dist/consent/index.d.ts.map +1 -0
  9. package/dist/consent/index.js +2 -0
  10. package/dist/consent/index.js.map +1 -0
  11. package/dist/deserializer/index.d.ts +7 -0
  12. package/dist/deserializer/index.d.ts.map +1 -0
  13. package/dist/deserializer/index.js +7 -0
  14. package/dist/deserializer/index.js.map +1 -0
  15. package/dist/deserializer/turtle-parser.d.ts +47 -0
  16. package/dist/deserializer/turtle-parser.d.ts.map +1 -0
  17. package/dist/deserializer/turtle-parser.js +840 -0
  18. package/dist/deserializer/turtle-parser.js.map +1 -0
  19. package/dist/index.d.ts +42 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +34 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/jsonld/context.d.ts +29 -0
  24. package/dist/jsonld/context.d.ts.map +1 -0
  25. package/dist/jsonld/context.js +95 -0
  26. package/dist/jsonld/context.js.map +1 -0
  27. package/dist/jsonld/converter.d.ts +50 -0
  28. package/dist/jsonld/converter.d.ts.map +1 -0
  29. package/dist/jsonld/converter.js +139 -0
  30. package/dist/jsonld/converter.js.map +1 -0
  31. package/dist/jsonld/index.d.ts +8 -0
  32. package/dist/jsonld/index.d.ts.map +1 -0
  33. package/dist/jsonld/index.js +8 -0
  34. package/dist/jsonld/index.js.map +1 -0
  35. package/dist/models/activity-snapshot.d.ts +49 -0
  36. package/dist/models/activity-snapshot.d.ts.map +1 -0
  37. package/dist/models/activity-snapshot.js +13 -0
  38. package/dist/models/activity-snapshot.js.map +1 -0
  39. package/dist/models/allergy.d.ts +49 -0
  40. package/dist/models/allergy.d.ts.map +1 -0
  41. package/dist/models/allergy.js +13 -0
  42. package/dist/models/allergy.js.map +1 -0
  43. package/dist/models/common.d.ts +174 -0
  44. package/dist/models/common.d.ts.map +1 -0
  45. package/dist/models/common.js +12 -0
  46. package/dist/models/common.js.map +1 -0
  47. package/dist/models/condition.d.ts +59 -0
  48. package/dist/models/condition.d.ts.map +1 -0
  49. package/dist/models/condition.js +13 -0
  50. package/dist/models/condition.js.map +1 -0
  51. package/dist/models/coverage.d.ts +117 -0
  52. package/dist/models/coverage.d.ts.map +1 -0
  53. package/dist/models/coverage.js +16 -0
  54. package/dist/models/coverage.js.map +1 -0
  55. package/dist/models/family-history.d.ts +38 -0
  56. package/dist/models/family-history.d.ts.map +1 -0
  57. package/dist/models/family-history.js +13 -0
  58. package/dist/models/family-history.js.map +1 -0
  59. package/dist/models/health-profile.d.ts +54 -0
  60. package/dist/models/health-profile.d.ts.map +1 -0
  61. package/dist/models/health-profile.js +11 -0
  62. package/dist/models/health-profile.js.map +1 -0
  63. package/dist/models/immunization.d.ts +78 -0
  64. package/dist/models/immunization.d.ts.map +1 -0
  65. package/dist/models/immunization.js +12 -0
  66. package/dist/models/immunization.js.map +1 -0
  67. package/dist/models/index.d.ts +20 -0
  68. package/dist/models/index.d.ts.map +1 -0
  69. package/dist/models/index.js +7 -0
  70. package/dist/models/index.js.map +1 -0
  71. package/dist/models/lab-result.d.ts +83 -0
  72. package/dist/models/lab-result.d.ts.map +1 -0
  73. package/dist/models/lab-result.js +12 -0
  74. package/dist/models/lab-result.js.map +1 -0
  75. package/dist/models/medication.d.ts +144 -0
  76. package/dist/models/medication.d.ts.map +1 -0
  77. package/dist/models/medication.js +13 -0
  78. package/dist/models/medication.js.map +1 -0
  79. package/dist/models/patient-profile.d.ts +171 -0
  80. package/dist/models/patient-profile.d.ts.map +1 -0
  81. package/dist/models/patient-profile.js +14 -0
  82. package/dist/models/patient-profile.js.map +1 -0
  83. package/dist/models/procedure.d.ts +53 -0
  84. package/dist/models/procedure.d.ts.map +1 -0
  85. package/dist/models/procedure.js +12 -0
  86. package/dist/models/procedure.js.map +1 -0
  87. package/dist/models/sleep-snapshot.d.ts +54 -0
  88. package/dist/models/sleep-snapshot.d.ts.map +1 -0
  89. package/dist/models/sleep-snapshot.js +13 -0
  90. package/dist/models/sleep-snapshot.js.map +1 -0
  91. package/dist/models/vital-sign.d.ts +74 -0
  92. package/dist/models/vital-sign.d.ts.map +1 -0
  93. package/dist/models/vital-sign.js +13 -0
  94. package/dist/models/vital-sign.js.map +1 -0
  95. package/dist/pod/index.d.ts +2 -0
  96. package/dist/pod/index.d.ts.map +1 -0
  97. package/dist/pod/index.js +2 -0
  98. package/dist/pod/index.js.map +1 -0
  99. package/dist/pod/pod-builder.d.ts +63 -0
  100. package/dist/pod/pod-builder.d.ts.map +1 -0
  101. package/dist/pod/pod-builder.js +245 -0
  102. package/dist/pod/pod-builder.js.map +1 -0
  103. package/dist/serializer/index.d.ts +8 -0
  104. package/dist/serializer/index.d.ts.map +1 -0
  105. package/dist/serializer/index.js +8 -0
  106. package/dist/serializer/index.js.map +1 -0
  107. package/dist/serializer/turtle-builder.d.ts +93 -0
  108. package/dist/serializer/turtle-builder.d.ts.map +1 -0
  109. package/dist/serializer/turtle-builder.js +204 -0
  110. package/dist/serializer/turtle-builder.js.map +1 -0
  111. package/dist/serializer/turtle-serializer.d.ts +66 -0
  112. package/dist/serializer/turtle-serializer.d.ts.map +1 -0
  113. package/dist/serializer/turtle-serializer.js +404 -0
  114. package/dist/serializer/turtle-serializer.js.map +1 -0
  115. package/dist/validator/index.d.ts +2 -0
  116. package/dist/validator/index.d.ts.map +1 -0
  117. package/dist/validator/index.js +2 -0
  118. package/dist/validator/index.js.map +1 -0
  119. package/dist/validator/validator.d.ts +16 -0
  120. package/dist/validator/validator.d.ts.map +1 -0
  121. package/dist/validator/validator.js +295 -0
  122. package/dist/validator/validator.js.map +1 -0
  123. package/dist/vocabularies/index.d.ts +8 -0
  124. package/dist/vocabularies/index.d.ts.map +1 -0
  125. package/dist/vocabularies/index.js +7 -0
  126. package/dist/vocabularies/index.js.map +1 -0
  127. package/dist/vocabularies/namespaces.d.ts +125 -0
  128. package/dist/vocabularies/namespaces.d.ts.map +1 -0
  129. package/dist/vocabularies/namespaces.js +361 -0
  130. package/dist/vocabularies/namespaces.js.map +1 -0
  131. package/package.json +48 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Cascade Agentic Labs
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # @the-cascade-protocol/sdk
2
+
3
+ TypeScript SDK for the Cascade Protocol -- a developer-first framework for patient-owned health data.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @the-cascade-protocol/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import type { Medication } from '@the-cascade-protocol/sdk';
15
+ import { serialize, deserializeOne, toJsonLd } from '@the-cascade-protocol/sdk';
16
+
17
+ // Create a medication record
18
+ const med: Medication = {
19
+ id: 'urn:uuid:med-001',
20
+ type: 'MedicationRecord',
21
+ medicationName: 'Lisinopril',
22
+ isActive: true,
23
+ dose: '20 mg',
24
+ frequency: 'once daily',
25
+ dataProvenance: 'ClinicalGenerated',
26
+ schemaVersion: '1.3',
27
+ };
28
+
29
+ // Serialize to Turtle (RDF)
30
+ const turtle = serialize(med);
31
+
32
+ // Deserialize back to a typed record
33
+ const parsed = deserializeOne<Medication>(turtle, 'MedicationRecord');
34
+
35
+ // Convert to JSON-LD
36
+ const jsonld = toJsonLd(med);
37
+ ```
38
+
39
+ ## Features
40
+
41
+ - **13 data model interfaces** -- Medication, Condition, Allergy, LabResult, VitalSign, Immunization, Procedure, FamilyHistory, Coverage, PatientProfile, ActivitySnapshot, SleepSnapshot, HealthProfile
42
+ - **Turtle serializer** -- Produces conformance-tested RDF/Turtle output with typed literals, URI references, and RDF lists
43
+ - **Turtle deserializer** -- Zero-dependency parser for Cascade Protocol Turtle documents
44
+ - **JSON-LD conversion** -- Convert records to/from JSON-LD format with bundled context
45
+ - **Vocabulary constants** -- NAMESPACES, TYPE_MAPPING, and PROPERTY_PREDICATES for all Cascade Protocol ontologies
46
+ - **TurtleBuilder** -- Fluent API for constructing custom Turtle documents
47
+
48
+ ## API Reference
49
+
50
+ ### Serialization
51
+
52
+ ```typescript
53
+ import { serialize, serializeMedication } from '@the-cascade-protocol/sdk';
54
+
55
+ // Generic serializer (dispatches by record.type)
56
+ const turtle = serialize(anyRecord);
57
+
58
+ // Type-specific serializers also available
59
+ const turtle = serializeMedication(med);
60
+ ```
61
+
62
+ Available type-specific serializers: `serializeMedication`, `serializeCondition`, `serializeAllergy`, `serializeLabResult`, `serializeVitalSign`, `serializeImmunization`, `serializeProcedure`, `serializeFamilyHistory`, `serializeCoverage`, `serializePatientProfile`, `serializeActivitySnapshot`, `serializeSleepSnapshot`.
63
+
64
+ ### Deserialization
65
+
66
+ ```typescript
67
+ import { deserialize, deserializeOne } from '@the-cascade-protocol/sdk';
68
+ import type { Medication } from '@the-cascade-protocol/sdk';
69
+
70
+ // Parse all medications from a Turtle document
71
+ const meds = deserialize<Medication>(turtleString, 'MedicationRecord');
72
+
73
+ // Parse a single record (returns null if not found)
74
+ const med = deserializeOne<Medication>(turtleString, 'MedicationRecord');
75
+ ```
76
+
77
+ Supported type strings: `MedicationRecord`, `ConditionRecord`, `AllergyRecord`, `LabResultRecord`, `ImmunizationRecord`, `VitalSign`, `ProcedureRecord`, `FamilyHistoryRecord`, `CoverageRecord`, `PatientProfile`, `ActivitySnapshot`, `SleepSnapshot`.
78
+
79
+ ### JSON-LD
80
+
81
+ ```typescript
82
+ import { toJsonLd, fromJsonLd, getContext, CONTEXT_URI } from '@the-cascade-protocol/sdk';
83
+
84
+ // Convert to JSON-LD
85
+ const doc = toJsonLd(medication);
86
+ // { "@context": "https://...", "@id": "urn:uuid:...", "@type": "health:MedicationRecord", ... }
87
+
88
+ // Convert back from JSON-LD
89
+ const record = fromJsonLd<Medication>(doc);
90
+
91
+ // Get the full JSON-LD context object
92
+ const context = getContext();
93
+ ```
94
+
95
+ ### Vocabulary Constants
96
+
97
+ ```typescript
98
+ import { NAMESPACES, TYPE_MAPPING, PROPERTY_PREDICATES } from '@the-cascade-protocol/sdk';
99
+
100
+ // Namespace URIs
101
+ NAMESPACES.cascade // "https://ns.cascadeprotocol.org/core/v1#"
102
+ NAMESPACES.health // "https://ns.cascadeprotocol.org/health/v1#"
103
+ NAMESPACES.clinical // "https://ns.cascadeprotocol.org/clinical/v1#"
104
+
105
+ // Type mappings
106
+ TYPE_MAPPING.medications.rdfType // "health:MedicationRecord"
107
+
108
+ // Property predicates
109
+ PROPERTY_PREDICATES.medicationName // "health:medicationName"
110
+ ```
111
+
112
+ ### TurtleBuilder
113
+
114
+ ```typescript
115
+ import { TurtleBuilder } from '@the-cascade-protocol/sdk';
116
+
117
+ const turtle = new TurtleBuilder()
118
+ .prefix('cascade', 'https://ns.cascadeprotocol.org/core/v1#')
119
+ .prefix('health', 'https://ns.cascadeprotocol.org/health/v1#')
120
+ .prefix('xsd', 'http://www.w3.org/2001/XMLSchema#')
121
+ .subject('<urn:uuid:custom-001>')
122
+ .type('health:MedicationRecord')
123
+ .literal('health:medicationName', 'Aspirin')
124
+ .boolean('health:isActive', true)
125
+ .dateTime('health:startDate', '2024-01-01T00:00:00Z')
126
+ .done()
127
+ .build();
128
+ ```
129
+
130
+ ## Data Models
131
+
132
+ All models extend the `CascadeRecord` base interface:
133
+
134
+ ```typescript
135
+ interface CascadeRecord {
136
+ id: string; // URN UUID (e.g., "urn:uuid:...")
137
+ type: string; // RDF type name
138
+ dataProvenance: ProvenanceType; // Source classification
139
+ schemaVersion: string; // Version string (e.g., "1.3")
140
+ sourceRecordId?: string; // Link to source system record
141
+ notes?: string; // Free-text notes
142
+ }
143
+ ```
144
+
145
+ ## Conformance
146
+
147
+ This SDK passes all Cascade Protocol conformance test fixtures. The serializer produces output that matches the expected Turtle format for all standard record types. Conformance fixtures are maintained in the [conformance/fixtures](../conformance/fixtures/) directory.
148
+
149
+ ## Development
150
+
151
+ ```bash
152
+ # Build
153
+ npm run build
154
+
155
+ # Run tests
156
+ npm test
157
+
158
+ # Watch mode
159
+ npm run test:watch
160
+ ```
161
+
162
+ ## License
163
+
164
+ Apache-2.0
@@ -0,0 +1,21 @@
1
+ import type { ProvenanceType } from '../models/common.js';
2
+ import type { HealthProfile } from '../models/health-profile.js';
3
+ export type ConsentCategory = 'medications' | 'conditions' | 'allergies' | 'labResults' | 'vitalSigns' | 'immunizations' | 'procedures' | 'familyHistory' | 'coverage' | 'patientProfile' | 'activitySnapshots' | 'sleepSnapshots';
4
+ export interface ConsentRule {
5
+ readonly category: ConsentCategory;
6
+ readonly allowed: boolean;
7
+ readonly provenanceFilter?: readonly ProvenanceType[];
8
+ }
9
+ export interface ConsentPolicy {
10
+ readonly rules: readonly ConsentRule[];
11
+ readonly defaultAllow: boolean;
12
+ }
13
+ /** Apply a consent policy to a HealthProfile, returning a new profile with only allowed records. */
14
+ export declare function applyConsent(profile: HealthProfile, policy: ConsentPolicy): HealthProfile;
15
+ /** Create a consent policy that shares only clinical data (no device/wellness). */
16
+ export declare function clinicalOnlyPolicy(): ConsentPolicy;
17
+ /** Create a consent policy that shares everything. */
18
+ export declare function fullAccessPolicy(): ConsentPolicy;
19
+ /** Create a consent policy that shares nothing. */
20
+ export declare function noAccessPolicy(): ConsentPolicy;
21
+ //# sourceMappingURL=consent-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-filter.d.ts","sourceRoot":"","sources":["../../src/consent/consent-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAIjE,MAAM,MAAM,eAAe,GACvB,aAAa,GACb,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,YAAY,GACZ,eAAe,GACf,UAAU,GACV,gBAAgB,GAChB,mBAAmB,GACnB,gBAAgB,CAAC;AAErB,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;CACvD;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IACvC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAsBD,oGAAoG;AACpG,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,GAAG,aAAa,CA6BzF;AAED,mFAAmF;AACnF,wBAAgB,kBAAkB,IAAI,aAAa,CASlD;AAED,sDAAsD;AACtD,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED,mDAAmD;AACnD,wBAAgB,cAAc,IAAI,aAAa,CAK9C"}
@@ -0,0 +1,71 @@
1
+ // ─── Internal Helpers ───────────────────────────────────────────────────────
2
+ function findRule(policy, category) {
3
+ return policy.rules.find((r) => r.category === category);
4
+ }
5
+ function isAllowed(policy, category) {
6
+ const rule = findRule(policy, category);
7
+ if (!rule)
8
+ return policy.defaultAllow;
9
+ return rule.allowed;
10
+ }
11
+ function getProvenanceFilter(policy, category) {
12
+ const rule = findRule(policy, category);
13
+ if (!rule)
14
+ return undefined;
15
+ return rule.provenanceFilter;
16
+ }
17
+ // ─── Public API ─────────────────────────────────────────────────────────────
18
+ /** Apply a consent policy to a HealthProfile, returning a new profile with only allowed records. */
19
+ export function applyConsent(profile, policy) {
20
+ const provenanceFilterFor = (category) => getProvenanceFilter(policy, category);
21
+ const filterByProvenance = (items, category) => {
22
+ if (!isAllowed(policy, category))
23
+ return [];
24
+ const pFilter = provenanceFilterFor(category);
25
+ if (!pFilter)
26
+ return [...items];
27
+ return items.filter((item) => pFilter.includes(item.dataProvenance));
28
+ };
29
+ return {
30
+ patientProfile: isAllowed(policy, 'patientProfile')
31
+ ? profile.patientProfile
32
+ : undefined,
33
+ medications: filterByProvenance(profile.medications, 'medications'),
34
+ conditions: filterByProvenance(profile.conditions, 'conditions'),
35
+ allergies: filterByProvenance(profile.allergies, 'allergies'),
36
+ labResults: filterByProvenance(profile.labResults, 'labResults'),
37
+ vitalSigns: filterByProvenance(profile.vitalSigns, 'vitalSigns'),
38
+ immunizations: filterByProvenance(profile.immunizations, 'immunizations'),
39
+ procedures: filterByProvenance(profile.procedures, 'procedures'),
40
+ familyHistory: filterByProvenance(profile.familyHistory, 'familyHistory'),
41
+ coverage: filterByProvenance(profile.coverage, 'coverage'),
42
+ activitySnapshots: filterByProvenance(profile.activitySnapshots, 'activitySnapshots'),
43
+ sleepSnapshots: filterByProvenance(profile.sleepSnapshots, 'sleepSnapshots'),
44
+ };
45
+ }
46
+ /** Create a consent policy that shares only clinical data (no device/wellness). */
47
+ export function clinicalOnlyPolicy() {
48
+ return {
49
+ defaultAllow: true,
50
+ rules: [
51
+ { category: 'activitySnapshots', allowed: false },
52
+ { category: 'sleepSnapshots', allowed: false },
53
+ { category: 'vitalSigns', allowed: true, provenanceFilter: ['ClinicalGenerated', 'EHRVerified'] },
54
+ ],
55
+ };
56
+ }
57
+ /** Create a consent policy that shares everything. */
58
+ export function fullAccessPolicy() {
59
+ return {
60
+ defaultAllow: true,
61
+ rules: [],
62
+ };
63
+ }
64
+ /** Create a consent policy that shares nothing. */
65
+ export function noAccessPolicy() {
66
+ return {
67
+ defaultAllow: false,
68
+ rules: [],
69
+ };
70
+ }
71
+ //# sourceMappingURL=consent-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-filter.js","sourceRoot":"","sources":["../../src/consent/consent-filter.ts"],"names":[],"mappings":"AA8BA,+EAA+E;AAE/E,SAAS,QAAQ,CAAC,MAAqB,EAAE,QAAyB;IAChE,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,SAAS,CAAC,MAAqB,EAAE,QAAyB;IACjE,MAAM,IAA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K,EAAE,EAAE;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { applyConsent, clinicalOnlyPolicy, fullAccessPolicy, noAccessPolicy, type ConsentCategory, type ConsentRule, type ConsentPolicy, } from './consent-filter.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { applyConsent, clinicalOnlyPolicy, fullAccessPolicy, noAccessPolicy, } from './consent-filter.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GAIf,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Re-exports for the Turtle deserializer module.
3
+ *
4
+ * @module deserializer
5
+ */
6
+ export { deserialize, deserializeOne } from './turtle-parser.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/deserializer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Re-exports for the Turtle deserializer module.
3
+ *
4
+ * @module deserializer
5
+ */
6
+ export { deserialize, deserializeOne } from './turtle-parser.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/deserializer/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Zero-dependency Turtle parser for deserializing Cascade Protocol records.
3
+ *
4
+ * Uses regex-based parsing to convert Turtle (Terse RDF Triple Language)
5
+ * content back into typed Cascade Protocol model objects.
6
+ *
7
+ * Supports:
8
+ * - @prefix declarations
9
+ * - Subject-predicate-object triples
10
+ * - Typed literals (xsd:dateTime, xsd:date, xsd:integer, xsd:double)
11
+ * - URI references (angle-bracket and prefixed forms)
12
+ * - Boolean literals
13
+ * - RDF lists `( item1 item2 ... )`
14
+ * - Blank nodes `[ ... ]`
15
+ * - Triple-quoted long literals
16
+ * - Multi-value predicates (repeated predicate with different objects)
17
+ *
18
+ * @module deserializer
19
+ */
20
+ import type { CascadeRecord } from '../models/common.js';
21
+ /**
22
+ * Parse Turtle content and return typed records matching the specified type.
23
+ *
24
+ * @param turtle - Turtle document content
25
+ * @param type - Record type string (e.g., "MedicationRecord", "VitalSign", "PatientProfile")
26
+ * @returns Array of parsed records of the specified type
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * import { deserialize } from '@the-cascade-protocol/sdk';
31
+ * import type { Medication } from '@the-cascade-protocol/sdk';
32
+ *
33
+ * const meds = deserialize<Medication>(turtleString, 'MedicationRecord');
34
+ * ```
35
+ */
36
+ export declare function deserialize<T extends CascadeRecord>(turtle: string, type: string): T[];
37
+ /**
38
+ * Parse a single record from Turtle content.
39
+ *
40
+ * Returns the first record matching the specified type, or `null` if none found.
41
+ *
42
+ * @param turtle - Turtle document content
43
+ * @param type - Record type string
44
+ * @returns The parsed record, or null
45
+ */
46
+ export declare function deserializeOne<T extends CascadeRecord>(turtle: string, type: string): T | null;
47
+ //# sourceMappingURL=turtle-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turtle-parser.d.ts","sourceRoot":"","sources":["../../src/deserializer/turtle-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAm3BzD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,CAyBtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAG9F"}