@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.
Files changed (104) hide show
  1. package/README.md +62 -56
  2. package/dist/index.d.ts +368 -99
  3. package/dist/index.js +3623 -1253
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/analyzer.ts +779 -120
  7. package/src/boxing.ts +124 -0
  8. package/src/completion-provider.ts +636 -0
  9. package/src/cursor-nodes.ts +111 -0
  10. package/src/errors.ts +247 -0
  11. package/src/index.ts +97 -14
  12. package/src/inspect.ts +309 -176
  13. package/src/interpreter.ts +380 -71
  14. package/src/lexer.ts +1 -0
  15. package/src/model-provider.ts +282 -39
  16. package/src/operations/abs-function.ts +40 -16
  17. package/src/operations/aggregate-function.ts +21 -10
  18. package/src/operations/all-function.ts +23 -11
  19. package/src/operations/allFalse-function.ts +14 -9
  20. package/src/operations/allTrue-function.ts +14 -9
  21. package/src/operations/and-operator.ts +21 -12
  22. package/src/operations/anyFalse-function.ts +11 -7
  23. package/src/operations/anyTrue-function.ts +11 -7
  24. package/src/operations/as-operator.ts +2 -1
  25. package/src/operations/ceiling-function.ts +14 -8
  26. package/src/operations/children-function.ts +98 -0
  27. package/src/operations/combine-function.ts +10 -6
  28. package/src/operations/combine-operator.ts +19 -5
  29. package/src/operations/contains-function.ts +26 -12
  30. package/src/operations/contains-operator.ts +15 -7
  31. package/src/operations/count-function.ts +7 -4
  32. package/src/operations/defineVariable-function.ts +11 -7
  33. package/src/operations/descendants-function.ts +64 -0
  34. package/src/operations/distinct-function.ts +21 -7
  35. package/src/operations/div-operator.ts +16 -3
  36. package/src/operations/divide-operator.ts +11 -6
  37. package/src/operations/dot-operator.ts +4 -2
  38. package/src/operations/empty-function.ts +7 -4
  39. package/src/operations/endsWith-function.ts +28 -14
  40. package/src/operations/equal-operator.ts +19 -7
  41. package/src/operations/equivalent-operator.ts +16 -11
  42. package/src/operations/exclude-function.ts +18 -14
  43. package/src/operations/exists-function.ts +19 -10
  44. package/src/operations/first-function.ts +12 -7
  45. package/src/operations/floor-function.ts +14 -8
  46. package/src/operations/greater-operator.ts +10 -5
  47. package/src/operations/greater-or-equal-operator.ts +10 -5
  48. package/src/operations/iif-function.ts +27 -23
  49. package/src/operations/implies-operator.ts +23 -8
  50. package/src/operations/in-operator.ts +18 -8
  51. package/src/operations/index.ts +3 -0
  52. package/src/operations/indexOf-function.ts +28 -14
  53. package/src/operations/intersect-function.ts +23 -24
  54. package/src/operations/is-operator.ts +67 -15
  55. package/src/operations/isDistinct-function.ts +17 -9
  56. package/src/operations/join-function.ts +22 -9
  57. package/src/operations/last-function.ts +12 -7
  58. package/src/operations/length-function.ts +17 -8
  59. package/src/operations/less-operator.ts +10 -5
  60. package/src/operations/less-or-equal-operator.ts +10 -5
  61. package/src/operations/less-than.ts +26 -2
  62. package/src/operations/lower-function.ts +17 -8
  63. package/src/operations/minus-operator.ts +10 -5
  64. package/src/operations/mod-operator.ts +20 -3
  65. package/src/operations/multiply-operator.ts +12 -7
  66. package/src/operations/not-equal-operator.ts +16 -7
  67. package/src/operations/not-equivalent-operator.ts +16 -11
  68. package/src/operations/not-function.ts +17 -7
  69. package/src/operations/ofType-function.ts +139 -0
  70. package/src/operations/or-operator.ts +21 -12
  71. package/src/operations/plus-operator.ts +19 -7
  72. package/src/operations/power-function.ts +27 -13
  73. package/src/operations/replace-function.ts +33 -14
  74. package/src/operations/round-function.ts +29 -12
  75. package/src/operations/select-function.ts +17 -9
  76. package/src/operations/single-function.ts +10 -6
  77. package/src/operations/skip-function.ts +18 -9
  78. package/src/operations/split-function.ts +30 -13
  79. package/src/operations/sqrt-function.ts +14 -8
  80. package/src/operations/startsWith-function.ts +26 -12
  81. package/src/operations/subsetOf-function.ts +20 -15
  82. package/src/operations/substring-function.ts +43 -24
  83. package/src/operations/supersetOf-function.ts +20 -15
  84. package/src/operations/tail-function.ts +8 -4
  85. package/src/operations/take-function.ts +18 -9
  86. package/src/operations/toBoolean-function.ts +23 -14
  87. package/src/operations/toDecimal-function.ts +18 -9
  88. package/src/operations/toInteger-function.ts +22 -12
  89. package/src/operations/toString-function.ts +26 -16
  90. package/src/operations/trace-function.ts +19 -10
  91. package/src/operations/trim-function.ts +16 -7
  92. package/src/operations/truncate-function.ts +14 -8
  93. package/src/operations/unary-minus-operator.ts +23 -13
  94. package/src/operations/unary-plus-operator.ts +2 -1
  95. package/src/operations/union-function.ts +25 -28
  96. package/src/operations/union-operator.ts +2 -1
  97. package/src/operations/upper-function.ts +17 -8
  98. package/src/operations/where-function.ts +20 -11
  99. package/src/operations/xor-operator.ts +9 -4
  100. package/src/parser.ts +527 -8
  101. package/src/quantity-value.ts +4 -8
  102. package/src/registry.ts +147 -5
  103. package/src/types.ts +42 -19
  104. 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
+ }