Class: DaVinciPlanNetTestKit::Generator::CombinationSearchTestGenerator
- Inherits:
-
Object
- Object
- DaVinciPlanNetTestKit::Generator::CombinationSearchTestGenerator
- Defined in:
- lib/davinci_plan_net_test_kit/generator/combination_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.
-
#test_data ⇒ Object
Returns the value of attribute test_data.
Class Method Summary collapse
Instance Method Summary collapse
- #a_or_an(name) ⇒ Object
- #additional_resource_type ⇒ Object
- #array_of_strings(array) ⇒ Object
- #base_output_file_name ⇒ Object
- #class_name ⇒ Object
- #first_search? ⇒ Boolean
- #fixed_value_search? ⇒ Boolean
- #fixed_value_search_param_name ⇒ Object
- #generate ⇒ Object
-
#initialize(group_metadata, search_metadata, base_output_dir, combination_example) ⇒ CombinationSearchTestGenerator
constructor
A new instance of CombinationSearchTestGenerator.
- #input_description ⇒ Object
- #input_name ⇒ Object
- #module_name ⇒ Object
- #optional_input? ⇒ Boolean
- #output ⇒ Object
- #output_file_directory ⇒ Object
- #output_file_name ⇒ Object
- #path_for_value(path) ⇒ Object
- #possible_status_search? ⇒ Boolean
- #profile_identifier ⇒ Object
- #required_comparators ⇒ Object
- #required_comparators_for_param(name) ⇒ Object
- #required_comparators_string ⇒ Object
- #resource_type ⇒ Object
- #saves_delayed_references? ⇒ Boolean
- #search_definition(name) ⇒ Object
- #search_identifier ⇒ 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_description ⇒ Object
- #test_goal ⇒ Object
- #test_id ⇒ Object
- #token_search_params ⇒ Object
- #token_search_params_string ⇒ Object
Constructor Details
#initialize(group_metadata, search_metadata, base_output_dir, combination_example) ⇒ CombinationSearchTestGenerator
Returns a new instance of CombinationSearchTestGenerator.
20 21 22 23 24 25 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 20 def initialize(, , base_output_dir, combination_example) self. = self. = self.base_output_dir = base_output_dir self.test_data = combination_example 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/combination_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/combination_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/combination_search_test_generator.rb', line 18 def @search_metadata end |
#test_data ⇒ Object
Returns the value of attribute test_data.
18 19 20 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 18 def test_data @test_data end |
Class Method Details
.generate(ig_metadata, examples_hash, base_output_dir) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 8 def generate(, examples_hash, base_output_dir) examples_hash.keys.each do |group| examples_hash[group].each do |combination_example| group_to_add_to = .groups.find { || .name == "plannet_#{group}"} new(group_to_add_to, group_to_add_to.searches.first, base_output_dir, combination_example).generate end end end |
Instance Method Details
#a_or_an(name) ⇒ Object
110 111 112 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 110 def a_or_an(name) ['a','e','i','o','u'].include?(name.first.downcase) ? "an #{name}" : "a #{name}" end |
#additional_resource_type ⇒ Object
75 76 77 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 75 def additional_resource_type test_data['additional_resource_type'] end |
#array_of_strings(array) ⇒ Object
165 166 167 168 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 165 def array_of_strings(array) quoted_strings = array.map { |element| "'#{element}'" } "[#{quoted_strings.join(', ')}]" end |
#base_output_file_name ⇒ Object
35 36 37 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 35 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
63 64 65 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 63 def class_name "#{Naming.upper_camel_case_for_profile()}#{search_title}SearchTest" end |
#first_search? ⇒ Boolean
97 98 99 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 97 def first_search? .searches.first == end |
#fixed_value_search? ⇒ Boolean
101 102 103 104 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 101 def fixed_value_search? #TODO false end |
#fixed_value_search_param_name ⇒ Object
106 107 108 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 106 def fixed_value_search_param_name #TODO end |
#generate ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 204 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 |
#input_description ⇒ Object
178 179 180 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 178 def input_description test_data['input_description'] end |
#input_name ⇒ Object
170 171 172 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 170 def input_name "#{search_identifier}_input" end |
#module_name ⇒ Object
67 68 69 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 67 def module_name "DaVinciPlanNet#{.reformatted_version.upcase}" end |
#optional_input? ⇒ Boolean
174 175 176 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 174 def optional_input? test_data['optional_input'] end |
#output ⇒ Object
31 32 33 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 31 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
39 40 41 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 39 def output_file_directory File.join(base_output_dir, profile_identifier.downcase) end |
#output_file_name ⇒ Object
43 44 45 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 43 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#path_for_value(path) ⇒ Object
122 123 124 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 122 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#possible_status_search? ⇒ Boolean
146 147 148 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 146 def possible_status_search? ![:names].include?('status') && .search_definitions.key?(:status) end |
#profile_identifier ⇒ Object
47 48 49 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 47 def profile_identifier Naming.snake_case_for_profile() end |
#required_comparators ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 130 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
126 127 128 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 126 def required_comparators_for_param(name) search_definition(name)[:comparators].select { |_comparator, expectation| expectation == 'SHALL' } end |
#required_comparators_string ⇒ Object
161 162 163 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 161 def required_comparators_string array_of_strings(required_comparators.keys) end |
#resource_type ⇒ Object
71 72 73 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 71 def resource_type .resource end |
#saves_delayed_references? ⇒ Boolean
142 143 144 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 142 def saves_delayed_references? first_search? && .delayed_references.present? end |
#search_definition(name) ⇒ Object
138 139 140 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 138 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
55 56 57 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 55 def search_identifier test_data['name'].gsub(/[-:]/, '_').underscore.gsub("organization_affiliation", "org_affil") end |
#search_param_names ⇒ Object
114 115 116 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 114 def search_param_names search_params.map { |param| param[:name] } end |
#search_param_names_array ⇒ Object
118 119 120 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 118 def search_param_names_array array_of_strings(search_param_names) end |
#search_params ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 87 def search_params @search_params ||= test_data['base_search_params'].map do |name| { name: name, path: search_definition(name)[:path] } end end |
#search_properties ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 182 def search_properties {}.tap do |properties| properties[:fixed_value_search] = 'true' if fixed_value_search? properties[:resource_type] = "'#{resource_type}'" properties[:search_param_names] = search_param_names_array properties[:input_name] = "'#{input_name}'" properties[:include_param] ="'#{test_data['include_param']}'" if !test_data['include_param'].empty? properties[:inc_param_sp] ="'#{test_data['inc_param_sp']}'" if !test_data['inc_param_sp'].empty? properties[:reverse_chain_param] = "'#{test_data['reverse_chain_param']}'" if !test_data['reverse_chain_param'].empty? properties[:reverse_chain_target] = "'#{test_data['reverse_chain_target']}'" if !test_data['reverse_chain_target'].empty? properties[:possible_status_search] = 'true' if possible_status_search? properties[:additional_resource_type] = "'#{additional_resource_type}'" properties[:combination_search] = 'true' end end |
#search_test_properties_string ⇒ Object
198 199 200 201 202 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 198 def search_test_properties_string search_properties .map { |key, value| "#{' ' * 10}#{key}: #{value}" } .join(",\n") end |
#search_title ⇒ Object
59 60 61 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 59 def search_title search_identifier.camelize end |
#template ⇒ Object
27 28 29 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 27 def template @template ||= File.read(File.join(__dir__, 'templates', 'combination_search_test.rb.erb')) end |
#test_description ⇒ Object
79 80 81 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 79 def test_description test_data['description'] end |
#test_goal ⇒ Object
83 84 85 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 83 def test_goal test_data['goal'] end |
#test_id ⇒ Object
51 52 53 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_search_test_generator.rb', line 51 def test_id "davinci_plan_net_#{.reformatted_version}_#{profile_identifier}_#{search_identifier}_search_test" end |
#token_search_params ⇒ Object
150 151 152 153 154 155 |
# File 'lib/davinci_plan_net_test_kit/generator/combination_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/combination_search_test_generator.rb', line 157 def token_search_params_string array_of_strings(token_search_params) end |