Class: USCoreTestKit::Generator::ValueExactor
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::ValueExactor
- Defined in:
- lib/us_core_test_kit/generator/value_extractor.rb
Instance Attribute Summary collapse
-
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
-
#profile_elements ⇒ Object
Returns the value of attribute profile_elements.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #bound_systems(the_element) ⇒ Object
- #bound_systems_from_valueset(value_set) ⇒ Object
- #codes_from_system_code_pair(codings) ⇒ Object
- #codes_from_value_set_binding(the_element) ⇒ Object
- #codings_from_bound_systems(bound_systems) ⇒ Object
- #codings_from_value_set_binding(the_element) ⇒ Object
- #fhir_metadata(current_path) ⇒ Object
-
#initialize(ig_resources, resource, profile_elements) ⇒ ValueExactor
constructor
A new instance of ValueExactor.
- #value_set(the_element) ⇒ Object
- #value_set_binding(the_element) ⇒ Object
- #value_set_expansion_contains(element) ⇒ Object
- #values_from_fixed_codes(profile_element, type) ⇒ Object
- #values_from_pattern_codeable_concept(profile_element, type) ⇒ Object
- #values_from_pattern_coding(profile_element, type) ⇒ Object
- #values_from_resource_metadata(paths) ⇒ Object
Constructor Details
#initialize(ig_resources, resource, profile_elements) ⇒ ValueExactor
Returns a new instance of ValueExactor.
6 7 8 9 10 |
# File 'lib/us_core_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_resources ⇒ Object
Returns the value of attribute ig_resources.
4 5 6 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 4 def ig_resources @ig_resources end |
#profile_elements ⇒ Object
Returns the value of attribute profile_elements.
4 5 6 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 4 def profile_elements @profile_elements end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 4 def resource @resource end |
Instance Method Details
#bound_systems(the_element) ⇒ Object
50 51 52 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 50 def bound_systems(the_element) bound_systems_from_valueset(value_set(the_element)) end |
#bound_systems_from_valueset(value_set) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 54 def bound_systems_from_valueset(value_set) value_set&.compose&.include&.map do |include_element| if include_element.concept.present? include_element elsif include_element.system.present? && include_element.filter&.empty? # Cannot process intensional value set with filters ig_resources.code_system_by_url(include_element.system) elsif include_element.valueSet.present? include_element.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 |
#codes_from_system_code_pair(codings) ⇒ Object
74 75 76 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 74 def codes_from_system_code_pair(codings) codings.present? ? codings.map { |coding| coding[:code] }.compact.uniq : [] end |
#codes_from_value_set_binding(the_element) ⇒ Object
70 71 72 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 70 def codes_from_value_set_binding(the_element) codes_from_system_code_pair(codings_from_value_set_binding(the_element)) end |
#codings_from_bound_systems(bound_systems) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 92 def codings_from_bound_systems(bound_systems) return [] unless bound_systems.present? bound_systems.flat_map do |bound_system| case bound_system when FHIR::ValueSet::Compose::Include bound_system.concept.map { |concept| { system: bound_system.system, code: concept.code } } when FHIR::CodeSystem bound_system.concept.map { |concept| { system: bound_system.url, code: concept.code } } else [] end end.uniq end |
#codings_from_value_set_binding(the_element) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 78 def codings_from_value_set_binding(the_element) return [] if the_element.nil? bound_systems = bound_systems(the_element) return codings_from_bound_systems(bound_systems) if bound_systems.present? expansion_contains = value_set_expansion_contains(the_element) return [] if expansion_contains.blank? expansion_contains.map { |contains| { system: contains.system, code: contains.code } }.compact.uniq end |
#fhir_metadata(current_path) ⇒ Object
111 112 113 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 111 def (current_path) FHIR.const_get(resource)::METADATA[current_path] end |
#value_set(the_element) ⇒ Object
46 47 48 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 46 def value_set(the_element) ig_resources.value_set_by_url(value_set_binding(the_element)&.valueSet) end |
#value_set_binding(the_element) ⇒ Object
42 43 44 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 42 def value_set_binding(the_element) the_element&.binding end |
#value_set_expansion_contains(element) ⇒ Object
107 108 109 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 107 def value_set_expansion_contains(element) value_set(element)&.expansion&.contains end |
#values_from_fixed_codes(profile_element, type) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 12 def values_from_fixed_codes(profile_element, type) return [] unless type == 'CodeableConcept' elements = profile_elements.select do |element| element.path == "#{profile_element.path}.coding.code" && element.fixedCode.present? end elements.map(&:fixedCode) end |
#values_from_pattern_codeable_concept(profile_element, type) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 32 def values_from_pattern_codeable_concept(profile_element, type) return [] unless type == 'CodeableConcept' elements = profile_elements.select do |element| element.path == profile_element.path && element.patternCodeableConcept.present? && element.min.positive? end elements.map { |element| element.patternCodeableConcept.coding.first.code } end |
#values_from_pattern_coding(profile_element, type) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 22 def values_from_pattern_coding(profile_element, type) return [] unless type == 'CodeableConcept' elements = profile_elements.select do |element| element.path == "#{profile_element.path}.coding" && element.patternCoding.present? end elements.map { |element| element.patternCoding.code } end |
#values_from_resource_metadata(paths) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/us_core_test_kit/generator/value_extractor.rb', line 115 def (paths) values = [] paths.each do |current_path| = (current_path) next unless &.dig('valid_codes').present? values += ['valid_codes'].flat_map do |system, codes| codes.map { |code| { system:, code: } } end end values end |