Commit ccfc3bd
committed
Fix forEach .where() parsing with nested parentheses and .first()
Fixed two issues in PathParser.parseFhirPathWhere():
1. Replaced greedy regex with balanced parenthesis counting
- Old: /^(.+)\.where\((.*)\)$/ would match to the LAST )
- New: Counts opening/closing parens to find matching )
- Fixes: "component.where(code.coding.exists(...)).first()"
2. Convert .first() to [0] array indexing
- .first() after .where() is now converted to [0]
- Results in correct SQL: WHERE [key] = '0'
This allows forEach paths like:
component.where(code.coding.exists(system='...' and code=%const)).first()
To correctly:
- Extract condition: code.coding.exists(system='...' and code=%const)
- Substitute constants: %const → actual value
- Apply .first(): converted to [0] array index
- Generate: OPENJSON with WHERE clause including [key] = '0'1 parent bc49d95 commit ccfc3bd
1 file changed
+38
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
60 | 92 | | |
61 | 93 | | |
62 | 94 | | |
63 | 95 | | |
64 | | - | |
| 96 | + | |
65 | 97 | | |
66 | 98 | | |
67 | 99 | | |
| |||
76 | 108 | | |
77 | 109 | | |
78 | 110 | | |
79 | | - | |
| 111 | + | |
80 | 112 | | |
81 | 113 | | |
82 | 114 | | |
| |||
0 commit comments