From 3e5fbde3c28042894be6c33c6a4c1980422959ce Mon Sep 17 00:00:00 2001 From: atuonufure Date: Fri, 12 Jan 2024 03:57:50 +0100 Subject: [PATCH] Update ofType --- fhirpathpy/engine/invocations/__init__.py | 2 +- fhirpathpy/engine/invocations/filtering.py | 2 +- fhirpathpy/engine/nodes.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fhirpathpy/engine/invocations/__init__.py b/fhirpathpy/engine/invocations/__init__.py index 7d75b95..97cf326 100644 --- a/fhirpathpy/engine/invocations/__init__.py +++ b/fhirpathpy/engine/invocations/__init__.py @@ -39,7 +39,7 @@ "single": {"fn": filtering.single_fn}, "first": {"fn": filtering.first_fn}, "last": {"fn": filtering.last_fn}, - "ofType": {"fn": filtering.of_type_fn, "arity": {1: ["Identifier"]}}, + "ofType": {"fn": filtering.of_type_fn, "arity": {1: ["TypeSpecifier"]}}, "type": {"fn": types.type_fn, "arity": {0: []}}, "is": {"fn": types.is_fn, "arity": {1: ["TypeSpecifier"]}}, "as": {"fn": types.as_fn, "arity": {1: ["TypeSpecifier"]}}, diff --git a/fhirpathpy/engine/invocations/filtering.py b/fhirpathpy/engine/invocations/filtering.py index 19fb3f7..995fca3 100644 --- a/fhirpathpy/engine/invocations/filtering.py +++ b/fhirpathpy/engine/invocations/filtering.py @@ -133,7 +133,7 @@ def check_fhir_type(ctx, x, tp): def of_type_fn(ctx, coll, tp): - return list(filter(lambda x: check_fhir_type(ctx, util.get_data(x), tp), coll)) + return [value for value in coll if nodes.TypeInfo.from_value(value).is_(tp)] def extension(ctx, data, url): diff --git a/fhirpathpy/engine/nodes.py b/fhirpathpy/engine/nodes.py index 93d9360..126879f 100644 --- a/fhirpathpy/engine/nodes.py +++ b/fhirpathpy/engine/nodes.py @@ -887,6 +887,10 @@ def create_by_value_in_namespace(namespace, value): name = "time" elif isinstance(value, FP_Quantity): name = "Quantity" + elif isinstance(value, str): + name = "string" + elif isinstance(value, dict): + name = "object" if name == "bool": name = "boolean"