Commit eb036e2
committed
Fix .first() transpilation in forEach with .where() filtering
Previously, .first() was incorrectly converted to [0] array indexing,
which applied index filtering BEFORE the WHERE condition. This caused
queries to fail when the desired element was not at index 0.
For example, in blood pressure observations where:
- component[0] = diastolic (8462-4)
- component[1] = systolic (8480-6)
The query `component.where(code='8480-6').first()` would incorrectly
check only index 0 (which has code 8462-4), returning no results.
Changes:
- Modified FhirPathWhereResult interface to include useFirst flag
- Updated parseFhirPathWhere() to detect .first() and set flag instead
of converting to [0]
- Modified ForEachProcessor.buildSimpleApplyClause() to use TOP 1 with
ORDER BY [key] when useFirst is true
- This generates: SELECT TOP 1 * ... WHERE condition ORDER BY [key]
- Correctly filters all elements first, then takes the first match
The fix ensures .first() applies to filtered results, not to
pre-filtered array positions.1 parent 6a54a14 commit eb036e2
2 files changed
+24
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
386 | | - | |
387 | | - | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
388 | 391 | | |
389 | 392 | | |
390 | 393 | | |
| |||
407 | 410 | | |
408 | 411 | | |
409 | 412 | | |
| 413 | + | |
410 | 414 | | |
411 | 415 | | |
412 | 416 | | |
| |||
420 | 424 | | |
421 | 425 | | |
422 | 426 | | |
| 427 | + | |
423 | 428 | | |
424 | 429 | | |
425 | 430 | | |
426 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
427 | 438 | | |
428 | | - | |
429 | | - | |
| 439 | + | |
| 440 | + | |
430 | 441 | | |
431 | 442 | | |
432 | 443 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| 125 | + | |
123 | 126 | | |
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
| 132 | + | |
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| |||
0 commit comments