Class: USCoreTestKit::Generator::SearchDefinitionMetadataExtractor
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::SearchDefinitionMetadataExtractor
- Defined in:
- lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb
Instance Attribute Summary collapse
-
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
-
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
-
#name ⇒ Object
Returns the value of attribute name.
-
#profile_elements ⇒ Object
Returns the value of attribute profile_elements.
Instance Method Summary collapse
- #chain ⇒ Object
- #chain_expectations ⇒ Object
- #chain_extensions ⇒ Object
- #comparator_expectation(extension) ⇒ Object
- #comparator_expectation_extensions ⇒ Object
- #comparators ⇒ Object
- #contains_multiple? ⇒ Boolean
- #extension_definition ⇒ Object
- #extensions ⇒ Object
- #full_paths ⇒ Object
-
#initialize(name, ig_resources, profile_elements, group_metadata) ⇒ SearchDefinitionMetadataExtractor
constructor
A new instance of SearchDefinitionMetadataExtractor.
- #multiple_or_expectation ⇒ Object
- #param ⇒ Object
- #param_hash ⇒ Object
- #paths ⇒ Object
- #profile_element ⇒ Object
- #remove_additional_extension_from_asserted_date(full_paths) ⇒ Object
- #resource ⇒ Object
- #search_definition ⇒ Object
- #support_expectation(extension) ⇒ Object
- #type ⇒ Object
- #value_extractor ⇒ Object
- #values ⇒ Object
- #values_from_must_support_elements(short_path) ⇒ Object
- #values_from_must_support_slices(profile_element, short_path, mandatory_slice_only) ⇒ Object
- #values_from_must_supports(profile_element) ⇒ Object
- #values_from_resource_metadata(paths) ⇒ Object
Constructor Details
#initialize(name, ig_resources, profile_elements, group_metadata) ⇒ SearchDefinitionMetadataExtractor
Returns a new instance of SearchDefinitionMetadataExtractor.
8 9 10 11 12 13 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 8 def initialize(name, ig_resources, profile_elements, ) self.name = name self.ig_resources = ig_resources self.profile_elements = profile_elements self. = end |
Instance Attribute Details
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
6 7 8 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def @group_metadata end |
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
6 7 8 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def ig_resources @ig_resources end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def name @name end |
#profile_elements ⇒ Object
Returns the value of attribute profile_elements.
6 7 8 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def profile_elements @profile_elements end |
Instance Method Details
#chain ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 156 def chain return nil if param.chain.blank? param.chain .zip(chain_expectations) .map { |chain, expectation| { chain: chain, expectation: expectation } } end |
#chain_expectations ⇒ Object
152 153 154 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 152 def chain_expectations chain_extensions.map { |extension| support_expectation(extension) } end |
#chain_extensions ⇒ Object
148 149 150 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 148 def chain_extensions param_hash['_chain'] end |
#comparator_expectation(extension) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 106 def comparator_expectation(extension) if extension.nil? 'MAY' else support_expectation(extension) end end |
#comparator_expectation_extensions ⇒ Object
98 99 100 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 98 def comparator_expectation_extensions @comparator_expectation_extensions ||= param_hash['_comparator'] || [] end |
#comparators ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 114 def comparators {}.tap do |comparators| param.comparator&.each_with_index do |comparator, index| comparators[comparator.to_sym] = comparator_expectation(comparator_expectation_extensions[index]) end end end |
#contains_multiple? ⇒ Boolean
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 132 def contains_multiple? if profile_element.present? if profile_element.id.start_with?('Extension') && extension_definition.present? # Find the extension instance in a US Core profile target_element = profile_elements.find do |element| element.type.any? { |type| type.code == "Extension" && type.profile.include?(extension_definition.url) } end target_element&.max == '*' else profile_element.max == '*' end else false end end |
#extension_definition ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 86 def extension_definition @extension_definition ||= begin ext_definition = nil extensions&.each do || ext_definition = ig_resources.profile_by_url([:url]) break if ext_definition.present? end ext_definition end end |
#extensions ⇒ Object
72 73 74 75 76 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 72 def extensions @extensions ||= full_paths.select { |a_path| a_path.include?('extension.where') } .map { |a_path| { url: a_path[/(?<=extension.where\(url=').*(?='\))/] }} .presence end |
#full_paths ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 41 def full_paths @full_paths ||= begin path = param.expression.gsub(/.where\(resolve\((.*)/, '').gsub(/url = '/, 'url=\'') path = path[1..-2] if path.start_with?('(') && path.end_with?(')') path.scan(/[. ]as[( ]([^)]*)[)]?/).flatten.map do |as_type| path.gsub!(/[. ]as[( ](#{as_type}[^)]*)[)]?/, as_type.upcase_first) if as_type.present? end full_paths = path.split('|') # There is a bug in US Core 5 asserted-date search parameter. See FHIR-40573 if param.respond_to?(:version) && param.version == '5.0.1' && name == 'asserted-date' remove_additional_extension_from_asserted_date(full_paths) end full_paths end end |
#multiple_or_expectation ⇒ Object
164 165 166 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 164 def multiple_or_expectation param_hash['_multipleOr']['extension'].first['valueCode'] end |
#param ⇒ Object
33 34 35 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 33 def param @param ||= ig_resources.search_param_by_resource_and_name(resource, name) end |
#param_hash ⇒ Object
37 38 39 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 37 def param_hash param.source_hash end |
#paths ⇒ Object
68 69 70 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 68 def paths @paths ||= full_paths.map { |a_path| a_path.gsub("#{resource}.", '') } end |
#profile_element ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 78 def profile_element @profile_element ||= ( profile_elements.find { |element| full_paths.include?(element.id) } || extension_definition&.differential&.element&.find { |element| element.id == 'Extension.value[x]'} ) end |
#remove_additional_extension_from_asserted_date(full_paths) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 61 def remove_additional_extension_from_asserted_date(full_paths) full_paths.each do |full_path| next unless full_path.include?('http://hl7.org/fhir/StructureDefinition/condition-assertedDate') full_path.gsub!(/\).extension./, ').') end end |
#resource ⇒ Object
29 30 31 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 29 def resource [:resource] end |
#search_definition ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 15 def search_definition @search_definition ||= { paths: paths, full_paths: full_paths, comparators: comparators, values: values, type: type, contains_multiple: contains_multiple?, multiple_or: multiple_or_expectation, chain: chain }.compact end |
#support_expectation(extension) ⇒ Object
102 103 104 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 102 def support_expectation(extension) extension['extension'].first['valueCode'] end |
#type ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 122 def type if profile_element.present? profile_element.type.first.code else # search is a variable type, eg. Condition.onsetDateTime - element # in profile def is Condition.onset[x] param.type end end |
#value_extractor ⇒ Object
223 224 225 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 223 def value_extractor @value_extractor ||= ValueExactor.new(ig_resources, resource, profile_elements) end |
#values ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 168 def values values_from_must_supports(profile_element).presence || value_extractor.values_from_fixed_codes(profile_element, type).presence || #value_extractor.values_from_required_binding(profile_element).presence || value_extractor.values_from_value_set_binding(profile_element).presence || (paths).presence || [] end |
#values_from_must_support_elements(short_path) ⇒ Object
209 210 211 212 213 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 209 def values_from_must_support_elements(short_path) [:must_supports][:elements] .select { |element| element[:path] == "#{short_path}.coding.code" } .map { |element| element[:fixed_value] } end |
#values_from_must_support_slices(profile_element, short_path, mandatory_slice_only) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 188 def values_from_must_support_slices(profile_element, short_path, mandatory_slice_only) [:must_supports][:slices] .select { |slice| [short_path, "#{short_path}.coding"].include?(slice[:path]) } .map do |slice| slice_element = profile_elements.find { |element| slice[:slice_id] == element.id } next if (profile_element.min > 0 && slice_element.min == 0 && mandatory_slice_only) case slice[:discriminator][:type] when 'patternCoding', 'patternCodeableConcept' slice[:discriminator][:code] when 'requiredBinding' slice[:discriminator][:values] when 'value' slice[:discriminator][:values] .select { |value| value[:path] == 'coding.code' } .map { |value| value[:value] } end end .compact.flatten end |
#values_from_must_supports(profile_element) ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 177 def values_from_must_supports(profile_element) return if profile_element.nil? short_path = profile_element.path.split('.', 2)[1] values_from_must_support_slices(profile_element, short_path, true).presence || values_from_must_support_slices(profile_element, short_path, false).presence || values_from_must_support_elements(short_path).presence || [] end |
#values_from_resource_metadata(paths) ⇒ Object
215 216 217 218 219 220 221 |
# File 'lib/us_core_test_kit/generator/search_definition_metadata_extractor.rb', line 215 def (paths) if multiple_or_expectation == 'SHALL' || paths.any? { |path| path.downcase.include?('status') } value_extractor.(paths) else [] end end |