Class: DaVinciPlanNetTestKit::Generator::IncludeSearchTestGenerator
- Inherits:
-
Object
- Object
- DaVinciPlanNetTestKit::Generator::IncludeSearchTestGenerator
- Defined in:
- lib/davinci_plan_net_test_kit/generator/include_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.
-
#include_param ⇒ Object
Returns the value of attribute include_param.
-
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #a_or_an(name) ⇒ 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
- #inc_param_sp ⇒ Object
- #include_param_resource ⇒ Object
- #include_param_string ⇒ Object
-
#initialize(group_metadata, search_metadata, base_output_dir, include_param) ⇒ IncludeSearchTestGenerator
constructor
A new instance of IncludeSearchTestGenerator.
- #input_name ⇒ Object
- #module_name ⇒ Object
- #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_id ⇒ Object
- #token_search_params ⇒ Object
- #token_search_params_string ⇒ Object
Constructor Details
#initialize(group_metadata, search_metadata, base_output_dir, include_param) ⇒ IncludeSearchTestGenerator
Returns a new instance of IncludeSearchTestGenerator.
20 21 22 23 24 25 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 20 def initialize(, , base_output_dir, include_param) self. = self. = self.base_output_dir = base_output_dir self.include_param = include_param 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/include_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/include_search_test_generator.rb', line 18 def @group_metadata end |
#include_param ⇒ Object
Returns the value of attribute include_param.
18 19 20 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 18 def include_param @include_param end |
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
18 19 20 |
# File 'lib/davinci_plan_net_test_kit/generator/include_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/include_search_test_generator.rb', line 8 def generate(, base_output_dir) .groups .reject { |group| SpecialCases.exclude_group? group } .select { |group| !group.include_params.empty? } .each do |group| group.include_params.each { |include_param| new(group, group.searches.first, base_output_dir, include_param).generate } end end |
Instance Method Details
#a_or_an(name) ⇒ Object
168 169 170 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 168 def a_or_an(name) ['a','e','i','o','u'].include?(name.first.downcase) ? "an #{name}" : "a #{name}" end |
#array_of_strings(array) ⇒ Object
163 164 165 166 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 163 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/include_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/include_search_test_generator.rb', line 63 def class_name "#{Naming.upper_camel_case_for_profile()}Include#{search_title}SearchTest" end |
#first_search? ⇒ Boolean
85 86 87 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 85 def first_search? .searches.first == end |
#fixed_value_search? ⇒ Boolean
89 90 91 92 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 89 def fixed_value_search? #TODO false end |
#fixed_value_search_param_name ⇒ Object
94 95 96 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 94 def fixed_value_search_param_name #TODO end |
#generate ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 194 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 |
#inc_param_sp ⇒ Object
108 109 110 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 108 def inc_param_sp include_param.split(/:/)[1] end |
#include_param_resource ⇒ Object
102 103 104 105 106 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 102 def include_param_resource res_type = .search_definitions[:"#{include_param.split(/:/)[1]}"][:type] res_type = .search_definitions[:"#{include_param.split(/:/)[1]}"][:target] if res_type == "Reference" res_type end |
#include_param_string ⇒ Object
98 99 100 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 98 def include_param_string "_include=#{include_param}" end |
#input_name ⇒ Object
172 173 174 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 172 def input_name "#{search_identifier.downcase}_input" end |
#module_name ⇒ Object
67 68 69 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 67 def module_name "DaVinciPlanNet#{.reformatted_version.upcase}" end |
#output ⇒ Object
31 32 33 |
# File 'lib/davinci_plan_net_test_kit/generator/include_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/include_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/include_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
120 121 122 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 120 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#possible_status_search? ⇒ Boolean
144 145 146 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 144 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/include_search_test_generator.rb', line 47 def profile_identifier Naming.snake_case_for_profile() end |
#required_comparators ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 128 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
124 125 126 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 124 def required_comparators_for_param(name) search_definition(name)[:comparators].select { |_comparator, expectation| expectation == 'SHALL' } end |
#required_comparators_string ⇒ Object
159 160 161 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 159 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/include_search_test_generator.rb', line 71 def resource_type .resource end |
#saves_delayed_references? ⇒ Boolean
140 141 142 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 140 def saves_delayed_references? first_search? && .delayed_references.present? end |
#search_definition(name) ⇒ Object
136 137 138 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 136 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
55 56 57 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 55 def search_identifier include_param.gsub(/[-:]/, '_').underscore end |
#search_param_names ⇒ Object
112 113 114 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 112 def search_param_names search_params.map { |param| param[:name] } end |
#search_param_names_array ⇒ Object
116 117 118 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 116 def search_param_names_array array_of_strings(search_param_names) end |
#search_params ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 75 def search_params @search_params ||= [:names].map do |name| { name: name, path: search_definition(name)[:path] } end end |
#search_properties ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 176 def search_properties {}.tap do |properties| properties[:fixed_value_search] = 'true' if fixed_value_search? properties[:resource_type] = "'#{resource_type}'" properties[:search_param_names] = [] properties[:possible_status_search] = 'true' if possible_status_search? properties[:include_param] = "'#{include_param}'" properties[:inc_param_sp] = "'#{inc_param_sp}'" properties[:additional_resource_type] = "'#{include_param_resource}'" end end |
#search_test_properties_string ⇒ Object
188 189 190 191 192 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 188 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/include_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/include_search_test_generator.rb', line 27 def template @template ||= File.read(File.join(__dir__, 'templates', 'include_search.rb.erb')) end |
#test_id ⇒ Object
51 52 53 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 51 def test_id "davinci_plan_net_#{.reformatted_version}_include_#{profile_identifier}_#{search_identifier}_search_test" end |
#token_search_params ⇒ Object
148 149 150 151 152 153 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 148 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
155 156 157 |
# File 'lib/davinci_plan_net_test_kit/generator/include_search_test_generator.rb', line 155 def token_search_params_string array_of_strings(token_search_params) end |