Class: DaVinciPlanNetTestKit::Generator::SearchTestGenerator
- Inherits:
-
Object
- Object
- DaVinciPlanNetTestKit::Generator::SearchTestGenerator
- Defined in:
- lib/davinci_plan_net_test_kit/generator/search_test_generator.rb
Instance Attribute Summary collapse
-
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
-
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
-
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #array_of_strings(array) ⇒ Object
- #base_output_file_name ⇒ Object
- #class_name ⇒ Object
- #conformance_expectation ⇒ Object
- #description ⇒ Object
- #first_search? ⇒ Boolean
- #first_search_description ⇒ Object
- #fixed_value_search? ⇒ Boolean
- #fixed_value_search_param_name ⇒ Object
- #generate ⇒ Object
-
#initialize(group_metadata, search_metadata, base_output_dir) ⇒ SearchTestGenerator
constructor
A new instance of SearchTestGenerator.
- #module_name ⇒ Object
- #needs_resource_id? ⇒ Boolean
- #optional? ⇒ Boolean
- #output ⇒ Object
- #output_file_directory ⇒ Object
- #output_file_name ⇒ Object
- #path_for_value(path) ⇒ Object
- #possible_status_search? ⇒ Boolean
- #post_search_description ⇒ Object
- #profile_identifier ⇒ Object
- #reference_search_description ⇒ Object
- #required_comparators ⇒ Object
- #required_comparators_for_param(name) ⇒ Object
- #required_comparators_string ⇒ Object
- #required_multiple_or_search_params ⇒ Object
- #required_multiple_or_search_params_string ⇒ Object
- #resource_type ⇒ Object
- #saves_delayed_references? ⇒ Boolean
- #search_definition(name) ⇒ Object
- #search_identifier ⇒ Object
- #search_param_name_string ⇒ Object
- #search_param_names ⇒ Object
- #search_param_names_array ⇒ Object
- #search_params ⇒ Object
- #search_properties ⇒ Object
- #search_test_properties_string ⇒ Object
- #search_title ⇒ Object
- #template ⇒ Object
- #test_id ⇒ Object
- #test_post_search? ⇒ Boolean
- #test_reference_variants? ⇒ Boolean
- #token_search_params ⇒ Object
- #token_search_params_string ⇒ Object
- #url_version ⇒ Object
Constructor Details
#initialize(group_metadata, search_metadata, base_output_dir) ⇒ SearchTestGenerator
Returns a new instance of SearchTestGenerator.
20 21 22 23 24 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 20 def initialize(, , base_output_dir) self. = self. = self.base_output_dir = base_output_dir end |
Instance Attribute Details
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
18 19 20 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 18 def base_output_dir @base_output_dir end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
18 19 20 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 18 def @group_metadata end |
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
18 19 20 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 18 def @search_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 8 def generate(, base_output_dir) .groups .reject { |group| SpecialCases.exclude_group? group } .select { |group| group.searches.present? } .each do |group| group.searches.each { |search| new(group, search, base_output_dir).generate } end end |
Instance Method Details
#array_of_strings(array) ⇒ Object
176 177 178 179 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 176 def array_of_strings(array) quoted_strings = array.map { |element| "'#{element}'" } "[#{quoted_strings.join(', ')}]" end |
#base_output_file_name ⇒ Object
34 35 36 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 34 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
62 63 64 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 62 def class_name "#{Naming.upper_camel_case_for_profile()}#{search_title}SearchTest" end |
#conformance_expectation ⇒ Object
74 75 76 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 74 def conformance_expectation [:expectation] end |
#description ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 260 def description <<~DESCRIPTION.gsub(/\n{3,}/, "\n\n") A server #{conformance_expectation} support searching by #{search_param_name_string} on the #{resource_type} resource. This test will pass if resources are returned and match the search criteria. If none are returned, the test is skipped. #{reference_search_description} #{first_search_description} #{post_search_description} [Plan Net Server CapabilityStatement](http://hl7.org/fhir/us/davinci-pdex-plan-net/STU1.1/CapabilityStatement/plan-net) DESCRIPTION end |
#first_search? ⇒ Boolean
88 89 90 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 88 def first_search? false end |
#first_search_description ⇒ Object
240 241 242 243 244 245 246 247 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 240 def first_search_description return '' unless first_search? <<~FIRST_SEARCH_DESCRIPTION Because this is the first search of the sequence, resources in the response will be used for subsequent tests. FIRST_SEARCH_DESCRIPTION end |
#fixed_value_search? ⇒ Boolean
92 93 94 95 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 92 def fixed_value_search? #TODO false end |
#fixed_value_search_param_name ⇒ Object
97 98 99 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 97 def fixed_value_search_param_name #TODO end |
#generate ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 219 def generate FileUtils.mkdir_p(output_file_directory) File.open(output_file_name, 'w') { |f| f.write(output) } .add_test( id: test_id, file_name: base_output_file_name ) end |
#module_name ⇒ Object
66 67 68 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 66 def module_name "DaVinciPlanNet#{.reformatted_version.upcase}" end |
#needs_resource_id? ⇒ Boolean
105 106 107 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 105 def needs_resource_id? [:names].include?(resource_type) end |
#optional? ⇒ Boolean
133 134 135 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 133 def optional? conformance_expectation != 'SHALL' || ![:must_support_or_mandatory] end |
#output ⇒ Object
30 31 32 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 30 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
38 39 40 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 38 def output_file_directory File.join(base_output_dir, profile_identifier) end |
#output_file_name ⇒ Object
42 43 44 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 42 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#path_for_value(path) ⇒ Object
117 118 119 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 117 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#possible_status_search? ⇒ Boolean
145 146 147 148 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 145 def possible_status_search? ![:names].any? { |name| name.include? 'status' } && .search_definitions.keys.any? { |key| key.to_s.include? 'status' } end |
#post_search_description ⇒ Object
249 250 251 252 253 254 255 256 257 258 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 249 def post_search_description return '' unless test_post_search? <<~POST_SEARCH_DESCRIPTION Additionally, this test will check that GET and POST search methods return the same number of results. Search by POST is required by the FHIR R4 specification, and these tests interpret search by GET as a requirement of Plan Net #{.version}. POST_SEARCH_DESCRIPTION end |
#profile_identifier ⇒ Object
46 47 48 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 46 def profile_identifier Naming.snake_case_for_profile() end |
#reference_search_description ⇒ Object
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 229 def reference_search_description return '' unless test_reference_variants? <<~REFERENCE_SEARCH_DESCRIPTION This test verifies that the server supports searching by reference using the form `resource=[id]` as well as `resource=Resource/[id]`. The two different forms are expected to return the same number of results. Plan Net requires that both forms are supported by Plan Net responders. REFERENCE_SEARCH_DESCRIPTION end |
#required_comparators ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 125 def required_comparators @required_comparators ||= search_param_names.each_with_object({}) do |name, comparators| required_comparators = required_comparators_for_param(name) comparators[name] = required_comparators if required_comparators.present? end end |
#required_comparators_for_param(name) ⇒ Object
121 122 123 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 121 def required_comparators_for_param(name) search_definition(name)[:comparators].select { |_comparator, expectation| expectation == 'SHALL' } end |
#required_comparators_string ⇒ Object
172 173 174 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 172 def required_comparators_string array_of_strings(required_comparators.keys) end |
#required_multiple_or_search_params ⇒ Object
161 162 163 164 165 166 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 161 def required_multiple_or_search_params @multiple_or_search_params ||= search_param_names.select do |name| search_definition(name)[:multiple_or] == 'SHALL' end end |
#required_multiple_or_search_params_string ⇒ Object
168 169 170 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 168 def required_multiple_or_search_params_string array_of_strings(required_multiple_or_search_params) end |
#resource_type ⇒ Object
70 71 72 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 70 def resource_type .resource end |
#saves_delayed_references? ⇒ Boolean
141 142 143 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 141 def saves_delayed_references? first_search? && .delayed_references.present? end |
#search_definition(name) ⇒ Object
137 138 139 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 137 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
54 55 56 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 54 def search_identifier [:names].join('_').tr('-', '_') end |
#search_param_name_string ⇒ Object
101 102 103 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 101 def search_param_name_string [:names].join(' + ') end |
#search_param_names ⇒ Object
109 110 111 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 109 def search_param_names search_params.map { |param| param[:name] } end |
#search_param_names_array ⇒ Object
113 114 115 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 113 def search_param_names_array array_of_strings(search_param_names) end |
#search_params ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 78 def search_params @search_params ||= [:names].map do |name| { name: name, path: search_definition(name)[:path] } end end |
#search_properties ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 190 def search_properties {}.tap do |properties| properties[:first_search] = 'true' if first_search? properties[:fixed_value_search] = 'true' if fixed_value_search? properties[:resource_type] = "'#{resource_type}'" properties[:search_param_names] = search_param_names_array properties[:saves_delayed_references] = 'true' if saves_delayed_references? properties[:possible_status_search] = 'true' if possible_status_search? properties[:token_search_params] = token_search_params_string if token_search_params.present? properties[:test_reference_variants] = 'true' if test_reference_variants? properties[:params_with_comparators] = required_comparators_string if required_comparators.present? properties[:multiple_or_search_params] = required_multiple_or_search_params_string if required_multiple_or_search_params.present? properties[:test_post_search] = 'true' if first_search? end end |
#search_test_properties_string ⇒ Object
213 214 215 216 217 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 213 def search_test_properties_string search_properties .map { |key, value| "#{' ' * 8}#{key}: #{value}" } .join(",\n") end |
#search_title ⇒ Object
58 59 60 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 58 def search_title search_identifier.camelize end |
#template ⇒ Object
26 27 28 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 26 def template @template ||= File.read(File.join(__dir__, 'templates', 'search.rb.erb')) end |
#test_id ⇒ Object
50 51 52 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 50 def test_id "davinci_plan_net_#{.reformatted_version}_#{profile_identifier}_#{search_identifier}_search_test" end |
#test_post_search? ⇒ Boolean
186 187 188 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 186 def test_post_search? first_search? end |
#test_reference_variants? ⇒ Boolean
181 182 183 184 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 181 def test_reference_variants? # TODO false end |
#token_search_params ⇒ Object
150 151 152 153 154 155 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 150 def token_search_params @token_search_params ||= search_param_names.select do |name| ['Identifier', 'CodeableConcept', 'Coding'].include? .search_definitions[name.to_sym][:type] end end |
#token_search_params_string ⇒ Object
157 158 159 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 157 def token_search_params_string array_of_strings(token_search_params) end |
#url_version ⇒ Object
206 207 208 209 210 211 |
# File 'lib/davinci_plan_net_test_kit/generator/search_test_generator.rb', line 206 def url_version case .version when 'v3.1.1' 'STU3.1.1' end end |