Skip to content

Commit

Permalink
Merge pull request #26 from zakharych/convert-path-value
Browse files Browse the repository at this point in the history
Convert path to str if DSL type
  • Loading branch information
ir4y committed Aug 18, 2023
2 parents b8f5e32 + 3674154 commit 1086a9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fhirpathpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def evaluate(resource, path, context={}, model=None):
int: Description of return value
"""
if isinstance(path, DSL):
path = str(path)
node = parse(path)
return apply_parsed_path(resource, node, context, model)

Expand Down
15 changes: 14 additions & 1 deletion tests/test_evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from fhirpathpy import evaluate
from fhirpathpy.engine.invocations.constants import constants

from fhirpathpy import dsl


@pytest.mark.parametrize(
("resource", "path", "expected"),
Expand Down Expand Up @@ -212,7 +214,7 @@ def now_function_test():
old_now_value = evaluate({}, 'now()')
frozen_datetime.tick(1.0)
new_now_value = evaluate({}, 'now()')

assert old_now_value != new_now_value


Expand Down Expand Up @@ -246,3 +248,14 @@ def combining_functions_test(resource, path, expected):
)
def path_functions_test(resource, path, expected):
assert evaluate(resource, path) == expected


@pytest.mark.parametrize(
("resource", "path", "expected"),
[
({"a": "lorem ipsum"}, "a.contains('sum')", [True]),
({"a": "lorem ipsum"}, dsl.a.contains('sum'), [True]),
],
)
def convert_dsl_path_test(resource, path, expected):
assert evaluate(resource, path) == expected

0 comments on commit 1086a9a

Please sign in to comment.