Skip to content

Commit

Permalink
Types (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
atuonufure committed Dec 12, 2023
1 parent 3d7b463 commit ba71798
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions fhirpathpy/engine/evaluators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def polarity_expression(ctx, parentData, node):
"InequalityExpression": op_expression,
"AdditiveExpression": op_expression,
"MultiplicativeExpression": op_expression,
"TypeExpression": alias_op_expression({"is": "isOp", "as": "asOp"}),
"EqualityExpression": op_expression,
"OrExpression": op_expression,
"ImpliesExpression": op_expression,
Expand Down
2 changes: 2 additions & 0 deletions fhirpathpy/engine/invocations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"last": {"fn": filtering.last_fn},
"ofType": {"fn": filtering.of_type_fn, "arity": {1: ["Identifier"]}},
"is": {"fn": types.is_fn, "arity": {1: ["TypeSpecifier"]}},
"as": {"fn": types.as_fn, "arity": {1: ["TypeSpecifier"]}},
"tail": {"fn": filtering.tail_fn},
"take": {"fn": filtering.take_fn, "arity": {1: ["Integer"]}},
"skip": {"fn": filtering.skip_fn, "arity": {1: ["Integer"]}},
Expand Down Expand Up @@ -100,6 +101,7 @@
">=": {"fn": equality.gte, "arity": {2: ["Any", "Any"]}, "nullable": True},
"containsOp": {"fn": collections.contains, "arity": {2: ["Any", "Any"]}},
"inOp": {"fn": collections.inn, "arity": {2: ["Any", "Any"]}},
"isOp": {"fn": types.is_fn, "arity": {2: ["Any", "TypeSpecifier"]}},
"&": {"fn": math.amp, "arity": {2: ["String", "String"]}},
"+": {"fn": math.plus, "arity": {2: ["Any", "Any"]}, "nullable": True},
"-": {"fn": math.minus, "arity": {2: ["Any", "Any"]}, "nullable": True},
Expand Down
19 changes: 18 additions & 1 deletion fhirpathpy/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,20 @@ def __hash__(self):
path_hash = hash(self.path)
return hash((data_hash, path_hash))

def get_type_info(self):
namespace = TypeInfo.FHIR

match = re.match(r"^System\.(.*)$", self.path)
if match:
return TypeInfo(namespace=TypeInfo.System, name=match.group(1))
elif "." not in self.path:
return TypeInfo(namespace=namespace, name=self.path)

if not TypeInfo.model:
return TypeInfo.create_by_value_in_namespace(namespace=namespace, value=self.data)

return TypeInfo(namespace=namespace, name="BackboneElement")

def toJSON(self):
return json.dumps(self.data)

Expand Down Expand Up @@ -620,7 +634,7 @@ def is_(self, other):
def create_by_value_in_namespace(namespace, value):
name = type(value).__name__

if isinstance(value, int):
if isinstance(value, int) and not isinstance(value, bool):
name = "integer"
elif isinstance(value, float) or isinstance(value, Decimal):
name = "decimal"
Expand All @@ -631,6 +645,9 @@ def create_by_value_in_namespace(namespace, value):
elif isinstance(value, FP_Quantity):
name = "Quantity"

if name == "bool":
name = "Boolean"

if namespace == TypeInfo.System:
name = name.capitalize()

Expand Down

0 comments on commit ba71798

Please sign in to comment.