Class: IpaTestKit::Generator::SearchDefinitionMetadataExtractor
- Inherits:
-
Object
- Object
- IpaTestKit::Generator::SearchDefinitionMetadataExtractor
- Defined in:
- lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb
Instance Attribute Summary collapse
-
#base_search_params ⇒ Object
Returns the value of attribute base_search_params.
-
#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.
-
#resource ⇒ Object
Returns the value of attribute resource.
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
- #full_paths ⇒ Object
-
#initialize(name, ig_resources, resource, profile_elements, base_search_params) ⇒ SearchDefinitionMetadataExtractor
constructor
A new instance of SearchDefinitionMetadataExtractor.
- #multiple_or_expectation ⇒ Object
- #param ⇒ Object
- #param_hash ⇒ Object
- #paths ⇒ Object
- #profile_element ⇒ Object
- #search_base_param_by_resource_and_name(resource, name) ⇒ Object
- #search_definition ⇒ Object
- #support_expectation(extension) ⇒ Object
- #type ⇒ Object
- #value_extractor ⇒ Object
- #values ⇒ Object
- #values_from_resource_metadata(paths) ⇒ Object
Constructor Details
#initialize(name, ig_resources, resource, profile_elements, base_search_params) ⇒ SearchDefinitionMetadataExtractor
Returns a new instance of SearchDefinitionMetadataExtractor.
8 9 10 11 12 13 14 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 8 def initialize(name, ig_resources, resource, profile_elements, base_search_params) self.name = name self.ig_resources = ig_resources self.resource = resource self.profile_elements = profile_elements self.base_search_params = base_search_params end |
Instance Attribute Details
#base_search_params ⇒ Object
Returns the value of attribute base_search_params.
6 7 8 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def base_search_params @base_search_params end |
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
6 7 8 |
# File 'lib/ipa_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/ipa_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/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def profile_elements @profile_elements end |
#resource ⇒ Object
Returns the value of attribute resource.
6 7 8 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 6 def resource @resource end |
Instance Method Details
#chain ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 112 def chain return nil if param.chain.blank? param.chain .zip(chain_expectations) .map { |chain, expectation| { chain: chain, expectation: expectation } } end |
#chain_expectations ⇒ Object
108 109 110 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 108 def chain_expectations chain_extensions.map { |extension| support_expectation(extension) } end |
#chain_extensions ⇒ Object
104 105 106 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 104 def chain_extensions param_hash['_chain'] end |
#comparator_expectation(extension) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 74 def comparator_expectation(extension) if extension.nil? 'MAY' else support_expectation(extension) end end |
#comparator_expectation_extensions ⇒ Object
66 67 68 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 66 def comparator_expectation_extensions @comparator_expectation_extensions ||= param_hash['_comparator'] || [] end |
#comparators ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 82 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
100 101 102 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 100 def contains_multiple? profile_element&.max == '*' end |
#full_paths ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 43 def full_paths @full_paths ||= begin path = param.expression.gsub(/\.where\(resolve\(\)[^\)]*\)/, '') path = path.gsub(/.where\((.*)/, '') 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 path.gsub!("Resource.", "#{resource}.") path.split('|').map(&:strip) end end |
#multiple_or_expectation ⇒ Object
120 121 122 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 120 def multiple_or_expectation param_hash['_multipleOr']&.[]('extension')&.first&.[]('valueCode') end |
#param ⇒ Object
30 31 32 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 30 def param @param ||= ig_resources.search_param_by_resource_and_name(resource, name) || search_base_param_by_resource_and_name(resource, name) end |
#param_hash ⇒ Object
39 40 41 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 39 def param_hash param.source_hash end |
#paths ⇒ Object
57 58 59 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 57 def paths @paths ||= full_paths.map { |a_path| a_path.gsub("#{resource}.", '')} end |
#profile_element ⇒ Object
61 62 63 64 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 61 def profile_element @profile_element ||= profile_elements.find { |element| full_paths.include?(element.id) } end |
#search_base_param_by_resource_and_name(resource, name) ⇒ Object
34 35 36 37 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 34 def search_base_param_by_resource_and_name(resource, name) search_param = base_search_params['entry'].find{|entry| entry['resource']['code'] == name && (entry['resource']['base'].include?(resource) || entry['resource']['base'].include?('Resource'))} FHIR::SearchParameter.new(search_param['resource']) end |
#search_definition ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 16 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
70 71 72 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 70 def support_expectation(extension) extension['extension'].first['valueCode'] end |
#type ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 90 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
138 139 140 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 138 def value_extractor @value_extractor ||= ValueExactor.new(ig_resources, resource, profile_elements) end |
#values ⇒ Object
124 125 126 127 128 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 124 def values value_extractor.values_from_slicing(profile_element, type).presence || value_extractor.values_from_value_set_binding(profile_element).presence || (paths).presence || [] end |
#values_from_resource_metadata(paths) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/ipa_test_kit/generator/search_definition_metadata_extractor.rb', line 130 def (paths) if multiple_or_expectation == 'SHALL' || paths.any? { |path| path.downcase.include?('status') } value_extractor.(paths) else [] end end |