Module: FHIR::CommonElementDefinition

Included in:
R4::ElementDefinition, R4B::ElementDefinition, R5::ElementDefinition
Defined in:
lib/fhir_models/fhir_ext/common_element_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

children is used to hierarchically arrange elements so profile validation is easier to compute



5
6
7
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 5

def children
  @children
end

#local_nameObject

Returns the value of attribute local_name.



6
7
8
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 6

def local_name
  @local_name
end

#marked_for_keepingObject

Returns the value of attribute marked_for_keeping.



7
8
9
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 7

def marked_for_keeping
  @marked_for_keeping
end

Instance Method Details

#add_descendent(element) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 9

def add_descendent(element)
  @children = [] if @children.nil?
  element.local_name = element.path.gsub("#{path}.", '')
  if @children.last && element.path.start_with?(@children.last.path)
    if element.path == @children.last.path
      # slicing
      @children << element
    else
      @children.last.add_descendent(element)
    end
  else
    @children << element
  end
end

#keep_children(whitelist = []) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 24

def keep_children(whitelist = [])
  @marked_for_keeping = true if whitelist.include?(path)
  return unless @children

  @children.each do |child|
    child.keep_children(whitelist)
  end
end


41
42
43
44
45
46
47
48
49
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 41

def print_children(spaces = 0)
  puts "#{' ' * spaces}+#{local_name || path}"
  return nil unless @children

  @children.each do |child|
    child.print_children(spaces + 2)
  end
  nil
end

#sweep_childrenObject



33
34
35
36
37
38
39
# File 'lib/fhir_models/fhir_ext/common_element_definition.rb', line 33

def sweep_children
  return unless @children

  @children.each(&:sweep_children)
  @children.keep_if(&:marked_for_keeping)
  @marked_for_keeping = !@children.empty? || @marked_for_keeping
end