Class: IpaTestKit::Generator::ValueExactor

Inherits:
Object
  • Object
show all
Defined in:
lib/ipa_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.



6
7
8
9
10
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 6

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.



4
5
6
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 4

def ig_resources
  @ig_resources
end

#profile_elementsObject

Returns the value of attribute profile_elements.



4
5
6
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 4

def profile_elements
  @profile_elements
end

#resourceObject

Returns the value of attribute resource.



4
5
6
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 4

def resource
  @resource
end

Instance Method Details

#bound_systems(the_element) ⇒ Object



70
71
72
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 70

def bound_systems(the_element)
  value_set(the_element)&.compose&.include&.reject { |code| code.concept.nil? }
end

#fhir_metadata(current_path) ⇒ Object



82
83
84
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 82

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

#value_set(the_element) ⇒ Object



66
67
68
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 66

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

#value_set_binding(the_element) ⇒ Object



62
63
64
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 62

def value_set_binding(the_element)
  the_element&.binding
end

#values_from_fixed_codes(profile_element, type) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 32

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 { |element| element.fixedCode }
end

#values_from_pattern_codeable_concept(profile_element, type) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 52

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 > 0
    end
    .map { |element| element.patternCodeableConcept.coding.first.code }
end

#values_from_pattern_coding(profile_element, type) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 42

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



21
22
23
24
25
26
27
28
29
30
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 21

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



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 86

def (paths)
  values = []

  paths.each do |current_path|
     = (current_path)

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

  values
end

#values_from_slicing(profile_element, type) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 12

def values_from_slicing(profile_element, type)
  (
    values_from_required_binding(profile_element) +
    values_from_fixed_codes(profile_element, type) +
    values_from_pattern_coding(profile_element, type) +
    values_from_pattern_codeable_concept(profile_element, type)
  ).uniq
end

#values_from_value_set_binding(the_element) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/ipa_test_kit/generator/value_extractor.rb', line 74

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| code.code } }.uniq
end