@atomic-ehr/fhirpath 0.0.2 → 0.0.3-canary.2be66fb.20250905161900
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 +716 -238
- package/dist/index.d.ts +226 -120
- package/dist/index.js +11552 -5580
- package/dist/index.js.map +1 -1
- package/package.json +12 -5
- package/src/analyzer/augmentor.ts +242 -0
- package/src/analyzer/cursor-services.ts +75 -0
- package/src/analyzer/scope-manager.ts +57 -0
- package/src/analyzer/trivia-indexer.ts +58 -0
- package/src/analyzer/type-compat.ts +157 -0
- package/src/analyzer/utils.ts +132 -0
- package/src/analyzer.ts +939 -1204
- package/src/completion-provider.ts +209 -191
- package/src/complex-types/quantity-value.ts +410 -0
- package/src/complex-types/temporal.ts +1776 -0
- package/src/errors.ts +25 -3
- package/src/index.ts +17 -104
- package/src/inspect.ts +4 -4
- package/src/{boxing.ts → interpreter/boxing.ts} +1 -1
- package/src/interpreter/navigator.ts +94 -0
- package/src/interpreter/runtime-context.ts +273 -0
- package/src/interpreter.ts +506 -468
- package/src/lexer.ts +192 -211
- package/src/model-provider.ts +71 -43
- package/src/operations/abs-function.ts +1 -1
- package/src/operations/aggregate-function.ts +84 -5
- package/src/operations/all-function.ts +4 -3
- package/src/operations/allFalse-function.ts +2 -1
- package/src/operations/allTrue-function.ts +2 -1
- package/src/operations/and-operator.ts +2 -1
- package/src/operations/anyFalse-function.ts +2 -1
- package/src/operations/anyTrue-function.ts +2 -1
- package/src/operations/as-function.ts +99 -0
- package/src/operations/as-operator.ts +57 -19
- package/src/operations/ceiling-function.ts +1 -1
- package/src/operations/children-function.ts +14 -5
- package/src/operations/combine-function.ts +6 -3
- package/src/operations/combine-operator.ts +6 -7
- package/src/operations/comparison.ts +744 -0
- package/src/operations/contains-function.ts +1 -1
- package/src/operations/contains-operator.ts +2 -1
- package/src/operations/convertsToBoolean-function.ts +78 -0
- package/src/operations/convertsToDecimal-function.ts +82 -0
- package/src/operations/convertsToInteger-function.ts +71 -0
- package/src/operations/convertsToLong-function.ts +89 -0
- package/src/operations/convertsToQuantity-function.ts +132 -0
- package/src/operations/convertsToString-function.ts +88 -0
- package/src/operations/count-function.ts +2 -1
- package/src/operations/dateOf-function.ts +69 -0
- package/src/operations/dayOf-function.ts +66 -0
- package/src/operations/decimal-boundaries.ts +133 -0
- package/src/operations/defineVariable-function.ts +130 -17
- package/src/operations/distinct-function.ts +1 -1
- package/src/operations/div-operator.ts +1 -1
- package/src/operations/divide-operator.ts +12 -7
- package/src/operations/dot-operator.ts +1 -1
- package/src/operations/empty-function.ts +30 -21
- package/src/operations/endsWith-function.ts +6 -1
- package/src/operations/equal-operator.ts +23 -32
- package/src/operations/equivalent-operator.ts +13 -53
- package/src/operations/exclude-function.ts +2 -1
- package/src/operations/exists-function.ts +4 -3
- package/src/operations/extension-function.ts +84 -0
- package/src/operations/first-function.ts +1 -1
- package/src/operations/floor-function.ts +1 -1
- package/src/operations/greater-operator.ts +7 -9
- package/src/operations/greater-or-equal-operator.ts +7 -9
- package/src/operations/highBoundary-function.ts +120 -0
- package/src/operations/hourOf-function.ts +66 -0
- package/src/operations/iif-function.ts +193 -8
- package/src/operations/implies-operator.ts +2 -1
- package/src/operations/in-operator.ts +2 -1
- package/src/operations/index.ts +43 -0
- package/src/operations/indexOf-function.ts +1 -1
- package/src/operations/intersect-function.ts +1 -1
- package/src/operations/is-function.ts +70 -0
- package/src/operations/is-operator.ts +176 -13
- package/src/operations/isDistinct-function.ts +2 -1
- package/src/operations/join-function.ts +1 -1
- package/src/operations/last-function.ts +1 -1
- package/src/operations/lastIndexOf-function.ts +85 -0
- package/src/operations/length-function.ts +1 -1
- package/src/operations/less-operator.ts +8 -9
- package/src/operations/less-or-equal-operator.ts +7 -9
- package/src/operations/less-than.ts +8 -13
- package/src/operations/lowBoundary-function.ts +120 -0
- package/src/operations/lower-function.ts +1 -1
- package/src/operations/matches-function.ts +86 -0
- package/src/operations/matchesFull-function.ts +96 -0
- package/src/operations/millisecondOf-function.ts +66 -0
- package/src/operations/minus-operator.ts +76 -4
- package/src/operations/minuteOf-function.ts +66 -0
- package/src/operations/mod-operator.ts +8 -2
- package/src/operations/monthOf-function.ts +66 -0
- package/src/operations/multiply-operator.ts +27 -3
- package/src/operations/not-equal-operator.ts +24 -30
- package/src/operations/not-equivalent-operator.ts +13 -53
- package/src/operations/not-function.ts +10 -3
- package/src/operations/ofType-function.ts +43 -12
- package/src/operations/or-operator.ts +2 -1
- package/src/operations/plus-operator.ts +71 -7
- package/src/operations/power-function.ts +35 -10
- package/src/operations/precision-function.ts +146 -0
- package/src/operations/repeat-function.ts +169 -0
- package/src/operations/replace-function.ts +1 -1
- package/src/operations/replaceMatches-function.ts +125 -0
- package/src/operations/round-function.ts +1 -1
- package/src/operations/secondOf-function.ts +66 -0
- package/src/operations/select-function.ts +66 -5
- package/src/operations/single-function.ts +1 -1
- package/src/operations/skip-function.ts +1 -1
- package/src/operations/split-function.ts +1 -1
- package/src/operations/sqrt-function.ts +15 -8
- package/src/operations/startsWith-function.ts +1 -1
- package/src/operations/subsetOf-function.ts +6 -2
- package/src/operations/substring-function.ts +1 -1
- package/src/operations/supersetOf-function.ts +6 -2
- package/src/operations/tail-function.ts +1 -1
- package/src/operations/take-function.ts +1 -1
- package/src/operations/temporal-functions.ts +555 -0
- package/src/operations/timeOf-function.ts +67 -0
- package/src/operations/timezoneOffsetOf-function.ts +69 -0
- package/src/operations/toBoolean-function.ts +27 -8
- package/src/operations/toChars-function.ts +56 -0
- package/src/operations/toDecimal-function.ts +27 -8
- package/src/operations/toInteger-function.ts +15 -3
- package/src/operations/toLong-function.ts +98 -0
- package/src/operations/toQuantity-function.ts +181 -0
- package/src/operations/toString-function.ts +78 -15
- package/src/operations/trace-function.ts +1 -1
- package/src/operations/trim-function.ts +1 -1
- package/src/operations/truncate-function.ts +1 -1
- package/src/operations/unary-minus-operator.ts +2 -2
- package/src/operations/unary-plus-operator.ts +1 -1
- package/src/operations/union-function.ts +1 -1
- package/src/operations/union-operator.ts +16 -26
- package/src/operations/upper-function.ts +1 -1
- package/src/operations/where-function.ts +3 -3
- package/src/operations/xor-operator.ts +1 -1
- package/src/operations/yearOf-function.ts +66 -0
- package/src/{cursor-nodes.ts → parser/cursor-nodes.ts} +10 -7
- package/src/parser.ts +262 -503
- package/src/registry.ts +53 -42
- package/src/types.ts +129 -17
- package/src/utils/decimal.ts +76 -0
- package/src/utils/pprint.ts +151 -0
- package/src/quantity-value.ts +0 -198
package/src/quantity-value.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { ucum } from '@atomic-ehr/ucum';
|
|
2
|
-
import type { Quantity } from '@atomic-ehr/ucum';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Wrapper for FHIRPath quantity values with UCUM integration
|
|
6
|
-
*/
|
|
7
|
-
export interface QuantityValue {
|
|
8
|
-
value: number;
|
|
9
|
-
unit: string;
|
|
10
|
-
_ucumQuantity?: Quantity; // Lazy-initialized
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Calendar duration unit to UCUM unit mapping
|
|
15
|
-
*/
|
|
16
|
-
export const CALENDAR_TO_UCUM: Record<string, string> = {
|
|
17
|
-
'year': 'a', // annum
|
|
18
|
-
'years': 'a',
|
|
19
|
-
'month': 'mo', // month
|
|
20
|
-
'months': 'mo',
|
|
21
|
-
'week': 'wk', // week
|
|
22
|
-
'weeks': 'wk',
|
|
23
|
-
'day': 'd', // day
|
|
24
|
-
'days': 'd',
|
|
25
|
-
'hour': 'h', // hour
|
|
26
|
-
'hours': 'h',
|
|
27
|
-
'minute': 'min', // minute
|
|
28
|
-
'minutes': 'min',
|
|
29
|
-
'second': 's', // second
|
|
30
|
-
'seconds': 's',
|
|
31
|
-
'millisecond': 'ms', // millisecond
|
|
32
|
-
'milliseconds': 'ms'
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a quantity value
|
|
37
|
-
*/
|
|
38
|
-
export function createQuantity(value: number, unit: string, isCalendarUnit: boolean = false): QuantityValue {
|
|
39
|
-
const actualUnit = isCalendarUnit && CALENDAR_TO_UCUM[unit] ? CALENDAR_TO_UCUM[unit] : unit;
|
|
40
|
-
return {
|
|
41
|
-
value,
|
|
42
|
-
unit: actualUnit
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get or create the UCUM quantity for a QuantityValue
|
|
48
|
-
*/
|
|
49
|
-
export function getUcumQuantity(quantity: QuantityValue): Quantity | null {
|
|
50
|
-
if (!quantity._ucumQuantity) {
|
|
51
|
-
try {
|
|
52
|
-
quantity._ucumQuantity = ucum.quantity(quantity.value, quantity.unit);
|
|
53
|
-
} catch (e) {
|
|
54
|
-
// Invalid unit - return null
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return quantity._ucumQuantity || null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Check if a quantity has a valid unit
|
|
63
|
-
*/
|
|
64
|
-
export function isValidQuantity(quantity: QuantityValue): boolean {
|
|
65
|
-
return getUcumQuantity(quantity) !== null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Add two quantities
|
|
70
|
-
*/
|
|
71
|
-
export function addQuantities(left: QuantityValue, right: QuantityValue): QuantityValue | null {
|
|
72
|
-
const leftUcum = getUcumQuantity(left);
|
|
73
|
-
const rightUcum = getUcumQuantity(right);
|
|
74
|
-
|
|
75
|
-
if (!leftUcum || !rightUcum) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const result = ucum.add(leftUcum, rightUcum);
|
|
81
|
-
return {
|
|
82
|
-
value: result.value,
|
|
83
|
-
unit: result.unit
|
|
84
|
-
};
|
|
85
|
-
} catch (e) {
|
|
86
|
-
// Incompatible dimensions
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Subtract two quantities
|
|
93
|
-
*/
|
|
94
|
-
export function subtractQuantities(left: QuantityValue, right: QuantityValue): QuantityValue | null {
|
|
95
|
-
const leftUcum = getUcumQuantity(left);
|
|
96
|
-
const rightUcum = getUcumQuantity(right);
|
|
97
|
-
|
|
98
|
-
if (!leftUcum || !rightUcum) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const result = ucum.subtract(leftUcum, rightUcum);
|
|
104
|
-
return {
|
|
105
|
-
value: result.value,
|
|
106
|
-
unit: result.unit
|
|
107
|
-
};
|
|
108
|
-
} catch (e) {
|
|
109
|
-
// Incompatible dimensions
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Multiply two quantities
|
|
116
|
-
*/
|
|
117
|
-
export function multiplyQuantities(left: QuantityValue, right: QuantityValue): QuantityValue | null {
|
|
118
|
-
const leftUcum = getUcumQuantity(left);
|
|
119
|
-
const rightUcum = getUcumQuantity(right);
|
|
120
|
-
|
|
121
|
-
if (!leftUcum || !rightUcum) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
const result = ucum.multiply(leftUcum, rightUcum);
|
|
127
|
-
return {
|
|
128
|
-
value: result.value,
|
|
129
|
-
unit: result.unit
|
|
130
|
-
};
|
|
131
|
-
} catch (e) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Divide two quantities
|
|
138
|
-
*/
|
|
139
|
-
export function divideQuantities(left: QuantityValue, right: QuantityValue): QuantityValue | null {
|
|
140
|
-
const leftUcum = getUcumQuantity(left);
|
|
141
|
-
const rightUcum = getUcumQuantity(right);
|
|
142
|
-
|
|
143
|
-
if (!leftUcum || !rightUcum) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
const result = ucum.divide(leftUcum, rightUcum);
|
|
149
|
-
return {
|
|
150
|
-
value: result.value,
|
|
151
|
-
unit: result.unit
|
|
152
|
-
};
|
|
153
|
-
} catch (e) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Compare two quantities
|
|
160
|
-
* Returns -1 if left < right, 0 if equal, 1 if left > right, null if incomparable
|
|
161
|
-
*/
|
|
162
|
-
export function compareQuantities(left: QuantityValue, right: QuantityValue): number | null {
|
|
163
|
-
const leftUcum = getUcumQuantity(left);
|
|
164
|
-
const rightUcum = getUcumQuantity(right);
|
|
165
|
-
|
|
166
|
-
if (!leftUcum || !rightUcum) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
// Try to convert right to left's unit for comparison
|
|
172
|
-
const rightValue = ucum.convert(rightUcum.value, rightUcum.unit, leftUcum.unit);
|
|
173
|
-
if (leftUcum.value < rightValue) {
|
|
174
|
-
return -1;
|
|
175
|
-
} else if (leftUcum.value > rightValue) {
|
|
176
|
-
return 1;
|
|
177
|
-
} else {
|
|
178
|
-
return 0;
|
|
179
|
-
}
|
|
180
|
-
} catch (e) {
|
|
181
|
-
// Incompatible dimensions
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Check if two quantities are equal
|
|
188
|
-
*/
|
|
189
|
-
export function equalQuantities(left: QuantityValue, right: QuantityValue): boolean {
|
|
190
|
-
return compareQuantities(left, right) === 0;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Convert quantity to string representation
|
|
195
|
-
*/
|
|
196
|
-
export function quantityToString(quantity: QuantityValue): string {
|
|
197
|
-
return `${quantity.value} '${quantity.unit}'`;
|
|
198
|
-
}
|