From 309052f21d5559ed79e0302a73f95de340cb659d Mon Sep 17 00:00:00 2001 From: Pavel R Date: Wed, 13 Dec 2023 16:39:02 +0100 Subject: [PATCH] Update toDecimal --- fhirpathpy/engine/invocations/__init__.py | 4 +++- fhirpathpy/engine/invocations/misc.py | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fhirpathpy/engine/invocations/__init__.py b/fhirpathpy/engine/invocations/__init__.py index c1505c4..c4b2189 100644 --- a/fhirpathpy/engine/invocations/__init__.py +++ b/fhirpathpy/engine/invocations/__init__.py @@ -1,3 +1,5 @@ +from decimal import Decimal + import fhirpathpy.engine.invocations.collections as collections import fhirpathpy.engine.invocations.existence as existence import fhirpathpy.engine.invocations.filtering as filtering @@ -121,6 +123,6 @@ "max": {"fn": aggregate.max_fn}, "convertsToBoolean": {"fn": misc.create_converts_to_fn(misc.to_boolean, 'bool')}, "convertsToInteger": {"fn": misc.create_converts_to_fn(misc.to_integer, 'int')}, - "convertsToDecimal": {"fn": misc.create_converts_to_fn(misc.to_decimal, 'float')}, + "convertsToDecimal": {"fn": misc.create_converts_to_fn(misc.to_decimal, Decimal)}, "convertsToString": {"fn": misc.create_converts_to_fn(misc.to_string, 'str')}, } diff --git a/fhirpathpy/engine/invocations/misc.py b/fhirpathpy/engine/invocations/misc.py index 6f33fdb..dccb200 100644 --- a/fhirpathpy/engine/invocations/misc.py +++ b/fhirpathpy/engine/invocations/misc.py @@ -1,6 +1,6 @@ -import logging -from decimal import Decimal import re +from decimal import Decimal + import fhirpathpy.engine.util as util import fhirpathpy.engine.nodes as nodes @@ -103,13 +103,13 @@ def to_decimal(ctx, coll): value = util.get_data(coll[0]) if value is False: - return 0 + return Decimal(0) if value is True: - return 1.0 + return Decimal(1.0) if util.is_number(value): - return value + return Decimal(value) if isinstance(value, str): if re.match(numRegex, value) is not None: