Class: USCoreTestKit::Generator::ProvenanceRevincludeSearchTestGenerator
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::ProvenanceRevincludeSearchTestGenerator
- Defined in:
- lib/us_core_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
- #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_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.
18 19 20 21 22 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 18 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.
16 17 18 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 16 def base_output_dir @base_output_dir end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
16 17 18 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 16 def @group_metadata end |
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
16 17 18 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 16 def @search_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/us_core_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' } .each { |group| new(group, group.searches.first, base_output_dir).generate } end |
Instance Method Details
#array_of_strings(array) ⇒ Object
160 161 162 163 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_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
32 33 34 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 32 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
60 61 62 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 60 def class_name "#{Naming.upper_camel_case_for_profile()}#{search_title}SearchTest" end |
#first_search? ⇒ Boolean
82 83 84 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 82 def first_search? .searches.first == end |
#fixed_value_search? ⇒ Boolean
86 87 88 89 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 86 def fixed_value_search? [:names] != ['patient'] && !.delayed? && resource_type != 'Patient' end |
#fixed_value_search_param_name ⇒ Object
91 92 93 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 91 def fixed_value_search_param_name ([:names] - [:patient]).first end |
#generate ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 180 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
64 65 66 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 64 def module_name "USCore#{.reformatted_version.upcase}" end |
#needs_patient_id? ⇒ Boolean
99 100 101 102 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 99 def needs_patient_id? [:names].include?('patient') || (resource_type == 'Patient' && [:names].include?('_id')) end |
#output ⇒ Object
28 29 30 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 28 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
36 37 38 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 36 def output_file_directory File.join(base_output_dir, profile_identifier) end |
#output_file_name ⇒ Object
40 41 42 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 40 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#path_for_value(path) ⇒ Object
112 113 114 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 112 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#possible_status_search? ⇒ Boolean
141 142 143 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 141 def possible_status_search? ![:names].include?('status') && .search_definitions.key?(:status) end |
#profile_identifier ⇒ Object
44 45 46 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 44 def profile_identifier Naming.snake_case_for_profile() end |
#required_comparators ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 120 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
116 117 118 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 116 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/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 156 def required_comparators_string array_of_strings(required_comparators.keys) end |
#resource_type ⇒ Object
68 69 70 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 68 def resource_type .resource end |
#saves_delayed_references? ⇒ Boolean
137 138 139 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 137 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
133 134 135 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 133 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
52 53 54 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 52 def search_identifier 'provenance_revinclude' end |
#search_param_name_string ⇒ Object
95 96 97 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 95 def search_param_name_string [:names].join(' + ') + ' + revInclude:Provenance:target' end |
#search_param_names ⇒ Object
104 105 106 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 104 def search_param_names search_params.map { |param| param[:name] } end |
#search_param_names_array ⇒ Object
108 109 110 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 108 def search_param_names_array array_of_strings(search_param_names) end |
#search_params ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 72 def search_params @search_params ||= [:names].map do |name| { name: name, path: search_definition(name)[:path] } end end |
#search_properties ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 165 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[:possible_status_search] = 'true' if possible_status_search? end end |
#search_test_properties_string ⇒ Object
174 175 176 177 178 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 174 def search_test_properties_string search_properties .map { |key, value| "#{' ' * 8}#{key}: #{value}" } .join(",\n") end |
#search_title ⇒ Object
56 57 58 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 56 def search_title search_identifier.camelize end |
#template ⇒ Object
24 25 26 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 24 def template @template ||= File.read(File.join(__dir__, 'templates', 'provenance_revinclude_search.rb.erb')) end |
#test_id ⇒ Object
48 49 50 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 48 def test_id "us_core_#{.reformatted_version}_#{profile_identifier}_#{search_identifier}_search_test" end |
#token_search_params ⇒ Object
145 146 147 148 149 150 |
# File 'lib/us_core_test_kit/generator/provenance_revinclude_search_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/us_core_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 152 def token_search_params_string array_of_strings(token_search_params) end |