lib/fhir_models/fluentpath/evaluate.rb in fhir_models-1.8.2 vs lib/fhir_models/fluentpath/evaluate.rb in fhir_models-1.8.3
- old
+ new
@@ -246,11 +246,11 @@
tree[index] = node[1..-2] if node.is_a?(String) && node.start_with?("'") && node.end_with?("'")
end
FHIR.logger.debug "DATA: #{tree}"
# evaluate all the functions at this level
- functions = [:all, :not, :empty, :exists, :startsWith, :substring, :contains, :in, :distinct, :toInteger, :count]
+ functions = [:all, :not, :empty, :exists, :startsWith, :substring, :contains, :in, :distinct, :toInteger, :count, :length]
size = -1
while tree.length != size
FHIR.logger.debug "FUNC: #{tree}"
previous_node = data
previous_index = nil
@@ -271,11 +271,18 @@
when :not
tree[index] = !convert_to_boolean(previous_node)
clean_index(tree, previous_index)
when :count
tree[index] = 0
- tree[index] = 1 unless previous_node.nil?
+ tree[index] = 1 unless previous_node == :null || previous_node.nil?
tree[index] = previous_node.length if previous_node.is_a?(Array)
+ clean_index(tree, previous_index)
+ when :length
+ if previous_node == :null || previous_node.nil?
+ tree[index] = 0
+ else
+ tree[index] = previous_node.to_s.length
+ end
clean_index(tree, previous_index)
when :empty
tree[index] = (previous_node == :null || previous_node.empty? rescue previous_node.nil?)
clean_index(tree, previous_index)
when :exists