Skip to content

Commit

Permalink
Fix existence and filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Dec 20, 2023
1 parent bd46761 commit 05e7bd3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion fhirpathpy/engine/invocations/existence.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def exists_macro(ctx, coll, expr=None):


def all_macro(ctx, colls, expr):
for coll in colls:
for i, coll in enumerate(colls):
ctx["$index"] = i
if not util.is_true(expr(coll)):
return [False]

Expand Down
17 changes: 15 additions & 2 deletions fhirpathpy/engine/invocations/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ def where_macro(ctx, data, expr):
if not isinstance(data, list):
return []

return util.flatten([x for x in data if check_macro_expr(expr, x)])
result = []

for i, x in enumerate(data):
ctx["$index"] = i
if check_macro_expr(expr, x):
result.append(x)

return util.flatten(result)


def select_macro(ctx, data, expr):
if not isinstance(data, list):
return []

return util.flatten([expr(x) for x in data])
result = []

for i, x in enumerate(data):
ctx["$index"] = i
result.append(expr(x))

return util.flatten(result)


def repeat_macro(ctx, data, expr):
Expand Down

0 comments on commit 05e7bd3

Please sign in to comment.