sof-mssql 2.1.0 → 2.3.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.
Files changed (102) hide show
  1. package/dist/fhirpath/visitor.d.ts +78 -0
  2. package/dist/fhirpath/visitor.d.ts.map +1 -1
  3. package/dist/fhirpath/visitor.js +208 -11
  4. package/dist/fhirpath/visitor.js.map +1 -1
  5. package/dist/parser.d.ts +1 -1
  6. package/dist/parser.js +1 -1
  7. package/dist/queryGenerator/index.d.ts +0 -4
  8. package/dist/queryGenerator/index.d.ts.map +1 -1
  9. package/dist/queryGenerator/index.js +1 -9
  10. package/dist/queryGenerator/index.js.map +1 -1
  11. package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts +26 -0
  12. package/dist/queryGenerator/treeWalker/aliasGenerator.d.ts.map +1 -0
  13. package/dist/queryGenerator/treeWalker/aliasGenerator.js +31 -0
  14. package/dist/queryGenerator/treeWalker/aliasGenerator.js.map +1 -0
  15. package/dist/queryGenerator/treeWalker/classify.d.ts +19 -0
  16. package/dist/queryGenerator/treeWalker/classify.d.ts.map +1 -0
  17. package/dist/queryGenerator/treeWalker/classify.js +36 -0
  18. package/dist/queryGenerator/treeWalker/classify.js.map +1 -0
  19. package/dist/queryGenerator/treeWalker/compile.d.ts +29 -0
  20. package/dist/queryGenerator/treeWalker/compile.d.ts.map +1 -0
  21. package/dist/queryGenerator/treeWalker/compile.js +97 -0
  22. package/dist/queryGenerator/treeWalker/compile.js.map +1 -0
  23. package/dist/queryGenerator/treeWalker/cteTemplates.d.ts +58 -0
  24. package/dist/queryGenerator/treeWalker/cteTemplates.d.ts.map +1 -0
  25. package/dist/queryGenerator/treeWalker/cteTemplates.js +131 -0
  26. package/dist/queryGenerator/treeWalker/cteTemplates.js.map +1 -0
  27. package/dist/queryGenerator/treeWalker/index.d.ts +6 -0
  28. package/dist/queryGenerator/treeWalker/index.d.ts.map +1 -0
  29. package/dist/queryGenerator/treeWalker/index.js +9 -0
  30. package/dist/queryGenerator/treeWalker/index.js.map +1 -0
  31. package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts +28 -0
  32. package/dist/queryGenerator/treeWalker/mergeSiblings.d.ts.map +1 -0
  33. package/dist/queryGenerator/treeWalker/mergeSiblings.js +54 -0
  34. package/dist/queryGenerator/treeWalker/mergeSiblings.js.map +1 -0
  35. package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts +40 -0
  36. package/dist/queryGenerator/treeWalker/operators/columnsOnly.d.ts.map +1 -0
  37. package/dist/queryGenerator/treeWalker/operators/columnsOnly.js +56 -0
  38. package/dist/queryGenerator/treeWalker/operators/columnsOnly.js.map +1 -0
  39. package/dist/queryGenerator/treeWalker/operators/forEach.d.ts +47 -0
  40. package/dist/queryGenerator/treeWalker/operators/forEach.d.ts.map +1 -0
  41. package/dist/queryGenerator/treeWalker/operators/forEach.js +150 -0
  42. package/dist/queryGenerator/treeWalker/operators/forEach.js.map +1 -0
  43. package/dist/queryGenerator/treeWalker/operators/group.d.ts +35 -0
  44. package/dist/queryGenerator/treeWalker/operators/group.d.ts.map +1 -0
  45. package/dist/queryGenerator/treeWalker/operators/group.js +56 -0
  46. package/dist/queryGenerator/treeWalker/operators/group.js.map +1 -0
  47. package/dist/queryGenerator/treeWalker/operators/repeat.d.ts +47 -0
  48. package/dist/queryGenerator/treeWalker/operators/repeat.d.ts.map +1 -0
  49. package/dist/queryGenerator/treeWalker/operators/repeat.js +122 -0
  50. package/dist/queryGenerator/treeWalker/operators/repeat.js.map +1 -0
  51. package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts +54 -0
  52. package/dist/queryGenerator/treeWalker/operators/unionAll.d.ts.map +1 -0
  53. package/dist/queryGenerator/treeWalker/operators/unionAll.js +121 -0
  54. package/dist/queryGenerator/treeWalker/operators/unionAll.js.map +1 -0
  55. package/dist/queryGenerator/treeWalker/render.d.ts +34 -0
  56. package/dist/queryGenerator/treeWalker/render.d.ts.map +1 -0
  57. package/dist/queryGenerator/treeWalker/render.js +41 -0
  58. package/dist/queryGenerator/treeWalker/render.js.map +1 -0
  59. package/dist/queryGenerator/treeWalker/types.d.ts +64 -0
  60. package/dist/queryGenerator/treeWalker/types.d.ts.map +1 -0
  61. package/dist/queryGenerator/treeWalker/types.js +14 -0
  62. package/dist/queryGenerator/treeWalker/types.js.map +1 -0
  63. package/dist/queryGenerator/treeWalker/walker.d.ts +36 -0
  64. package/dist/queryGenerator/treeWalker/walker.d.ts.map +1 -0
  65. package/dist/queryGenerator/treeWalker/walker.js +58 -0
  66. package/dist/queryGenerator/treeWalker/walker.js.map +1 -0
  67. package/dist/queryGenerator.d.ts +8 -94
  68. package/dist/queryGenerator.d.ts.map +1 -1
  69. package/dist/queryGenerator.js +16 -268
  70. package/dist/queryGenerator.js.map +1 -1
  71. package/dist/tests/utils/database.d.ts +2 -0
  72. package/dist/tests/utils/database.d.ts.map +1 -1
  73. package/dist/tests/utils/database.js +10 -1
  74. package/dist/tests/utils/database.js.map +1 -1
  75. package/dist/tests/utils/generator.d.ts +2 -0
  76. package/dist/tests/utils/generator.d.ts.map +1 -1
  77. package/dist/tests/utils/generator.js +24 -0
  78. package/dist/tests/utils/generator.js.map +1 -1
  79. package/dist/tests/utils/reporter.d.ts +1 -1
  80. package/dist/tests/utils/reporter.d.ts.map +1 -1
  81. package/dist/tests/utils/reporter.js +5 -4
  82. package/dist/tests/utils/reporter.js.map +1 -1
  83. package/dist/tests/utils/types.d.ts +1 -1
  84. package/dist/tests/utils/types.js +1 -1
  85. package/dist/types.d.ts +1 -1
  86. package/package.json +2 -1
  87. package/dist/queryGenerator/ForEachProcessor.d.ts +0 -127
  88. package/dist/queryGenerator/ForEachProcessor.d.ts.map +0 -1
  89. package/dist/queryGenerator/ForEachProcessor.js +0 -351
  90. package/dist/queryGenerator/ForEachProcessor.js.map +0 -1
  91. package/dist/queryGenerator/RepeatProcessor.d.ts +0 -177
  92. package/dist/queryGenerator/RepeatProcessor.d.ts.map +0 -1
  93. package/dist/queryGenerator/RepeatProcessor.js +0 -336
  94. package/dist/queryGenerator/RepeatProcessor.js.map +0 -1
  95. package/dist/queryGenerator/SelectClauseBuilder.d.ts +0 -108
  96. package/dist/queryGenerator/SelectClauseBuilder.d.ts.map +0 -1
  97. package/dist/queryGenerator/SelectClauseBuilder.js +0 -346
  98. package/dist/queryGenerator/SelectClauseBuilder.js.map +0 -1
  99. package/dist/queryGenerator/SelectCombinationExpander.d.ts +0 -42
  100. package/dist/queryGenerator/SelectCombinationExpander.d.ts.map +0 -1
  101. package/dist/queryGenerator/SelectCombinationExpander.js +0 -95
  102. package/dist/queryGenerator/SelectCombinationExpander.js.map +0 -1
@@ -1,177 +0,0 @@
1
- /**
2
- * Processes repeat operations and generates recursive CTEs.
3
- *
4
- * The repeat directive recursively traverses a tree structure by following
5
- * one or more FHIRPath expressions at each level. This is implemented using
6
- * SQL Server recursive Common Table Expressions (CTEs).
7
- *
8
- * @author John Grimes
9
- */
10
- import type { TranspilerContext } from "../fhirpath/transpiler.js";
11
- import { ViewDefinitionSelect } from "../types.js";
12
- import { SelectCombination } from "./SelectCombinationExpander.js";
13
- /**
14
- * Counter state for generating unique repeat CTE aliases.
15
- */
16
- interface CounterState {
17
- value: number;
18
- }
19
- /**
20
- * Context specific to a repeat operation.
21
- */
22
- export interface RepeatContext {
23
- /** Unique alias for the CTE (e.g., "repeat_0"). */
24
- cteAlias: string;
25
- /** FHIRPath expressions to follow recursively. */
26
- paths: string[];
27
- /** JSON source expression for the anchor member. */
28
- sourceExpression: string;
29
- /** The transpiler context for columns within this repeat. */
30
- transpilerContext: TranspilerContext;
31
- }
32
- /**
33
- * Result of building repeat context map.
34
- */
35
- export interface RepeatContextMapResult {
36
- repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>;
37
- topLevelRepeat: ViewDefinitionSelect[];
38
- }
39
- /**
40
- * Handles all repeat-related processing and recursive CTE generation.
41
- *
42
- * The repeat directive works similarly to forEach but traverses tree structures
43
- * of arbitrary depth. For example, `repeat: ["item"]` follows the `item` array
44
- * at each level until no more items exist.
45
- *
46
- * Multiple paths can be specified (e.g., `["item", "answer.item"]`) to follow
47
- * different traversal patterns at each level, with results unioned together.
48
- */
49
- export declare class RepeatProcessor {
50
- /**
51
- * Check if a specific combination has repeat operations.
52
- *
53
- * @param combination - The select combination to check.
54
- * @returns True if any select in the combination has repeat.
55
- */
56
- combinationHasRepeat(combination: SelectCombination): boolean;
57
- /**
58
- * Check if a single select has repeat operations (including nested).
59
- *
60
- * @param select - The select element to check.
61
- * @returns True if the select or any nested select has repeat.
62
- */
63
- selectHasRepeat(select: ViewDefinitionSelect): boolean;
64
- /**
65
- * Check if any select in the array has repeat operations.
66
- */
67
- private hasRepeatInSelects;
68
- /**
69
- * Check if any unionAll option has repeat operations.
70
- */
71
- private unionAllHasRepeat;
72
- /**
73
- * Check if a select is a repeat select.
74
- */
75
- isRepeatSelect(select: ViewDefinitionSelect): boolean;
76
- /**
77
- * Build the repeat context map by generating contexts for all repeat operations.
78
- *
79
- * @param selects - The top-level select elements.
80
- * @param context - The base transpiler context.
81
- * @param combination - Optional combination for unionAll handling.
82
- * @param externalCounter - Optional external counter for shared CTE aliases across combinations.
83
- * @returns Map of repeat selects to their contexts and list of top-level repeats.
84
- */
85
- buildRepeatContextMap(selects: ViewDefinitionSelect[], context: TranspilerContext, combination?: SelectCombination, externalCounter?: CounterState): RepeatContextMapResult;
86
- /**
87
- * Collect all repeat selects that should be treated as top-level.
88
- */
89
- private collectTopLevelRepeat;
90
- /**
91
- * Process a select for repeat, handling both direct repeat and nested selects.
92
- */
93
- private processSelectRepeat;
94
- /**
95
- * Process a select with a unionAll choice from a combination.
96
- */
97
- private processUnionAllChoice;
98
- /**
99
- * Add repeat selects from a select array to the topLevelRepeat list.
100
- */
101
- private addRepeatFromSelectArray;
102
- /**
103
- * Generate repeat context for a single repeat select.
104
- */
105
- private generateRepeatContext;
106
- /**
107
- * Generate CTE definitions as an array for repeat operations.
108
- *
109
- * This method returns the CTE definitions without the WITH keyword,
110
- * allowing them to be consolidated when multiple unionAll branches
111
- * each have their own repeat CTEs.
112
- *
113
- * @param repeatContextMap - Map of repeat selects to their contexts.
114
- * @param topLevelRepeat - List of top-level repeat selects.
115
- * @param resourceAlias - The alias for the resource table (e.g., "r").
116
- * @param resourceType - The FHIR resource type.
117
- * @param testId - Optional test ID for filtering.
118
- * @param tableName - The fully qualified table name (e.g., "[dbo].[fhir_resources]").
119
- * @returns Array of CTE definition strings (without WITH keyword).
120
- */
121
- buildRepeatCteDefinitions(repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>, topLevelRepeat: ViewDefinitionSelect[], resourceAlias: string, resourceType: string, testId?: string, tableName?: string): string[];
122
- /**
123
- * Generate a single recursive CTE definition.
124
- *
125
- * The CTE has the following structure:
126
- * - Anchor member: Selects initial items using the FIRST path from the root.
127
- * Only the first path is used for the anchor because subsequent paths
128
- * (like `answer.item`) represent traversal patterns that should only be
129
- * followed during recursion, not at the root level.
130
- * - Recursive member: For each path in repeat, follows that path from the
131
- * current level and unions all results.
132
- *
133
- * The CTE columns are:
134
- * - resource_id: Links back to the source resource.
135
- * - item_json: The JSON content of the current item (used for column extraction).
136
- * - depth: Recursion depth (used to prevent infinite loops).
137
- */
138
- private generateSingleCte;
139
- /**
140
- * Build a recursive member for a single path.
141
- *
142
- * Multi-segment paths like "answer.item" require nested CROSS APPLY clauses
143
- * to traverse through each array. For example, "answer.item" means:
144
- * 1. Iterate over the `answer` array
145
- * 2. For each answer, iterate over the `item` array within it
146
- *
147
- * @param path - The FHIRPath expression (e.g., "item" or "answer.item").
148
- * @param cteAlias - The alias of the recursive CTE.
149
- * @param index - Index of this path for alias generation.
150
- * @returns SQL fragment for the recursive member.
151
- */
152
- private buildRecursiveMember;
153
- /**
154
- * Build a JSON path from a FHIRPath expression.
155
- * Handles simple paths and dot-separated paths like "answer.item".
156
- */
157
- private buildJsonPath;
158
- /**
159
- * Build the test ID condition for filtering test data.
160
- *
161
- * @param resourceAlias - The alias for the resource table.
162
- * @param testId - Optional test ID for filtering.
163
- * @returns SQL condition string or empty string if no testId.
164
- */
165
- private buildTestIdCondition;
166
- /**
167
- * Build CROSS APPLY clause to join CTE results to the main query.
168
- *
169
- * @param repeatContextMap - Map of repeat selects to their contexts.
170
- * @param topLevelRepeat - List of top-level repeat selects.
171
- * @param resourceAlias - The alias for the resource table.
172
- * @returns The CROSS APPLY clause(s) for joining CTE results.
173
- */
174
- buildRepeatApplyClauses(repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>, topLevelRepeat: ViewDefinitionSelect[], resourceAlias: string): string;
175
- }
176
- export {};
177
- //# sourceMappingURL=RepeatProcessor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RepeatProcessor.d.ts","sourceRoot":"","sources":["../../src/queryGenerator/RepeatProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;GAEG;AACH,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,oDAAoD;IACpD,gBAAgB,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,GAAG,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;IAC3D,cAAc,EAAE,oBAAoB,EAAE,CAAC;CACxC;AAED;;;;;;;;;GASG;AACH,qBAAa,eAAe;IAC1B;;;;;OAKG;IACH,oBAAoB,CA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MAAM;CAqBV"}
@@ -1,336 +0,0 @@
1
- "use strict";
2
- /**
3
- * Processes repeat operations and generates recursive CTEs.
4
- *
5
- * The repeat directive recursively traverses a tree structure by following
6
- * one or more FHIRPath expressions at each level. This is implemented using
7
- * SQL Server recursive Common Table Expressions (CTEs).
8
- *
9
- * @author John Grimes
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RepeatProcessor = void 0;
13
- /**
14
- * Handles all repeat-related processing and recursive CTE generation.
15
- *
16
- * The repeat directive works similarly to forEach but traverses tree structures
17
- * of arbitrary depth. For example, `repeat: ["item"]` follows the `item` array
18
- * at each level until no more items exist.
19
- *
20
- * Multiple paths can be specified (e.g., `["item", "answer.item"]`) to follow
21
- * different traversal patterns at each level, with results unioned together.
22
- */
23
- class RepeatProcessor {
24
- /**
25
- * Check if a specific combination has repeat operations.
26
- *
27
- * @param combination - The select combination to check.
28
- * @returns True if any select in the combination has repeat.
29
- */
30
- combinationHasRepeat(combination) {
31
- for (let i = 0; i < combination.selects.length; i++) {
32
- const select = combination.selects[i];
33
- const unionChoice = combination.unionChoices[i];
34
- if (this.selectHasRepeat(select)) {
35
- return true;
36
- }
37
- // If this select has a unionAll choice, also check the chosen branch.
38
- if (unionChoice >= 0 && select.unionAll?.[unionChoice]) {
39
- const chosenBranch = select.unionAll[unionChoice];
40
- if (this.selectHasRepeat(chosenBranch)) {
41
- return true;
42
- }
43
- }
44
- }
45
- return false;
46
- }
47
- /**
48
- * Check if a single select has repeat operations (including nested).
49
- *
50
- * @param select - The select element to check.
51
- * @returns True if the select or any nested select has repeat.
52
- */
53
- selectHasRepeat(select) {
54
- if (this.isRepeatSelect(select)) {
55
- return true;
56
- }
57
- if (select.select && this.hasRepeatInSelects(select.select)) {
58
- return true;
59
- }
60
- return !!(select.unionAll && this.unionAllHasRepeat(select.unionAll));
61
- }
62
- /**
63
- * Check if any select in the array has repeat operations.
64
- */
65
- hasRepeatInSelects(selects) {
66
- return selects.some((select) => this.selectHasRepeat(select));
67
- }
68
- /**
69
- * Check if any unionAll option has repeat operations.
70
- */
71
- unionAllHasRepeat(unionAllOptions) {
72
- return unionAllOptions.some((unionOption) => this.isRepeatSelect(unionOption) ||
73
- (unionOption.select && this.hasRepeatInSelects(unionOption.select)));
74
- }
75
- /**
76
- * Check if a select is a repeat select.
77
- */
78
- isRepeatSelect(select) {
79
- return !!(select.repeat && select.repeat.length > 0);
80
- }
81
- /**
82
- * Build the repeat context map by generating contexts for all repeat operations.
83
- *
84
- * @param selects - The top-level select elements.
85
- * @param context - The base transpiler context.
86
- * @param combination - Optional combination for unionAll handling.
87
- * @param externalCounter - Optional external counter for shared CTE aliases across combinations.
88
- * @returns Map of repeat selects to their contexts and list of top-level repeats.
89
- */
90
- buildRepeatContextMap(selects, context, combination, externalCounter) {
91
- const repeatContextMap = new Map();
92
- // Use external counter if provided, otherwise create a local one.
93
- const counterState = externalCounter ?? { value: 0 };
94
- const topLevelRepeat = this.collectTopLevelRepeat(selects, combination);
95
- for (const select of topLevelRepeat) {
96
- this.generateRepeatContext(select, context.resourceAlias + ".json", context, repeatContextMap, counterState);
97
- }
98
- return { repeatContextMap, topLevelRepeat };
99
- }
100
- /**
101
- * Collect all repeat selects that should be treated as top-level.
102
- */
103
- collectTopLevelRepeat(selects, combination) {
104
- const topLevelRepeat = [];
105
- for (const select of selects) {
106
- this.processSelectRepeat(select, topLevelRepeat);
107
- // Also process unionAll choices if present and parent doesn't have repeat.
108
- if (combination && !this.isRepeatSelect(select)) {
109
- this.processUnionAllChoice(select, combination, topLevelRepeat);
110
- }
111
- }
112
- return topLevelRepeat;
113
- }
114
- /**
115
- * Process a select for repeat, handling both direct repeat and nested selects.
116
- */
117
- processSelectRepeat(select, topLevelRepeat) {
118
- if (this.isRepeatSelect(select)) {
119
- topLevelRepeat.push(select);
120
- }
121
- else if (select.select) {
122
- this.addRepeatFromSelectArray(select.select, topLevelRepeat);
123
- }
124
- }
125
- /**
126
- * Process a select with a unionAll choice from a combination.
127
- */
128
- processUnionAllChoice(select, combination, topLevelRepeat) {
129
- const selectIndex = combination.selects.indexOf(select);
130
- const unionChoice = selectIndex >= 0 ? combination.unionChoices[selectIndex] : -1;
131
- if (unionChoice >= 0 && select.unionAll?.[unionChoice]) {
132
- const chosenBranch = select.unionAll[unionChoice];
133
- if (this.isRepeatSelect(chosenBranch)) {
134
- topLevelRepeat.push(chosenBranch);
135
- }
136
- else if (chosenBranch.select) {
137
- this.addRepeatFromSelectArray(chosenBranch.select, topLevelRepeat);
138
- }
139
- }
140
- }
141
- /**
142
- * Add repeat selects from a select array to the topLevelRepeat list.
143
- */
144
- addRepeatFromSelectArray(selects, topLevelRepeat) {
145
- for (const nestedSelect of selects) {
146
- if (this.isRepeatSelect(nestedSelect)) {
147
- topLevelRepeat.push(nestedSelect);
148
- }
149
- }
150
- }
151
- /**
152
- * Generate repeat context for a single repeat select.
153
- */
154
- generateRepeatContext(repeatSelect, sourceExpression, baseContext, repeatContextMap, counterState) {
155
- const cteAlias = `repeat_${counterState.value++}`;
156
- const paths = repeatSelect.repeat ?? [];
157
- const repeatContext = {
158
- cteAlias,
159
- paths,
160
- sourceExpression,
161
- transpilerContext: {
162
- ...baseContext,
163
- // The iteration context points to the CTE's item_json column.
164
- iterationContext: `${cteAlias}.item_json`,
165
- currentForEachAlias: cteAlias,
166
- forEachSource: sourceExpression,
167
- forEachPath: paths.join(", "),
168
- },
169
- };
170
- repeatContextMap.set(repeatSelect, repeatContext);
171
- }
172
- /**
173
- * Generate CTE definitions as an array for repeat operations.
174
- *
175
- * This method returns the CTE definitions without the WITH keyword,
176
- * allowing them to be consolidated when multiple unionAll branches
177
- * each have their own repeat CTEs.
178
- *
179
- * @param repeatContextMap - Map of repeat selects to their contexts.
180
- * @param topLevelRepeat - List of top-level repeat selects.
181
- * @param resourceAlias - The alias for the resource table (e.g., "r").
182
- * @param resourceType - The FHIR resource type.
183
- * @param testId - Optional test ID for filtering.
184
- * @param tableName - The fully qualified table name (e.g., "[dbo].[fhir_resources]").
185
- * @returns Array of CTE definition strings (without WITH keyword).
186
- */
187
- buildRepeatCteDefinitions(repeatContextMap, topLevelRepeat, resourceAlias, resourceType, testId, tableName = "[dbo].[fhir_resources]") {
188
- if (topLevelRepeat.length === 0) {
189
- return [];
190
- }
191
- const cteDefinitions = [];
192
- for (const select of topLevelRepeat) {
193
- const repeatContext = repeatContextMap.get(select);
194
- if (!repeatContext) {
195
- throw new Error("Repeat context not found for select.");
196
- }
197
- const cteDef = this.generateSingleCte(repeatContext, resourceAlias, resourceType, testId, tableName);
198
- cteDefinitions.push(cteDef);
199
- }
200
- return cteDefinitions;
201
- }
202
- /**
203
- * Generate a single recursive CTE definition.
204
- *
205
- * The CTE has the following structure:
206
- * - Anchor member: Selects initial items using the FIRST path from the root.
207
- * Only the first path is used for the anchor because subsequent paths
208
- * (like `answer.item`) represent traversal patterns that should only be
209
- * followed during recursion, not at the root level.
210
- * - Recursive member: For each path in repeat, follows that path from the
211
- * current level and unions all results.
212
- *
213
- * The CTE columns are:
214
- * - resource_id: Links back to the source resource.
215
- * - item_json: The JSON content of the current item (used for column extraction).
216
- * - depth: Recursion depth (used to prevent infinite loops).
217
- */
218
- generateSingleCte(repeatContext, resourceAlias, resourceType, testId, tableName = "[dbo].[fhir_resources]") {
219
- const { cteAlias, paths, sourceExpression } = repeatContext;
220
- // Build anchor member using only the FIRST path.
221
- // The anchor represents the entry point into the tree structure.
222
- // For example, with `repeat: ["item", "answer.item"]`, the anchor uses
223
- // `$.item` to get the root items. The `answer.item` path is only followed
224
- // during recursion when traversing from an item that has answers.
225
- const firstPath = paths[0];
226
- const anchorJsonPath = this.buildJsonPath(firstPath);
227
- const anchorSql = `SELECT
228
- [${resourceAlias}].[id] AS resource_id,
229
- anchor.value AS item_json,
230
- 0 AS depth
231
- FROM ${tableName} AS [${resourceAlias}]
232
- CROSS APPLY OPENJSON(${sourceExpression}, '${anchorJsonPath}') AS anchor
233
- WHERE [${resourceAlias}].[resource_type] = '${resourceType}'${this.buildTestIdCondition(resourceAlias, testId)}`;
234
- // Build recursive member: for each path, follows that path from current item.
235
- // All paths are used during recursion to traverse the tree structure.
236
- // Multi-segment paths like "answer.item" require nested CROSS APPLY.
237
- const recursiveMembers = paths.map((path, index) => {
238
- return this.buildRecursiveMember(path, cteAlias, index);
239
- });
240
- const recursiveSql = recursiveMembers.join("\n UNION ALL\n");
241
- return `${cteAlias} AS (
242
- ${anchorSql}
243
- UNION ALL
244
- ${recursiveSql}
245
- )`;
246
- }
247
- /**
248
- * Build a recursive member for a single path.
249
- *
250
- * Multi-segment paths like "answer.item" require nested CROSS APPLY clauses
251
- * to traverse through each array. For example, "answer.item" means:
252
- * 1. Iterate over the `answer` array
253
- * 2. For each answer, iterate over the `item` array within it
254
- *
255
- * @param path - The FHIRPath expression (e.g., "item" or "answer.item").
256
- * @param cteAlias - The alias of the recursive CTE.
257
- * @param index - Index of this path for alias generation.
258
- * @returns SQL fragment for the recursive member.
259
- */
260
- buildRecursiveMember(path, cteAlias, index) {
261
- const segments = path.split(".");
262
- if (segments.length === 1) {
263
- // Simple path: single CROSS APPLY.
264
- const jsonPath = `$.${segments[0]}`;
265
- const alias = `child_${index}`;
266
- return `SELECT
267
- cte.resource_id,
268
- ${alias}.value AS item_json,
269
- cte.depth + 1
270
- FROM ${cteAlias} AS cte
271
- CROSS APPLY OPENJSON(cte.item_json, '${jsonPath}') AS ${alias}`;
272
- }
273
- // Multi-segment path: nested CROSS APPLY for each segment.
274
- // Build from inside out: the last segment is the final result.
275
- let crossApplies = "";
276
- let currentSource = "cte.item_json";
277
- for (let i = 0; i < segments.length; i++) {
278
- const segment = segments[i];
279
- const alias = `child_${index}_${i}`;
280
- crossApplies += `\n CROSS APPLY OPENJSON(${currentSource}, '$.${segment}') AS ${alias}`;
281
- currentSource = `${alias}.value`;
282
- }
283
- const finalAlias = `child_${index}_${segments.length - 1}`;
284
- return `SELECT
285
- cte.resource_id,
286
- ${finalAlias}.value AS item_json,
287
- cte.depth + 1
288
- FROM ${cteAlias} AS cte${crossApplies}`;
289
- }
290
- /**
291
- * Build a JSON path from a FHIRPath expression.
292
- * Handles simple paths and dot-separated paths like "answer.item".
293
- */
294
- buildJsonPath(fhirPath) {
295
- // Convert FHIRPath to JSON path (simple case: just prefix with $.).
296
- return `$.${fhirPath}`;
297
- }
298
- /**
299
- * Build the test ID condition for filtering test data.
300
- *
301
- * @param resourceAlias - The alias for the resource table.
302
- * @param testId - Optional test ID for filtering.
303
- * @returns SQL condition string or empty string if no testId.
304
- */
305
- buildTestIdCondition(resourceAlias, testId) {
306
- if (!testId) {
307
- return "";
308
- }
309
- return `\n AND [${resourceAlias}].[test_id] = '${testId}'`;
310
- }
311
- /**
312
- * Build CROSS APPLY clause to join CTE results to the main query.
313
- *
314
- * @param repeatContextMap - Map of repeat selects to their contexts.
315
- * @param topLevelRepeat - List of top-level repeat selects.
316
- * @param resourceAlias - The alias for the resource table.
317
- * @returns The CROSS APPLY clause(s) for joining CTE results.
318
- */
319
- buildRepeatApplyClauses(repeatContextMap, topLevelRepeat, resourceAlias) {
320
- if (topLevelRepeat.length === 0) {
321
- return "";
322
- }
323
- const applyClauses = [];
324
- for (const select of topLevelRepeat) {
325
- const repeatContext = repeatContextMap.get(select);
326
- if (!repeatContext) {
327
- throw new Error("Repeat context not found for select.");
328
- }
329
- // Join the CTE to the resource table by resource_id.
330
- applyClauses.push(`\nINNER JOIN ${repeatContext.cteAlias} ON ${repeatContext.cteAlias}.resource_id = [${resourceAlias}].[id]`);
331
- }
332
- return applyClauses.join("");
333
- }
334
- }
335
- exports.RepeatProcessor = RepeatProcessor;
336
- //# sourceMappingURL=RepeatProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RepeatProcessor.js","sourceRoot":"","sources":["../../src/queryGenerator/RepeatProcessor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAmCH;;;;;;;;;GASG;AACH,MAAa,eAAe;IAC1B;;;;;OAKG;IACH,oBAAoB,CAAC,W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,CAAC;QACZ,CAAC;QACD,OAAO,cAAc,aAAa,kBAAkB,MAAM,GAAG,CAAC;IAChE,CAAC;IAED;;;;;;;OAOG;IACH,uBAAuB,CACrB,gBAA0D,EAC1D,cAAsC,EACtC,aAAqB;QAErB,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,YAAY,GAAa,EAAE,CAAC;QAElC,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE,CAAC;YACpC,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACnD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YAED,qDAAqD;YACrD,YAAY,CAAC,IAAI,CACf,gBAAgB,aAAa,CAAC,QAAQ,OAAO,aAAa,CAAC,QAAQ,mBAAmB,aAAa,QAAQ,CAC5G,CAAC;QACJ,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;CACF;AAjaD,0CAiaC"}
@@ -1,108 +0,0 @@
1
- /**
2
- * Builds SELECT clauses for SQL queries.
3
- */
4
- import { TranspilerContext } from "../fhirpath/transpiler.js";
5
- import { ViewDefinitionSelect } from "../types.js";
6
- import { SelectCombination } from "./SelectCombinationExpander.js";
7
- import { ColumnExpressionGenerator } from "./ColumnExpressionGenerator.js";
8
- import { RepeatContext } from "./RepeatProcessor.js";
9
- /**
10
- * Handles generation of SELECT clauses.
11
- */
12
- export declare class SelectClauseBuilder {
13
- private readonly columnGenerator;
14
- constructor(columnGenerator: ColumnExpressionGenerator);
15
- /**
16
- * Generate SELECT clause for a simple (non-forEach) statement.
17
- */
18
- generateSimpleSelectClause(combination: SelectCombination, context: TranspilerContext): string;
19
- /**
20
- * Generate SELECT clause specifically for forEach statements.
21
- */
22
- generateForEachSelectClause(combination: SelectCombination, context: TranspilerContext, forEachContextMap: Map<ViewDefinitionSelect, TranspilerContext>): string;
23
- /**
24
- * Generate SELECT clause for repeat statements.
25
- *
26
- * For repeat selects, columns are extracted from the CTE's item_json column.
27
- * Non-repeat columns use the base context (resource JSON).
28
- * If forEach is also present, those columns use the forEach context.
29
- *
30
- * @param combination - The select combination being processed.
31
- * @param context - The base transpiler context.
32
- * @param repeatContextMap - Map of repeat selects to their contexts.
33
- * @param forEachContextMap - Optional map of forEach selects to their contexts.
34
- * @returns The generated SELECT clause.
35
- */
36
- generateRepeatSelectClause(combination: SelectCombination, context: TranspilerContext, repeatContextMap: Map<ViewDefinitionSelect, RepeatContext>, forEachContextMap?: Map<ViewDefinitionSelect, TranspilerContext>): string;
37
- /**
38
- * Add columns for a repeat select.
39
- *
40
- * Columns within the repeat use the repeat context (CTE item_json).
41
- * Nested forEach within the repeat use their forEach context.
42
- */
43
- private addRepeatSelectColumns;
44
- /**
45
- * Add nested select columns for a repeat select.
46
- *
47
- * Nested forEach selects use their own context, while other nested selects
48
- * use the repeat context.
49
- */
50
- private addNestedSelectColumnsForRepeat;
51
- /**
52
- * Add columns for unionAll branches within a repeat select.
53
- */
54
- private addRepeatUnionAllColumns;
55
- /**
56
- * Add columns for a non-repeat select (when repeat is present elsewhere).
57
- */
58
- private addNonRepeatSelectColumns;
59
- /**
60
- * Add unionAll columns when repeat context is available.
61
- */
62
- private addUnionAllColumnsForRepeatContext;
63
- /**
64
- * Check if a select is a repeat select.
65
- */
66
- private isRepeatSelect;
67
- /**
68
- * Add columns from a select element to the column parts array.
69
- */
70
- private addSelectElementColumns;
71
- /**
72
- * Generate column expressions for a select element (used for nested selects).
73
- */
74
- private generateSelectElementColumns;
75
- /**
76
- * Add unionAll columns for the chosen combination.
77
- */
78
- private addUnionAllColumns;
79
- /**
80
- * Add columns for a forEach select.
81
- */
82
- private addForEachSelectColumns;
83
- /**
84
- * Add columns for a non-forEach select.
85
- */
86
- private addNonForEachSelectColumns;
87
- /**
88
- * Add nested select columns for forEach select.
89
- */
90
- private addNestedSelectColumnsForForEach;
91
- /**
92
- * Add nested select columns for non-forEach select.
93
- */
94
- private addNestedSelectColumnsForNonForEach;
95
- /**
96
- * Add unionAll columns for a select.
97
- */
98
- private addUnionAllColumnsForSelect;
99
- /**
100
- * Add columns to the column parts list.
101
- */
102
- private addColumnsToList;
103
- /**
104
- * Check if a select is a forEach or forEachOrNull.
105
- */
106
- private isForEachSelect;
107
- }
108
- //# sourceMappingURL=SelectClauseBuilder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectClauseBuilder.d.ts","sourceRoot":"","sources":["../../src/queryGenerator/SelectClauseBuilder.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAwB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4B;gBAEhD,eAAe,EAAE,yBAAyB;IAItD;;OAEG;IACH,0BAA0B,CACxB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,iBAAiB,GACzB,MAAM;IAcT;;OAEG;IACH,2BAA2B,CACzB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,iBAAiB,EAC1B,iBAAiB,EAAE,GAAG,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,GAC9D,MAAM;IA4BT;;;;;;;;;;;;OAYG;IACH,0BAA0B,CACxB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,iBAAiB,EAC1B,gBAAgB,EAAE,GAAG,CAAC,oBAAoB,EAAE,aAAa,CAAC,EAC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