Skip to content

Commit

Permalink
Update toDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Dec 13, 2023
1 parent 572a0c9 commit 309052f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion fhirpathpy/engine/invocations/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')},
}
10 changes: 5 additions & 5 deletions fhirpathpy/engine/invocations/misc.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 309052f

Please sign in to comment.