diff --git a/fhirpathpy/__init__.py b/fhirpathpy/__init__.py index 3e33842..1635627 100644 --- a/fhirpathpy/__init__.py +++ b/fhirpathpy/__init__.py @@ -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) diff --git a/tests/test_evaluators.py b/tests/test_evaluators.py index 67bc93b..5ded737 100644 --- a/tests/test_evaluators.py +++ b/tests/test_evaluators.py @@ -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"), @@ -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 @@ -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