Class: USCoreTestKit::Generator::GranularScopeTestGenerator
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::GranularScopeTestGenerator
- Defined in:
- lib/us_core_test_kit/generator/granular_scope_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.
-
#group_number ⇒ Object
Returns the value of attribute group_number.
-
#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
- #conformance_expectation ⇒ Object
- #description ⇒ Object
- #generate ⇒ Object
-
#initialize(group_metadata, search_metadata, base_output_dir) ⇒ GranularScopeTestGenerator
constructor
A new instance of GranularScopeTestGenerator.
- #module_name ⇒ Object
- #needs_patient_id? ⇒ Boolean
- #optional? ⇒ Boolean
- #output ⇒ Object
- #output_file_directory ⇒ Object
- #output_file_name ⇒ Object
- #path_for_value(path) ⇒ Object
- #profile_identifier ⇒ Object
- #resource_type ⇒ Object
- #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
Constructor Details
#initialize(group_metadata, search_metadata, base_output_dir) ⇒ GranularScopeTestGenerator
Returns a new instance of GranularScopeTestGenerator.
29 30 31 32 33 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 29 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.
27 28 29 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 27 def base_output_dir @base_output_dir end |
#group_metadata ⇒ Object
Returns the value of attribute group_metadata.
27 28 29 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 27 def @group_metadata end |
#group_number ⇒ Object
Returns the value of attribute group_number.
27 28 29 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 27 def group_number @group_number end |
#search_metadata ⇒ Object
Returns the value of attribute search_metadata.
27 28 29 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 27 def @search_metadata end |
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 9 def generate(, base_output_dir) return unless ['6', '7'].include? .ig_version[1] scopes = SmartScopesConstants::SMART_GRANULAR_SCOPES_GROUP1[.reformatted_version] + SmartScopesConstants::SMART_GRANULAR_SCOPES_GROUP2[.reformatted_version] SmartScopesConstants::SMART_GRANULAR_SCOPE_RESOURCES.each do |resource_type| group = .groups.find { |group| group.resource == resource_type } next if scopes.none? { |scope| scope.start_with? "patient/#{group.resource}" } group.searches .each { |search| new(group, search, base_output_dir).generate } end end |
Instance Method Details
#array_of_strings(array) ⇒ Object
126 127 128 129 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 126 def array_of_strings(array) quoted_strings = array.map { |element| "'#{element}'" } "[#{quoted_strings.join(', ')}]" end |
#base_output_file_name ⇒ Object
43 44 45 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 43 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
71 72 73 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 71 def class_name "#{resource_type}#{search_title}GranularScopeSearchTest" end |
#conformance_expectation ⇒ Object
83 84 85 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 83 def conformance_expectation [:expectation] end |
#description ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 154 def description <<~DESCRIPTION.gsub(/\n{3,}/, "\n\n") This test repeats all #{resource_type} searches by #{search_param_name_string} and verifies that the results have been filtered based on the granted granular scopes. DESCRIPTION end |
#generate ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 144 def generate FileUtils.mkdir_p(output_file_directory) File.open(output_file_name, 'w') { |f| f.write(output) } .add_granular_scope_test( id: test_id, file_name: base_output_file_name ) end |
#module_name ⇒ Object
75 76 77 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 75 def module_name "USCore#{.reformatted_version.upcase}" end |
#needs_patient_id? ⇒ Boolean
101 102 103 104 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 101 def needs_patient_id? [:names].include?('patient') || (resource_type == 'Patient' && [:names].include?('_id')) end |
#optional? ⇒ Boolean
118 119 120 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 118 def optional? conformance_expectation != 'SHALL' || ![:must_support_or_mandatory] end |
#output ⇒ Object
39 40 41 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 39 def output @output ||= ERB.new(template).result(binding) end |
#output_file_directory ⇒ Object
47 48 49 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 47 def output_file_directory File.join(base_output_dir, 'granular_scope_tests', resource_type.underscore) end |
#output_file_name ⇒ Object
51 52 53 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 51 def output_file_name File.join(output_file_directory, base_output_file_name) end |
#path_for_value(path) ⇒ Object
114 115 116 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 114 def path_for_value(path) path == 'class' ? 'local_class' : path end |
#profile_identifier ⇒ Object
55 56 57 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 55 def profile_identifier Naming.snake_case_for_profile() end |
#resource_type ⇒ Object
79 80 81 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 79 def resource_type .resource end |
#search_definition(name) ⇒ Object
122 123 124 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 122 def search_definition(name) .search_definitions[name.to_sym] end |
#search_identifier ⇒ Object
63 64 65 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 63 def search_identifier [:names].join('_').tr('-', '_') end |
#search_param_name_string ⇒ Object
97 98 99 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 97 def search_param_name_string [:names].join(' + ') end |
#search_param_names ⇒ Object
106 107 108 |
# File 'lib/us_core_test_kit/generator/granular_scope_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/us_core_test_kit/generator/granular_scope_test_generator.rb', line 110 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/us_core_test_kit/generator/granular_scope_test_generator.rb', line 87 def search_params @search_params ||= [:names].map do |name| { name: name, path: search_definition(name)[:path] } end end |
#search_properties ⇒ Object
131 132 133 134 135 136 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 131 def search_properties {}.tap do |properties| properties[:resource_type] = "'#{resource_type}'" properties[:search_param_names] = search_param_names_array end end |
#search_test_properties_string ⇒ Object
138 139 140 141 142 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 138 def search_test_properties_string search_properties .map { |key, value| "#{' ' * 8}#{key}: #{value}" } .join(",\n") end |
#search_title ⇒ Object
67 68 69 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 67 def search_title search_identifier.camelize end |
#template ⇒ Object
35 36 37 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 35 def template @template ||= File.read(File.join(__dir__, 'templates', 'granular_scope_test.rb.erb')) end |
#test_id ⇒ Object
59 60 61 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 59 def test_id "us_core_#{.reformatted_version}_#{resource_type}_#{search_identifier}_granular_scope_search_test" end |