Class: Inferno::DSL::ValueExtractor
- Inherits:
-
Object
- Object
- Inferno::DSL::ValueExtractor
- Defined in:
- lib/inferno/dsl/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
- #bound_systems_from_valueset_include_element(include_element) ⇒ 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_include(include_element) ⇒ Object
A whole code system include becomes a system-only value.
- #codings_from_value_set_binding(the_element) ⇒ Object
- #fhir_metadata(current_path) ⇒ Object
-
#initialize(ig_resources, resource, profile_elements) ⇒ ValueExtractor
constructor
A new instance of ValueExtractor.
- #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
-
#whole_code_system(include_element) ⇒ Object
An include of a whole code system lists no codes.
- #whole_code_system_include?(include_element) ⇒ Boolean
Constructor Details
#initialize(ig_resources, resource, profile_elements) ⇒ ValueExtractor
Returns a new instance of ValueExtractor.
6 7 8 9 10 |
# File 'lib/inferno/dsl/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/inferno/dsl/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/inferno/dsl/value_extractor.rb', line 4 def profile_elements @profile_elements end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/inferno/dsl/value_extractor.rb', line 4 def resource @resource end |
Instance Method Details
#bound_systems(the_element) ⇒ Object
50 51 52 |
# File 'lib/inferno/dsl/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 |
# File 'lib/inferno/dsl/value_extractor.rb', line 54 def bound_systems_from_valueset(value_set) value_set&.compose&.include&.map do |include_element| bound_systems_from_valueset_include_element(include_element) end&.flatten&.compact end |
#bound_systems_from_valueset_include_element(include_element) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/inferno/dsl/value_extractor.rb', line 60 def bound_systems_from_valueset_include_element(include_element) if include_element.concept.present? include_element elsif whole_code_system_include?(include_element) whole_code_system(include_element) 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 |
#codes_from_system_code_pair(codings) ⇒ Object
89 90 91 |
# File 'lib/inferno/dsl/value_extractor.rb', line 89 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
85 86 87 |
# File 'lib/inferno/dsl/value_extractor.rb', line 85 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/inferno/dsl/value_extractor.rb', line 107 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 codings_from_include(bound_system) when FHIR::CodeSystem bound_system.concept.map { |concept| { system: bound_system.url, code: concept.code } } else [] end end.uniq end |
#codings_from_include(include_element) ⇒ Object
A whole code system include becomes a system-only value
123 124 125 126 127 |
# File 'lib/inferno/dsl/value_extractor.rb', line 123 def codings_from_include(include_element) return [{ system: include_element.system }] if include_element.concept.blank? include_element.concept.map { |concept| { system: include_element.system, code: concept.code } } end |
#codings_from_value_set_binding(the_element) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/inferno/dsl/value_extractor.rb', line 93 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
133 134 135 |
# File 'lib/inferno/dsl/value_extractor.rb', line 133 def (current_path) FHIR.const_get(resource)::METADATA[current_path] end |
#value_set(the_element) ⇒ Object
46 47 48 |
# File 'lib/inferno/dsl/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/inferno/dsl/value_extractor.rb', line 42 def value_set_binding(the_element) the_element&.binding end |
#value_set_expansion_contains(element) ⇒ Object
129 130 131 |
# File 'lib/inferno/dsl/value_extractor.rb', line 129 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/inferno/dsl/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/inferno/dsl/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/inferno/dsl/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
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/inferno/dsl/value_extractor.rb', line 137 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 |
#whole_code_system(include_element) ⇒ Object
An include of a whole code system lists no codes. Use the code system's concepts when the IG has them, otherwise keep the include so that any code from its system is accepted.
80 81 82 83 |
# File 'lib/inferno/dsl/value_extractor.rb', line 80 def whole_code_system(include_element) code_system = ig_resources.code_system_by_url(include_element.system) code_system&.concept.present? ? code_system : include_element end |
#whole_code_system_include?(include_element) ⇒ Boolean
73 74 75 76 |
# File 'lib/inferno/dsl/value_extractor.rb', line 73 def whole_code_system_include?(include_element) include_element.system.present? && include_element.concept.blank? && include_element.filter&.empty? && include_element.valueSet.blank? end |