Class: AUCoreTestKit::Generator::ValueExactor

Inherits:
Object
  • Object
show all
Defined in:
lib/au_core_test_kit/generator/value_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ig_resources, resource, profile_elements) ⇒ ValueExactor

Returns a new instance of ValueExactor.



8
9
10
11
12
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 8

def initialize(ig_resources, resource, profile_elements)
  self.ig_resources = ig_resources
  self.resource = resource
  self.profile_elements = profile_elements
end

Instance Attribute Details

#ig_resourcesObject

Returns the value of attribute ig_resources.



6
7
8
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 6

def ig_resources
  @ig_resources
end

#profile_elementsObject

Returns the value of attribute profile_elements.



6
7
8
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 6

def profile_elements
  @profile_elements
end

#resourceObject

Returns the value of attribute resource.



6
7
8
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 6

def resource
  @resource
end

Instance Method Details

#bound_systems(the_element) ⇒ Object



63
64
65
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 63

def bound_systems(the_element)
  bound_systems_from_valueset(value_set(the_element))
end

#bound_systems_from_valueset(value_set) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 67

def bound_systems_from_valueset(value_set)
  value_set&.compose&.include&.map do |include|
    if include.concept.present?
      include
    elsif include.system.present? && include.filter&.empty? # Cannot process intensional value set with filters
      ig_resources.code_system_by_url(include.system)
    elsif include.valueSet.present?
      include.valueSet.map do |vs|
        a_value_set = ig_resources.value_set_by_url(vs)
        bound_systems_from_valueset(a_value_set)
      end
    end
  end&.flatten&.compact
end

#fhir_metadata(current_path) ⇒ Object



90
91
92
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 90

def (current_path)
  FHIR.const_get(resource)::METADATA[current_path]
end

#value_set(the_element) ⇒ Object



59
60
61
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 59

def value_set(the_element)
  ig_resources.value_set_by_url(value_set_binding(the_element)&.valueSet)
end

#value_set_binding(the_element) ⇒ Object



55
56
57
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 55

def value_set_binding(the_element)
  the_element&.binding
end

#values_from_fixed_codes(profile_element, type) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 25

def values_from_fixed_codes(profile_element, type)
  return [] unless type == 'CodeableConcept'

  profile_elements
    .select do |element|
      element.path == "#{profile_element.path}.coding.code" && element.fixedCode.present?
    end
    .map(&:fixedCode)
end

#values_from_pattern_codeable_concept(profile_element, type) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 45

def values_from_pattern_codeable_concept(profile_element, type)
  return [] unless type == 'CodeableConcept'

  profile_elements
    .select do |element|
      element.path == profile_element.path && element.patternCodeableConcept.present? && element.min.positive?
    end
    .map { |element| element.patternCodeableConcept.coding.first.code }
end

#values_from_pattern_coding(profile_element, type) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 35

def values_from_pattern_coding(profile_element, type)
  return [] unless type == 'CodeableConcept'

  profile_elements
    .select do |element|
      element.path == "#{profile_element.path}.coding" && element.patternCoding.present?
    end
    .map { |element| element.patternCoding.code }
end

#values_from_required_binding(profile_element) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 14

def values_from_required_binding(profile_element)
  return [] unless profile_element&.max == '*'

  profile_elements
    .select do |element|
      element.path == profile_element.path && element.binding&.strength == 'required'
    end
    .map { |element| values_from_value_set_binding(element) }
    .flatten.compact
end

#values_from_resource_metadata(paths) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 94

def (paths)
  values = []

  paths.each do |current_path|
     = (current_path)

    values += ['valid_codes'].values.flatten if &.dig('valid_codes').present?
  end

  values
end

#values_from_value_set_binding(the_element) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/au_core_test_kit/generator/value_extractor.rb', line 82

def values_from_value_set_binding(the_element)
  bound_systems = bound_systems(the_element)

  return [] if bound_systems.blank?

  bound_systems.flat_map { |system| system.concept.map(&:code) }.uniq
end