Class: DaVinciPlanNetTestKit::Generator::ForwardChainSearchTestGenerator
- Inherits:
-
Object
- Object
- DaVinciPlanNetTestKit::Generator::ForwardChainSearchTestGenerator
- Defined in:
- lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb
Instance Attribute Summary collapse
-
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
-
#chain_param ⇒ Object
Returns the value of attribute chain_param.
-
#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
- #a_or_an(name) ⇒ Object
- #array_of_strings(array) ⇒ Object
- #base_output_file_name ⇒ Object
- #chain_param_base ⇒ Object
- #chain_param_string ⇒ Object
- #chained_resource ⇒ 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, chain_param) ⇒ ForwardChainSearchTestGenerator
constructor
A new instance of ForwardChainSearchTestGenerator.
- #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_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, chain_param) ⇒ ForwardChainSearchTestGenerator
Returns a new instance of ForwardChainSearchTestGenerator.
23 24 25 26 27 28 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 23 def initialize(, , base_output_dir, chain_param) self. = self. = self.base_output_dir = base_output_dir self.chain_param = chain_param end |
Instance Attribute Details
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
21 22 23 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 21 def base_output_dir @base_output_dir end |
#chain_param ⇒ Object
Returns the value of attribute chain_param.
21 22 23 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 21 def chain_param @chain_param end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
21 22 23 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 21 def @group_metadata end |
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
21 22 23 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 21 def @search_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 8 def generate(, base_output_dir) .groups .reject { |group| SpecialCases.exclude_group? group } .each do |group| group.searches.each do |search_param| # Generate a test for any parameters that specify chaining, one for each chain requirement search_def = group.search_definitions[search_param[:names].first.to_sym] search_def[:chain]&.each { |chain_param| new(group, search_param, base_output_dir, chain_param[:chain]).generate } end end end |
Instance Method Details
#a_or_an(name) ⇒ Object
105 106 107 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 105 def a_or_an(name) ['a','e','i','o','u'].include?(name.first.downcase) ? "an #{name}" : "a #{name}" end |
#array_of_strings(array) ⇒ Object
160 161 162 163 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 160 def array_of_strings(array) quoted_strings = array.map { |element| "'#{element}'" } "[#{quoted_strings.join(', ')}]" end |
#base_output_file_name ⇒ Object
38 39 40 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 38 def base_output_file_name "#{class_name.underscore}.rb" end |
#chain_param_base ⇒ Object
95 96 97 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 95 def chain_param_base [:names].first end |
#chain_param_string ⇒ Object
91 92 93 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 91 def chain_param_string "#{profile_identifier}.#{chain_param.gsub(/[-:]/, '_')}" end |
#chained_resource ⇒ Object
99 100 101 102 103 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 99 def chained_resource res_type = search_definition(chain_param_base.to_sym)[:type] res_type = search_definition(chain_param_base.to_sym)[:target] if res_type == "Reference" res_type end |
#class_name ⇒ Object
66 67 68 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 66 def class_name "#{Naming.upper_camel_case_for_profile()}ForwardChain#{search_title}SearchTest" end |
#first_search? ⇒ Boolean
78 79 80 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 78 def first_search? .searches.first == end |
#fixed_value_search? ⇒ Boolean
82 83 84 85 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 82 def fixed_value_search? #TODO false end |
#fixed_value_search_param_name ⇒ Object
87 88 89 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 87 def fixed_value_search_param_name #TODO end |
#generate ⇒ Object
187 188 189 190 191 192 193 194 195 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 187 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_name ⇒ Object
165 166 167 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 165 def input_name "#{search_identifier.downcase}_input" end |
#module_name ⇒ Object
70 71 72 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 70 def module_name "DaVinciPlanNet#{.reformatted_version.upcase}" end |
#output ⇒ Object
34 35 36 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 34 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
42 43 44 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 42 def output_file_directory File.join(base_output_dir, profile_identifier.downcase) end |
#output_file_name ⇒ Object
46 47 48 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 46 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/forward_chain_test_generator.rb', line 117 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#possible_status_search? ⇒ Boolean
141 142 143 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 141 def possible_status_search? ![:names].include?('status') && .search_definitions.key?(:status) end |
#profile_identifier ⇒ Object
50 51 52 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 50 def profile_identifier Naming.snake_case_for_profile() end |
#required_comparators ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_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/forward_chain_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
156 157 158 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 156 def required_comparators_string array_of_strings(required_comparators.keys) end |
#resource_type ⇒ Object
74 75 76 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 74 def resource_type .resource end |
#saves_delayed_references? ⇒ Boolean
137 138 139 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 137 def saves_delayed_references? first_search? && .delayed_references.present? end |
#search_definition(name) ⇒ Object
133 134 135 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 133 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
58 59 60 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 58 def search_identifier "#{chain_param_base}_#{chain_param.to_s.gsub(/[-:]/, '_')}".underscore end |
#search_param_names ⇒ Object
109 110 111 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_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/forward_chain_test_generator.rb', line 113 def search_param_names_array array_of_strings(search_param_names) end |
#search_properties ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 169 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[:chain_param] = "'#{chain_param}'" properties[:chain_param_base] = "'#{chain_param_base}'" properties[:additional_resource_type] = "'#{chained_resource}'" end end |
#search_test_properties_string ⇒ Object
181 182 183 184 185 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 181 def search_test_properties_string search_properties .map { |key, value| "#{' ' * 10}#{key}: #{value}" } .join(",\n") end |
#search_title ⇒ Object
62 63 64 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 62 def search_title search_identifier.camelize end |
#template ⇒ Object
30 31 32 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 30 def template @template ||= File.read(File.join(__dir__, 'templates', 'forward_chain_test.rb.erb')) end |
#test_id ⇒ Object
54 55 56 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 54 def test_id "davinci_plan_net_#{.reformatted_version}_forward_chain_#{profile_identifier}_#{search_identifier}_search_test" end |
#token_search_params ⇒ Object
145 146 147 148 149 150 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 145 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
152 153 154 |
# File 'lib/davinci_plan_net_test_kit/generator/forward_chain_test_generator.rb', line 152 def token_search_params_string array_of_strings(token_search_params) end |