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 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 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 if .ig_version[1].to_i < 6 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 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/us_core_test_kit/generator/granular_scope_test_generator.rb', line 154 def description " This test repeats all \#{resource_type} searches by\n \#{search_param_name_string} and verifies that the results have been\n filtered based on the granted granular scopes. The response to each\n repeated request will be compared to the corresponding original response\n independently using the following logic:\n - If the repeated search filters on a category value that\n is explicitly included within the granted scopes, e.g., a search for\n `Observation?category=survey` when the granted scopes includes\n `patient/Observation.rs?category=survey`, then the server is required to\n return the original response filtered to include only entries that match\n one of the granted scopes.\n - Otherwise, e.g., a search for `Observation?category=cognitive-status`\n when the granted scopes include only `patient/Observation.rs?category=survey`,\n servers may indicate that the request is unauthorized either through an empty\n Bundle or an explicit HTTP error, or they may return the original response\n filtered to include only entries that match one of the granted scopes.\n DESCRIPTION\nend\n".gsub(/\n{3,}/, "\n\n") |
#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#{group_metadata.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_#{group_metadata.reformatted_version}_#{resource_type}_#{search_identifier}_granular_scope_search_test" end |