@fhir-dsl/fhirpath 0.6.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.
- package/LICENSE +21 -0
- package/dist/index.cjs +1133 -0
- package/dist/index.d.cts +542 -0
- package/dist/index.d.ts +542 -0
- package/dist/index.js +1102 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
import { Quantity, CodeableConcept, Coding, HumanName, Identifier, Reference, Period, Range, Ratio, Resource } from '@fhir-dsl/types';
|
|
2
|
+
|
|
3
|
+
/** Strip array wrapper and undefined/null to get the element type */
|
|
4
|
+
type Unwrap<T> = NonNullable<T extends readonly (infer U)[] ? U : T>;
|
|
5
|
+
/** True when the unwrapped type is a JS primitive (terminal — no further navigation) */
|
|
6
|
+
type IsPrimitive<T> = Unwrap<T> extends string | number | boolean ? true : false;
|
|
7
|
+
/** String keys available for navigation on the unwrapped type */
|
|
8
|
+
type NavKeys<T> = string & keyof Unwrap<T>;
|
|
9
|
+
interface FhirTypeMap {
|
|
10
|
+
Quantity: Quantity;
|
|
11
|
+
CodeableConcept: CodeableConcept;
|
|
12
|
+
Coding: Coding;
|
|
13
|
+
HumanName: HumanName;
|
|
14
|
+
Identifier: Identifier;
|
|
15
|
+
Reference: Reference;
|
|
16
|
+
Period: Period;
|
|
17
|
+
Range: Range;
|
|
18
|
+
Ratio: Ratio;
|
|
19
|
+
string: string;
|
|
20
|
+
String: string;
|
|
21
|
+
boolean: boolean;
|
|
22
|
+
Boolean: boolean;
|
|
23
|
+
integer: number;
|
|
24
|
+
Integer: number;
|
|
25
|
+
decimal: number;
|
|
26
|
+
Decimal: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A predicate expression node used inside where(), select(), all(), etc.
|
|
30
|
+
* Supports navigation, comparison operators, and boolean logic.
|
|
31
|
+
*/
|
|
32
|
+
type FhirPathPredicate<T> = PredicateOps<T> & (IsPrimitive<T> extends true ? unknown : {
|
|
33
|
+
readonly [K in NavKeys<T>]: FhirPathPredicate<Unwrap<T>[K]>;
|
|
34
|
+
});
|
|
35
|
+
interface PredicateOps<T> {
|
|
36
|
+
/** Equals comparison */
|
|
37
|
+
eq(value: Unwrap<T> | FhirPathPredicate<Unwrap<T>>): FhirPathPredicate<boolean>;
|
|
38
|
+
/** Not equals comparison */
|
|
39
|
+
neq(value: Unwrap<T> | FhirPathPredicate<Unwrap<T>>): FhirPathPredicate<boolean>;
|
|
40
|
+
/** Less than comparison */
|
|
41
|
+
lt(value: Unwrap<T> | FhirPathPredicate<Unwrap<T>>): FhirPathPredicate<boolean>;
|
|
42
|
+
/** Greater than comparison */
|
|
43
|
+
gt(value: Unwrap<T> | FhirPathPredicate<Unwrap<T>>): FhirPathPredicate<boolean>;
|
|
44
|
+
/** Less than or equal comparison */
|
|
45
|
+
lte(value: Unwrap<T> | FhirPathPredicate<Unwrap<T>>): FhirPathPredicate<boolean>;
|
|
46
|
+
/** Greater than or equal comparison */
|
|
47
|
+
gte(value: Unwrap<T> | FhirPathPredicate<Unwrap<T>>): FhirPathPredicate<boolean>;
|
|
48
|
+
/** Boolean AND */
|
|
49
|
+
and(other: FhirPathPredicate<boolean>): FhirPathPredicate<boolean>;
|
|
50
|
+
/** Boolean OR */
|
|
51
|
+
or(other: FhirPathPredicate<boolean>): FhirPathPredicate<boolean>;
|
|
52
|
+
/** Boolean XOR */
|
|
53
|
+
xor(other: FhirPathPredicate<boolean>): FhirPathPredicate<boolean>;
|
|
54
|
+
/** Boolean NOT */
|
|
55
|
+
not(): FhirPathPredicate<boolean>;
|
|
56
|
+
/** Boolean IMPLIES */
|
|
57
|
+
implies(other: FhirPathPredicate<boolean>): FhirPathPredicate<boolean>;
|
|
58
|
+
/** String contains */
|
|
59
|
+
contains(substring: string): FhirPathPredicate<boolean>;
|
|
60
|
+
/** String starts with */
|
|
61
|
+
startsWith(prefix: string): FhirPathPredicate<boolean>;
|
|
62
|
+
/** String ends with */
|
|
63
|
+
endsWith(suffix: string): FhirPathPredicate<boolean>;
|
|
64
|
+
/** Regex match */
|
|
65
|
+
matches(regex: string): FhirPathPredicate<boolean>;
|
|
66
|
+
/** Existence check */
|
|
67
|
+
exists(): FhirPathPredicate<boolean>;
|
|
68
|
+
/** Empty check */
|
|
69
|
+
empty(): FhirPathPredicate<boolean>;
|
|
70
|
+
/** Count */
|
|
71
|
+
count(): FhirPathPredicate<number>;
|
|
72
|
+
/** Type check */
|
|
73
|
+
is(typeName: string): FhirPathPredicate<boolean>;
|
|
74
|
+
/** Type cast */
|
|
75
|
+
as(typeName: string): FhirPathPredicate<T>;
|
|
76
|
+
}
|
|
77
|
+
interface FhirPathCoreOps<T> {
|
|
78
|
+
/** Return the compiled FHIRPath expression string */
|
|
79
|
+
compile(): string;
|
|
80
|
+
/** Evaluate the expression against a resource, returning a collection */
|
|
81
|
+
evaluate(resource: unknown): Unwrap<T>[];
|
|
82
|
+
}
|
|
83
|
+
interface FhirPathExistenceOps<T> {
|
|
84
|
+
/** Filter by field equality (legacy shorthand) */
|
|
85
|
+
where<K extends NavKeys<T>>(field: K, value: string): FhirPathExpr<T>;
|
|
86
|
+
/** Filter by expression predicate */
|
|
87
|
+
where(predicate: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<boolean>): FhirPathExpr<T>;
|
|
88
|
+
/** True if collection is non-empty, or if any item matches criteria */
|
|
89
|
+
exists(): FhirPathExpr<boolean>;
|
|
90
|
+
exists(predicate: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<boolean>): FhirPathExpr<boolean>;
|
|
91
|
+
/** True if all items match criteria */
|
|
92
|
+
all(predicate: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<boolean>): FhirPathExpr<boolean>;
|
|
93
|
+
/** True if all items are true */
|
|
94
|
+
allTrue(): FhirPathExpr<boolean>;
|
|
95
|
+
/** True if any item is true */
|
|
96
|
+
anyTrue(): FhirPathExpr<boolean>;
|
|
97
|
+
/** True if all items are false */
|
|
98
|
+
allFalse(): FhirPathExpr<boolean>;
|
|
99
|
+
/** True if any item is false */
|
|
100
|
+
anyFalse(): FhirPathExpr<boolean>;
|
|
101
|
+
/** Number of elements */
|
|
102
|
+
count(): FhirPathExpr<number>;
|
|
103
|
+
/** True if collection is empty */
|
|
104
|
+
empty(): FhirPathExpr<boolean>;
|
|
105
|
+
/** Remove duplicate values */
|
|
106
|
+
distinct(): FhirPathExpr<T>;
|
|
107
|
+
/** True if all values are distinct */
|
|
108
|
+
isDistinct(): FhirPathExpr<boolean>;
|
|
109
|
+
}
|
|
110
|
+
interface FhirPathSubsetOps<T> {
|
|
111
|
+
/** First element */
|
|
112
|
+
first(): FhirPathExpr<Unwrap<T>>;
|
|
113
|
+
/** Last element */
|
|
114
|
+
last(): FhirPathExpr<Unwrap<T>>;
|
|
115
|
+
/** Exactly one element or error */
|
|
116
|
+
single(): FhirPathExpr<Unwrap<T>>;
|
|
117
|
+
/** All but the first element */
|
|
118
|
+
tail(): FhirPathExpr<T>;
|
|
119
|
+
/** Skip first n elements */
|
|
120
|
+
skip(count: number): FhirPathExpr<T>;
|
|
121
|
+
/** Take first n elements */
|
|
122
|
+
take(count: number): FhirPathExpr<T>;
|
|
123
|
+
/** Elements present in both collections */
|
|
124
|
+
intersect(other: FhirPathExpr<T>): FhirPathExpr<T>;
|
|
125
|
+
/** Elements not present in other collection */
|
|
126
|
+
exclude(other: FhirPathExpr<T>): FhirPathExpr<T>;
|
|
127
|
+
}
|
|
128
|
+
interface FhirPathProjectionOps<T> {
|
|
129
|
+
/** Project each element through expression */
|
|
130
|
+
select<R>(projection: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<R>): FhirPathExpr<R>;
|
|
131
|
+
/** Recursively project until stable */
|
|
132
|
+
repeat<R>(projection: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<R>): FhirPathExpr<R>;
|
|
133
|
+
/** Filter collection to elements of the specified type */
|
|
134
|
+
ofType<N extends keyof FhirTypeMap>(type: N): FhirPathExpr<FhirTypeMap[N]>;
|
|
135
|
+
}
|
|
136
|
+
interface FhirPathCombiningOps<T> {
|
|
137
|
+
/** Merge two collections (deduplicated) */
|
|
138
|
+
union(other: FhirPathExpr<T>): FhirPathExpr<T>;
|
|
139
|
+
/** Merge two collections (with duplicates) */
|
|
140
|
+
combine(other: FhirPathExpr<T>): FhirPathExpr<T>;
|
|
141
|
+
}
|
|
142
|
+
interface FhirPathStringOps {
|
|
143
|
+
/** Index of substring (-1 if not found) */
|
|
144
|
+
indexOf(substring: string): FhirPathExpr<number>;
|
|
145
|
+
/** Extract substring */
|
|
146
|
+
substring(start: number, length?: number): FhirPathExpr<string>;
|
|
147
|
+
/** True if string starts with prefix */
|
|
148
|
+
startsWith(prefix: string): FhirPathExpr<boolean>;
|
|
149
|
+
/** True if string ends with suffix */
|
|
150
|
+
endsWith(suffix: string): FhirPathExpr<boolean>;
|
|
151
|
+
/** True if string contains substring */
|
|
152
|
+
contains(substring: string): FhirPathExpr<boolean>;
|
|
153
|
+
/** Convert to uppercase */
|
|
154
|
+
upper(): FhirPathExpr<string>;
|
|
155
|
+
/** Convert to lowercase */
|
|
156
|
+
lower(): FhirPathExpr<string>;
|
|
157
|
+
/** Replace occurrences of pattern */
|
|
158
|
+
replace(pattern: string, substitution: string): FhirPathExpr<string>;
|
|
159
|
+
/** True if string matches regex */
|
|
160
|
+
matches(regex: string): FhirPathExpr<boolean>;
|
|
161
|
+
/** Replace regex matches */
|
|
162
|
+
replaceMatches(regex: string, substitution: string): FhirPathExpr<string>;
|
|
163
|
+
/** String length */
|
|
164
|
+
length(): FhirPathExpr<number>;
|
|
165
|
+
/** Split string into characters */
|
|
166
|
+
toChars(): FhirPathExpr<string>;
|
|
167
|
+
}
|
|
168
|
+
interface FhirPathMathOps {
|
|
169
|
+
/** Absolute value */
|
|
170
|
+
abs(): FhirPathExpr<number>;
|
|
171
|
+
/** Round up to integer */
|
|
172
|
+
ceiling(): FhirPathExpr<number>;
|
|
173
|
+
/** e^x */
|
|
174
|
+
exp(): FhirPathExpr<number>;
|
|
175
|
+
/** Round down to integer */
|
|
176
|
+
floor(): FhirPathExpr<number>;
|
|
177
|
+
/** Natural logarithm */
|
|
178
|
+
ln(): FhirPathExpr<number>;
|
|
179
|
+
/** Logarithm with base */
|
|
180
|
+
log(base: number): FhirPathExpr<number>;
|
|
181
|
+
/** Raise to power */
|
|
182
|
+
power(exponent: number): FhirPathExpr<number>;
|
|
183
|
+
/** Round to precision */
|
|
184
|
+
round(precision?: number): FhirPathExpr<number>;
|
|
185
|
+
/** Square root */
|
|
186
|
+
sqrt(): FhirPathExpr<number>;
|
|
187
|
+
/** Truncate to integer */
|
|
188
|
+
truncate(): FhirPathExpr<number>;
|
|
189
|
+
}
|
|
190
|
+
interface FhirPathConversionOps {
|
|
191
|
+
/** Convert to boolean */
|
|
192
|
+
toBoolean(): FhirPathExpr<boolean>;
|
|
193
|
+
/** Convert to integer */
|
|
194
|
+
toInteger(): FhirPathExpr<number>;
|
|
195
|
+
/** Convert to decimal */
|
|
196
|
+
toDecimal(): FhirPathExpr<number>;
|
|
197
|
+
/** Convert to string (FHIRPath toString) */
|
|
198
|
+
toFhirString(): FhirPathExpr<string>;
|
|
199
|
+
/** Convert to date */
|
|
200
|
+
toDate(): FhirPathExpr<string>;
|
|
201
|
+
/** Convert to dateTime */
|
|
202
|
+
toDateTime(): FhirPathExpr<string>;
|
|
203
|
+
/** Convert to time */
|
|
204
|
+
toTime(): FhirPathExpr<string>;
|
|
205
|
+
/** Convert to Quantity */
|
|
206
|
+
toQuantity(unit?: string): FhirPathExpr<Quantity>;
|
|
207
|
+
/** Can convert to boolean? */
|
|
208
|
+
convertsToBoolean(): FhirPathExpr<boolean>;
|
|
209
|
+
/** Can convert to integer? */
|
|
210
|
+
convertsToInteger(): FhirPathExpr<boolean>;
|
|
211
|
+
/** Can convert to decimal? */
|
|
212
|
+
convertsToDecimal(): FhirPathExpr<boolean>;
|
|
213
|
+
/** Can convert to string? */
|
|
214
|
+
convertsToString(): FhirPathExpr<boolean>;
|
|
215
|
+
/** Can convert to date? */
|
|
216
|
+
convertsToDate(): FhirPathExpr<boolean>;
|
|
217
|
+
/** Can convert to dateTime? */
|
|
218
|
+
convertsToDateTime(): FhirPathExpr<boolean>;
|
|
219
|
+
/** Can convert to time? */
|
|
220
|
+
convertsToTime(): FhirPathExpr<boolean>;
|
|
221
|
+
/** Can convert to Quantity? */
|
|
222
|
+
convertsToQuantity(): FhirPathExpr<boolean>;
|
|
223
|
+
}
|
|
224
|
+
interface FhirPathUtilityOps<T> {
|
|
225
|
+
/** Debug trace (returns input unchanged) */
|
|
226
|
+
trace(name: string): FhirPathExpr<T>;
|
|
227
|
+
/** Immediate children of each element */
|
|
228
|
+
children(): FhirPathExpr<unknown>;
|
|
229
|
+
/** All descendants of each element */
|
|
230
|
+
descendants(): FhirPathExpr<unknown>;
|
|
231
|
+
/** Conditional: if criterion then trueResult else otherwiseResult */
|
|
232
|
+
iif<R>(criterion: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<boolean>, trueResult: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<R>, otherwiseResult?: ($this: FhirPathPredicate<Unwrap<T>>) => FhirPathPredicate<R>): FhirPathExpr<R>;
|
|
233
|
+
/** Current dateTime */
|
|
234
|
+
now(): FhirPathExpr<string>;
|
|
235
|
+
/** Current time */
|
|
236
|
+
timeOfDay(): FhirPathExpr<string>;
|
|
237
|
+
/** Current date */
|
|
238
|
+
today(): FhirPathExpr<string>;
|
|
239
|
+
}
|
|
240
|
+
/** Composed FHIRPath operations interface */
|
|
241
|
+
interface FhirPathOps<T> extends FhirPathCoreOps<T>, FhirPathExistenceOps<T>, FhirPathSubsetOps<T>, FhirPathProjectionOps<T>, FhirPathCombiningOps<T>, FhirPathStringOps, FhirPathMathOps, FhirPathConversionOps, FhirPathUtilityOps<T> {
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* A type-safe FHIRPath expression node.
|
|
245
|
+
*
|
|
246
|
+
* When `T` resolves to a complex FHIR type, every property of the unwrapped
|
|
247
|
+
* type is available as a navigable key with full autocomplete.
|
|
248
|
+
* When `T` resolves to a primitive, only collection operations remain.
|
|
249
|
+
*/
|
|
250
|
+
type FhirPathExpr<T> = FhirPathOps<T> & (IsPrimitive<T> extends true ? unknown : {
|
|
251
|
+
readonly [K in NavKeys<T>]: FhirPathExpr<Unwrap<T>[K]>;
|
|
252
|
+
});
|
|
253
|
+
/** Constraint for the `fhirpath()` entry point — accepts any FHIR Resource. */
|
|
254
|
+
type FhirPathResource = Resource;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Create a type-safe FHIRPath expression builder for a FHIR resource type.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* import type { Patient } from "./fhir/r4";
|
|
262
|
+
*
|
|
263
|
+
* const expr = fhirpath<Patient>("Patient").name.family;
|
|
264
|
+
* expr.compile() // "Patient.name.family"
|
|
265
|
+
* expr.evaluate(somePatient) // ["Smith", "Doe"]
|
|
266
|
+
*
|
|
267
|
+
* // Expression predicates:
|
|
268
|
+
* fhirpath<Patient>("Patient")
|
|
269
|
+
* .name.where($this => $this.use.eq("official")).family
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
declare function fhirpath<T extends FhirPathResource>(resourceType: string): FhirPathExpr<T>;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Structured representation of each FHIRPath operation step.
|
|
276
|
+
*
|
|
277
|
+
* A compiled expression is an ordered array of PathOp values.
|
|
278
|
+
* The evaluator walks them left-to-right against a resource.
|
|
279
|
+
*/
|
|
280
|
+
interface CompiledPredicate {
|
|
281
|
+
ops: PathOp[];
|
|
282
|
+
compiledPath: string;
|
|
283
|
+
}
|
|
284
|
+
type NavOp = {
|
|
285
|
+
type: "nav";
|
|
286
|
+
prop: string;
|
|
287
|
+
} | {
|
|
288
|
+
type: "children";
|
|
289
|
+
} | {
|
|
290
|
+
type: "descendants";
|
|
291
|
+
};
|
|
292
|
+
type FilterOp = {
|
|
293
|
+
type: "where";
|
|
294
|
+
predicate: CompiledPredicate;
|
|
295
|
+
} | {
|
|
296
|
+
type: "where_simple";
|
|
297
|
+
field: string;
|
|
298
|
+
value: string;
|
|
299
|
+
} | {
|
|
300
|
+
type: "select";
|
|
301
|
+
projection: CompiledPredicate;
|
|
302
|
+
} | {
|
|
303
|
+
type: "repeat";
|
|
304
|
+
projection: CompiledPredicate;
|
|
305
|
+
} | {
|
|
306
|
+
type: "ofType";
|
|
307
|
+
typeName: string;
|
|
308
|
+
} | {
|
|
309
|
+
type: "exists";
|
|
310
|
+
} | {
|
|
311
|
+
type: "exists_predicate";
|
|
312
|
+
predicate: CompiledPredicate;
|
|
313
|
+
} | {
|
|
314
|
+
type: "all";
|
|
315
|
+
predicate: CompiledPredicate;
|
|
316
|
+
} | {
|
|
317
|
+
type: "allTrue";
|
|
318
|
+
} | {
|
|
319
|
+
type: "anyTrue";
|
|
320
|
+
} | {
|
|
321
|
+
type: "allFalse";
|
|
322
|
+
} | {
|
|
323
|
+
type: "anyFalse";
|
|
324
|
+
} | {
|
|
325
|
+
type: "count";
|
|
326
|
+
} | {
|
|
327
|
+
type: "empty";
|
|
328
|
+
} | {
|
|
329
|
+
type: "distinct";
|
|
330
|
+
} | {
|
|
331
|
+
type: "isDistinct";
|
|
332
|
+
} | {
|
|
333
|
+
type: "subsetOf";
|
|
334
|
+
other: CompiledPredicate;
|
|
335
|
+
} | {
|
|
336
|
+
type: "supersetOf";
|
|
337
|
+
other: CompiledPredicate;
|
|
338
|
+
};
|
|
339
|
+
type SubsetOp = {
|
|
340
|
+
type: "first";
|
|
341
|
+
} | {
|
|
342
|
+
type: "last";
|
|
343
|
+
} | {
|
|
344
|
+
type: "single";
|
|
345
|
+
} | {
|
|
346
|
+
type: "tail";
|
|
347
|
+
} | {
|
|
348
|
+
type: "skip";
|
|
349
|
+
num: number;
|
|
350
|
+
} | {
|
|
351
|
+
type: "take";
|
|
352
|
+
num: number;
|
|
353
|
+
} | {
|
|
354
|
+
type: "intersect";
|
|
355
|
+
other: CompiledPredicate;
|
|
356
|
+
} | {
|
|
357
|
+
type: "exclude";
|
|
358
|
+
other: CompiledPredicate;
|
|
359
|
+
};
|
|
360
|
+
type CombineOp = {
|
|
361
|
+
type: "union";
|
|
362
|
+
other: CompiledPredicate;
|
|
363
|
+
} | {
|
|
364
|
+
type: "combine";
|
|
365
|
+
other: CompiledPredicate;
|
|
366
|
+
};
|
|
367
|
+
type StringOp = {
|
|
368
|
+
type: "indexOf";
|
|
369
|
+
substring: string;
|
|
370
|
+
} | {
|
|
371
|
+
type: "substring";
|
|
372
|
+
start: number;
|
|
373
|
+
length?: number;
|
|
374
|
+
} | {
|
|
375
|
+
type: "startsWith";
|
|
376
|
+
prefix: string;
|
|
377
|
+
} | {
|
|
378
|
+
type: "endsWith";
|
|
379
|
+
suffix: string;
|
|
380
|
+
} | {
|
|
381
|
+
type: "str_contains";
|
|
382
|
+
substring: string;
|
|
383
|
+
} | {
|
|
384
|
+
type: "upper";
|
|
385
|
+
} | {
|
|
386
|
+
type: "lower";
|
|
387
|
+
} | {
|
|
388
|
+
type: "replace";
|
|
389
|
+
pattern: string;
|
|
390
|
+
substitution: string;
|
|
391
|
+
} | {
|
|
392
|
+
type: "matches";
|
|
393
|
+
regex: string;
|
|
394
|
+
} | {
|
|
395
|
+
type: "replaceMatches";
|
|
396
|
+
regex: string;
|
|
397
|
+
substitution: string;
|
|
398
|
+
} | {
|
|
399
|
+
type: "str_length";
|
|
400
|
+
} | {
|
|
401
|
+
type: "toChars";
|
|
402
|
+
};
|
|
403
|
+
type MathOp = {
|
|
404
|
+
type: "abs";
|
|
405
|
+
} | {
|
|
406
|
+
type: "ceiling";
|
|
407
|
+
} | {
|
|
408
|
+
type: "exp";
|
|
409
|
+
} | {
|
|
410
|
+
type: "floor";
|
|
411
|
+
} | {
|
|
412
|
+
type: "ln";
|
|
413
|
+
} | {
|
|
414
|
+
type: "log";
|
|
415
|
+
base: number;
|
|
416
|
+
} | {
|
|
417
|
+
type: "power";
|
|
418
|
+
exponent: number;
|
|
419
|
+
} | {
|
|
420
|
+
type: "round";
|
|
421
|
+
precision?: number;
|
|
422
|
+
} | {
|
|
423
|
+
type: "sqrt";
|
|
424
|
+
} | {
|
|
425
|
+
type: "truncate";
|
|
426
|
+
};
|
|
427
|
+
type ConversionOp = {
|
|
428
|
+
type: "toBoolean";
|
|
429
|
+
} | {
|
|
430
|
+
type: "toInteger";
|
|
431
|
+
} | {
|
|
432
|
+
type: "toDecimal";
|
|
433
|
+
} | {
|
|
434
|
+
type: "toFhirString";
|
|
435
|
+
} | {
|
|
436
|
+
type: "toDate";
|
|
437
|
+
} | {
|
|
438
|
+
type: "toDateTime";
|
|
439
|
+
} | {
|
|
440
|
+
type: "toTime";
|
|
441
|
+
} | {
|
|
442
|
+
type: "toQuantity";
|
|
443
|
+
unit?: string;
|
|
444
|
+
} | {
|
|
445
|
+
type: "convertsToBoolean";
|
|
446
|
+
} | {
|
|
447
|
+
type: "convertsToInteger";
|
|
448
|
+
} | {
|
|
449
|
+
type: "convertsToDecimal";
|
|
450
|
+
} | {
|
|
451
|
+
type: "convertsToString";
|
|
452
|
+
} | {
|
|
453
|
+
type: "convertsToDate";
|
|
454
|
+
} | {
|
|
455
|
+
type: "convertsToDateTime";
|
|
456
|
+
} | {
|
|
457
|
+
type: "convertsToTime";
|
|
458
|
+
} | {
|
|
459
|
+
type: "convertsToQuantity";
|
|
460
|
+
};
|
|
461
|
+
type UtilityOp = {
|
|
462
|
+
type: "trace";
|
|
463
|
+
name: string;
|
|
464
|
+
} | {
|
|
465
|
+
type: "now";
|
|
466
|
+
} | {
|
|
467
|
+
type: "timeOfDay";
|
|
468
|
+
} | {
|
|
469
|
+
type: "today";
|
|
470
|
+
} | {
|
|
471
|
+
type: "iif";
|
|
472
|
+
criterion: CompiledPredicate;
|
|
473
|
+
trueResult: CompiledPredicate;
|
|
474
|
+
otherwiseResult?: CompiledPredicate;
|
|
475
|
+
};
|
|
476
|
+
type OperatorOp = {
|
|
477
|
+
type: "eq";
|
|
478
|
+
value: unknown;
|
|
479
|
+
} | {
|
|
480
|
+
type: "neq";
|
|
481
|
+
value: unknown;
|
|
482
|
+
} | {
|
|
483
|
+
type: "lt";
|
|
484
|
+
value: unknown;
|
|
485
|
+
} | {
|
|
486
|
+
type: "gt";
|
|
487
|
+
value: unknown;
|
|
488
|
+
} | {
|
|
489
|
+
type: "lte";
|
|
490
|
+
value: unknown;
|
|
491
|
+
} | {
|
|
492
|
+
type: "gte";
|
|
493
|
+
value: unknown;
|
|
494
|
+
} | {
|
|
495
|
+
type: "and";
|
|
496
|
+
other: CompiledPredicate;
|
|
497
|
+
} | {
|
|
498
|
+
type: "or";
|
|
499
|
+
other: CompiledPredicate;
|
|
500
|
+
} | {
|
|
501
|
+
type: "xor";
|
|
502
|
+
other: CompiledPredicate;
|
|
503
|
+
} | {
|
|
504
|
+
type: "not";
|
|
505
|
+
} | {
|
|
506
|
+
type: "implies";
|
|
507
|
+
other: CompiledPredicate;
|
|
508
|
+
} | {
|
|
509
|
+
type: "is";
|
|
510
|
+
typeName: string;
|
|
511
|
+
} | {
|
|
512
|
+
type: "as";
|
|
513
|
+
typeName: string;
|
|
514
|
+
};
|
|
515
|
+
type LiteralOp = {
|
|
516
|
+
type: "literal";
|
|
517
|
+
value: unknown;
|
|
518
|
+
};
|
|
519
|
+
type PathOp = NavOp | FilterOp | SubsetOp | CombineOp | StringOp | MathOp | ConversionOp | UtilityOp | OperatorOp | LiteralOp;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Evaluate a sequence of FHIRPath operations against a resource.
|
|
523
|
+
* Returns the resulting collection.
|
|
524
|
+
*/
|
|
525
|
+
declare function evaluate(ops: PathOp[], resource: unknown): unknown[];
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Expression system for FHIRPath predicate callbacks.
|
|
529
|
+
*
|
|
530
|
+
* Used inside where(), select(), all(), exists(criteria), iif(), etc.
|
|
531
|
+
* The callback receives a `$this` proxy that captures navigation and
|
|
532
|
+
* comparison ops into a CompiledPredicate.
|
|
533
|
+
*/
|
|
534
|
+
|
|
535
|
+
/** Symbol used to extract internal ops from a predicate proxy */
|
|
536
|
+
declare const PREDICATE_SYMBOL: unique symbol;
|
|
537
|
+
/** Extract a CompiledPredicate from a predicate proxy result */
|
|
538
|
+
declare function extractPredicate(proxy: unknown): CompiledPredicate;
|
|
539
|
+
/** Create a predicate proxy representing `$this` inside expression callbacks */
|
|
540
|
+
declare function createPredicateProxy(path: string, ops: PathOp[]): unknown;
|
|
541
|
+
|
|
542
|
+
export { type CombineOp, type CompiledPredicate, type ConversionOp, type FhirPathExpr, type FhirPathOps, type FhirPathPredicate, type FhirPathResource, type FhirTypeMap, type FilterOp, type IsPrimitive, type LiteralOp, type MathOp, type NavKeys, type NavOp, type OperatorOp, PREDICATE_SYMBOL, type PathOp, type PredicateOps, type StringOp, type SubsetOp, type Unwrap, type UtilityOp, createPredicateProxy, evaluate, extractPredicate, fhirpath };
|