-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-basic-usage.ts
More file actions
193 lines (148 loc) · 3.36 KB
/
01-basic-usage.ts
File metadata and controls
193 lines (148 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
* Basic usage example without type extensions
* Shows backward compatibility with existing code
*/
import {
type AtomicContext,
AtomicSystem,
type Audit,
type CanonicalManager,
type FHIRPathEvaluator,
type Logger,
type ResourceRepository,
type Terminology,
type Validator,
} from "../src/index.js";
// Simple mock implementations
class SimpleValidator implements Validator {
dependencies = [];
capabilities = ["validate"];
async init() {
console.log("Validator initialized");
}
async destroy() {}
validate() {
return { valid: true, errors: [] };
}
validateResource() {
return { valid: true, errors: [] };
}
}
class SimpleRepository implements ResourceRepository {
dependencies = [];
capabilities = ["repository"];
async init() {
console.log("Repository initialized");
}
async destroy() {}
async create(opts: any) {
return { id: "123", ...opts.resource };
}
async read() {
return { id: "123" };
}
async update(opts: any) {
return opts.resource;
}
async delete() {}
async search() {
return [];
}
async patch(opts: any) {
return opts.patch;
}
async history() {
return [];
}
async typeHistory() {
return [];
}
async resolve() {
return { id: "123" };
}
async bulkResolve() {
return [];
}
}
class SimpleTerminology implements Terminology {
dependencies = [];
capabilities = ["terminology"];
async init() {}
async destroy() {}
async lookup() {
return { code: "test", display: "Test" };
}
async expand() {
return { contains: [] };
}
async validateCode() {
return { result: true };
}
}
class SimpleFHIRPath implements FHIRPathEvaluator {
dependencies = [];
capabilities = ["fhirpath"];
async init() {}
async destroy() {}
async evaluate() {
return [];
}
async compile(opts: any) {
return { expression: opts.expression, compiled: {} };
}
async analyze(opts: any) {
return { expression: opts.expression, valid: true };
}
}
class SimpleCanonicalManager implements CanonicalManager {
dependencies = [];
capabilities = ["canonicals"];
async init() {}
async destroy() {}
async resolve() {
return { url: "http://example.com", version: "1.0.0" };
}
async search() {
return [];
}
}
class SimpleAudit implements Audit {
dependencies = [];
capabilities = ["audit"];
async init() {}
async destroy() {}
async audit() {}
}
class SimpleLogger implements Logger {
dependencies = [];
capabilities = ["logger"];
async init() {}
async destroy() {}
async log(opts: any) {
console.log(`[${opts.level}] ${opts.message}`);
}
}
// Initialize the system
const context = await AtomicSystem({
validator: new SimpleValidator(),
repository: new SimpleRepository(),
terminology: new SimpleTerminology(),
fhirpath: new SimpleFHIRPath(),
canonicals: new SimpleCanonicalManager(),
audit: new SimpleAudit(),
logger: new SimpleLogger(),
});
console.log("✅ Atomic system initialized!");
console.log("Available services:", Object.keys(context));
// Use the system
const patient = await context.repository.create({
resourceType: "Patient",
resource: {
name: [{ family: "Doe", given: ["John"] }],
},
});
console.log("Created patient:", patient);
const validation = context.validator.validate({
resource: patient,
});
console.log("Validation result:", validation);