Skip to content

Commit

Permalink
Update iif function to 2 and 3 args
Browse files Browse the repository at this point in the history
  • Loading branch information
atuonufure committed Aug 3, 2023
1 parent 92daec5 commit f23bd6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fhirpathpy/engine/invocations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"skip": {"fn": filtering.skip_fn, "arity": {1: ["Integer"]}},
"intersect": {"fn": subsetting.intersect_fn, "arity": {1: ["AnyAtRoot"]}},
"combine": {"fn": combining.combine_fn, "arity": {1: ["AnyAtRoot"]}},
"iif": {"fn": misc.iif_macro, "arity": {3: ["Expr", "Expr", "Expr"]}},
"iif": {"fn": misc.iif_macro, "arity": {2: ["Expr", "Expr"], 3: ["Expr", "Expr", "Expr"]}},
"trace": {"fn": misc.trace_fn, "arity": {0: [], 1: ["String"]}},
"toInteger": {"fn": misc.to_integer},
"toDecimal": {"fn": misc.to_decimal},
Expand Down
8 changes: 5 additions & 3 deletions fhirpathpy/engine/invocations/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
numRegex = re.compile(r"^[+-]?\d+(\.\d+)?$")


def iif_macro(ctx, data, cond, ok, fail):
def iif_macro(ctx, data, cond, ok, fail=None):
if util.is_true(cond(data)):
return ok(data)

return fail(data)
elif fail:
return fail(data)
else:
return []


def trace_fn(ctx, x, label=""):
Expand Down

0 comments on commit f23bd6a

Please sign in to comment.