Class: IpaTestKit::Generator::ProvenanceRevincludeSearchTestGenerator
- Inherits:
-
Object
- Object
- IpaTestKit::Generator::ProvenanceRevincludeSearchTestGenerator
- Defined in:
- lib/ipa_test_kit/generator/provenance_revinclude_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
- #first_search? ⇒ Boolean
- #fixed_value_search? ⇒ Boolean
- #fixed_value_search_param_name ⇒ Object
- #generate ⇒ Object
-
#initialize(group_metadata, search_metadata, base_output_dir) ⇒ ProvenanceRevincludeSearchTestGenerator
constructor
A new instance of ProvenanceRevincludeSearchTestGenerator.
- #module_name ⇒ Object
- #needs_patient_id? ⇒ Boolean
- #output ⇒ Object
- #output_file_directory ⇒ Object
- #output_file_name ⇒ Object
- #path_for_value(path) ⇒ Object
- #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_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
- #token_search_params ⇒ Object
- #token_search_params_string ⇒ Object
Constructor Details
#initialize(group_metadata, search_metadata, base_output_dir) ⇒ ProvenanceRevincludeSearchTestGenerator
Returns a new instance of ProvenanceRevincludeSearchTestGenerator.
19 20 21 22 23 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 19 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.
17 18 19 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 17 def base_output_dir @base_output_dir end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
17 18 19 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 17 def @group_metadata end |
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
17 18 19 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 17 def @search_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 8 def generate(, base_output_dir) .groups .reject { |group| SpecialCases.exclude_group? group } .select { |group| group.revincludes.include? 'Provenance:target' } .select { |group| group.searches.any? } .each { |group| new(group, group.searches.first, base_output_dir).generate } end |
Instance Method Details
#array_of_strings(array) ⇒ Object
158 159 160 161 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 158 def array_of_strings(array) quoted_strings = array.map { |element| "'#{element}'" } "[#{quoted_strings.join(', ')}]" end |
#base_output_file_name ⇒ Object
33 34 35 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 33 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
61 62 63 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 61 def class_name "#{Naming.upper_camel_case_for_profile()}#{search_title}SearchTest" end |
#first_search? ⇒ Boolean
83 84 85 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 83 def first_search? .searches.first == end |
#fixed_value_search? ⇒ Boolean
87 88 89 90 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 87 def fixed_value_search? [:names] != ['patient'] && !.delayed? && resource_type != 'Patient' end |
#fixed_value_search_param_name ⇒ Object
92 93 94 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 92 def fixed_value_search_param_name ([:names] - [:patient]).first end |
#generate ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 177 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
65 66 67 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 65 def module_name "Ipa#{.reformatted_version.upcase}" end |
#needs_patient_id? ⇒ Boolean
101 102 103 104 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 101 def needs_patient_id? [:names].include?('patient') || (resource_type == 'Patient' && [:names].include?('_id')) end |
#output ⇒ Object
29 30 31 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 29 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
37 38 39 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 37 def output_file_directory File.join(base_output_dir, profile_identifier) end |
#output_file_name ⇒ Object
41 42 43 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 41 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#path_for_value(path) ⇒ Object
114 115 116 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 114 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#profile_identifier ⇒ Object
45 46 47 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 45 def profile_identifier Naming.snake_case_for_profile() end |
#required_comparators ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 122 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
118 119 120 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 118 def required_comparators_for_param(name) search_definition(name)[:comparators].select { |_comparator, expectation| expectation == 'SHALL' } end |
#required_comparators_string ⇒ Object
154 155 156 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 154 def required_comparators_string array_of_strings(required_comparators.keys) end |
#resource_type ⇒ Object
69 70 71 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 69 def resource_type .resource end |
#saves_delayed_references? ⇒ Boolean
139 140 141 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 139 def saves_delayed_references? first_search? && .delayed_references.present? end |
#search_definition(name) ⇒ Object
def patient_id_param?(param)
param[:name] == 'patient' ||
(resource_type == 'Patient' && param[:name] == '_id')
end
135 136 137 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 135 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
53 54 55 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 53 def search_identifier 'provenance_revinclude' end |
#search_param_name_string ⇒ Object
96 97 98 99 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 96 def search_param_name_string binding.pry if .nil? [:names].join(' + ') + ' + revInclude:Provenance:target' end |
#search_param_names ⇒ Object
106 107 108 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 106 def search_param_names search_params.map { |param| param[:name] } end |
#search_param_names_array ⇒ Object
110 111 112 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 110 def search_param_names_array array_of_strings(search_param_names) end |
#search_params ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 73 def search_params @search_params ||= [:names].map do |name| { name: name, path: search_definition(name)[:path] } end end |
#search_properties ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 163 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 end end |
#search_test_properties_string ⇒ Object
171 172 173 174 175 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 171 def search_test_properties_string search_properties .map { |key, value| "#{' ' * 8}#{key}: #{value}" } .join(",\n") end |
#search_title ⇒ Object
57 58 59 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 57 def search_title search_identifier.camelize end |
#template ⇒ Object
25 26 27 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 25 def template @template ||= File.read(File.join(__dir__, 'templates', 'provenance_revinclude_search.rb.erb')) end |
#test_id ⇒ Object
49 50 51 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 49 def test_id "ipa_#{.reformatted_version}_#{profile_identifier}_#{search_identifier}_search_test" end |
#token_search_params ⇒ Object
143 144 145 146 147 148 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 143 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
150 151 152 |
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 150 def token_search_params_string array_of_strings(token_search_params) end |