@atomic-ehr/fhirpath 0.0.1 → 0.0.2-canary.261bb9b.20250811212042
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/README.md +62 -56
- package/dist/index.d.ts +368 -99
- package/dist/index.js +3623 -1253
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/analyzer.ts +779 -120
- package/src/boxing.ts +124 -0
- package/src/completion-provider.ts +636 -0
- package/src/cursor-nodes.ts +111 -0
- package/src/errors.ts +247 -0
- package/src/index.ts +97 -14
- package/src/inspect.ts +309 -176
- package/src/interpreter.ts +380 -71
- package/src/lexer.ts +1 -0
- package/src/model-provider.ts +282 -39
- package/src/operations/abs-function.ts +40 -16
- package/src/operations/aggregate-function.ts +21 -10
- package/src/operations/all-function.ts +23 -11
- package/src/operations/allFalse-function.ts +14 -9
- package/src/operations/allTrue-function.ts +14 -9
- package/src/operations/and-operator.ts +21 -12
- package/src/operations/anyFalse-function.ts +11 -7
- package/src/operations/anyTrue-function.ts +11 -7
- package/src/operations/as-operator.ts +2 -1
- package/src/operations/ceiling-function.ts +14 -8
- package/src/operations/children-function.ts +98 -0
- package/src/operations/combine-function.ts +10 -6
- package/src/operations/combine-operator.ts +19 -5
- package/src/operations/contains-function.ts +26 -12
- package/src/operations/contains-operator.ts +15 -7
- package/src/operations/count-function.ts +7 -4
- package/src/operations/defineVariable-function.ts +11 -7
- package/src/operations/descendants-function.ts +64 -0
- package/src/operations/distinct-function.ts +21 -7
- package/src/operations/div-operator.ts +16 -3
- package/src/operations/divide-operator.ts +11 -6
- package/src/operations/dot-operator.ts +4 -2
- package/src/operations/empty-function.ts +7 -4
- package/src/operations/endsWith-function.ts +28 -14
- package/src/operations/equal-operator.ts +19 -7
- package/src/operations/equivalent-operator.ts +16 -11
- package/src/operations/exclude-function.ts +18 -14
- package/src/operations/exists-function.ts +19 -10
- package/src/operations/first-function.ts +12 -7
- package/src/operations/floor-function.ts +14 -8
- package/src/operations/greater-operator.ts +10 -5
- package/src/operations/greater-or-equal-operator.ts +10 -5
- package/src/operations/iif-function.ts +27 -23
- package/src/operations/implies-operator.ts +23 -8
- package/src/operations/in-operator.ts +18 -8
- package/src/operations/index.ts +3 -0
- package/src/operations/indexOf-function.ts +28 -14
- package/src/operations/intersect-function.ts +23 -24
- package/src/operations/is-operator.ts +67 -15
- package/src/operations/isDistinct-function.ts +17 -9
- package/src/operations/join-function.ts +22 -9
- package/src/operations/last-function.ts +12 -7
- package/src/operations/length-function.ts +17 -8
- package/src/operations/less-operator.ts +10 -5
- package/src/operations/less-or-equal-operator.ts +10 -5
- package/src/operations/less-than.ts +26 -2
- package/src/operations/lower-function.ts +17 -8
- package/src/operations/minus-operator.ts +10 -5
- package/src/operations/mod-operator.ts +20 -3
- package/src/operations/multiply-operator.ts +12 -7
- package/src/operations/not-equal-operator.ts +16 -7
- package/src/operations/not-equivalent-operator.ts +16 -11
- package/src/operations/not-function.ts +17 -7
- package/src/operations/ofType-function.ts +139 -0
- package/src/operations/or-operator.ts +21 -12
- package/src/operations/plus-operator.ts +19 -7
- package/src/operations/power-function.ts +27 -13
- package/src/operations/replace-function.ts +33 -14
- package/src/operations/round-function.ts +29 -12
- package/src/operations/select-function.ts +17 -9
- package/src/operations/single-function.ts +10 -6
- package/src/operations/skip-function.ts +18 -9
- package/src/operations/split-function.ts +30 -13
- package/src/operations/sqrt-function.ts +14 -8
- package/src/operations/startsWith-function.ts +26 -12
- package/src/operations/subsetOf-function.ts +20 -15
- package/src/operations/substring-function.ts +43 -24
- package/src/operations/supersetOf-function.ts +20 -15
- package/src/operations/tail-function.ts +8 -4
- package/src/operations/take-function.ts +18 -9
- package/src/operations/toBoolean-function.ts +23 -14
- package/src/operations/toDecimal-function.ts +18 -9
- package/src/operations/toInteger-function.ts +22 -12
- package/src/operations/toString-function.ts +26 -16
- package/src/operations/trace-function.ts +19 -10
- package/src/operations/trim-function.ts +16 -7
- package/src/operations/truncate-function.ts +14 -8
- package/src/operations/unary-minus-operator.ts +23 -13
- package/src/operations/unary-plus-operator.ts +2 -1
- package/src/operations/union-function.ts +25 -28
- package/src/operations/union-operator.ts +2 -1
- package/src/operations/upper-function.ts +17 -8
- package/src/operations/where-function.ts +20 -11
- package/src/operations/xor-operator.ts +9 -4
- package/src/parser.ts +527 -8
- package/src/quantity-value.ts +4 -8
- package/src/registry.ts +147 -5
- package/src/types.ts +42 -19
- package/src/parser-base.ts +0 -400
package/src/boxing.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type {TypeInfo} from './types';
|
|
2
|
+
export type {TypeInfo};
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Symbol to mark boxed values
|
|
6
|
+
*/
|
|
7
|
+
const BOXED_SYMBOL = Symbol('FHIRPathBoxedValue');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Extension structure for FHIR primitive elements
|
|
11
|
+
*/
|
|
12
|
+
export interface Extension {
|
|
13
|
+
url: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Metadata for FHIR primitive elements (e.g., _gender for gender property)
|
|
19
|
+
*/
|
|
20
|
+
export interface PrimitiveElement {
|
|
21
|
+
id?: string;
|
|
22
|
+
extension?: Extension[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Boxed FHIRPath value with metadata
|
|
27
|
+
*/
|
|
28
|
+
export interface FHIRPathValue<T = any> {
|
|
29
|
+
/** The actual value */
|
|
30
|
+
value: T;
|
|
31
|
+
|
|
32
|
+
/** Type information from ModelProvider */
|
|
33
|
+
typeInfo?: TypeInfo;
|
|
34
|
+
|
|
35
|
+
/** Primitive element extension (for primitives only) */
|
|
36
|
+
primitiveElement?: PrimitiveElement;
|
|
37
|
+
|
|
38
|
+
/** Internal marker to identify boxed values */
|
|
39
|
+
[BOXED_SYMBOL]: true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Box a value with optional metadata
|
|
44
|
+
*/
|
|
45
|
+
export function box<T>(
|
|
46
|
+
value: T,
|
|
47
|
+
typeInfo?: TypeInfo,
|
|
48
|
+
primitiveElement?: PrimitiveElement
|
|
49
|
+
): FHIRPathValue<T> {
|
|
50
|
+
return {
|
|
51
|
+
value,
|
|
52
|
+
typeInfo,
|
|
53
|
+
primitiveElement,
|
|
54
|
+
[BOXED_SYMBOL]: true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Unbox a value to get the raw value
|
|
60
|
+
*/
|
|
61
|
+
export function unbox<T>(boxedValue: FHIRPathValue<T>): T {
|
|
62
|
+
return boxedValue.value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Check if a value is already boxed
|
|
67
|
+
*/
|
|
68
|
+
export function isBoxed(value: any): value is FHIRPathValue {
|
|
69
|
+
return value !== null &&
|
|
70
|
+
value !== undefined &&
|
|
71
|
+
typeof value === 'object' &&
|
|
72
|
+
BOXED_SYMBOL in value &&
|
|
73
|
+
value[BOXED_SYMBOL] === true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Ensure a value is boxed, boxing it if necessary
|
|
78
|
+
*/
|
|
79
|
+
export function ensureBoxed(value: any, typeInfo?: TypeInfo): FHIRPathValue {
|
|
80
|
+
if (isBoxed(value)) {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
return box(value, typeInfo);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Map over an array of boxed values, preserving boxing
|
|
88
|
+
*/
|
|
89
|
+
export function mapBoxed<T, U>(
|
|
90
|
+
values: FHIRPathValue<T>[],
|
|
91
|
+
fn: (value: T, index: number) => U,
|
|
92
|
+
typeInfo?: TypeInfo
|
|
93
|
+
): FHIRPathValue<U>[] {
|
|
94
|
+
return values.map((boxedValue, index) =>
|
|
95
|
+
box(fn(boxedValue.value, index), typeInfo)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Filter an array of boxed values, preserving boxing
|
|
101
|
+
*/
|
|
102
|
+
export function filterBoxed<T>(
|
|
103
|
+
values: FHIRPathValue<T>[],
|
|
104
|
+
predicate: (value: T, index: number) => boolean
|
|
105
|
+
): FHIRPathValue<T>[] {
|
|
106
|
+
return values.filter((boxedValue, index) =>
|
|
107
|
+
predicate(boxedValue.value, index)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Flatten an array of boxed arrays into a single array of boxed values
|
|
113
|
+
*/
|
|
114
|
+
export function flattenBoxed<T>(values: FHIRPathValue<T[]>[]): FHIRPathValue<T>[] {
|
|
115
|
+
const result: FHIRPathValue<T>[] = [];
|
|
116
|
+
for (const boxedArray of values) {
|
|
117
|
+
if (Array.isArray(boxedArray.value)) {
|
|
118
|
+
for (const item of boxedArray.value) {
|
|
119
|
+
result.push(box(item, boxedArray.typeInfo));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|