Class: USCoreTestKit::Generator::GranularScopeResourceTypeGroupGenerator
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::GranularScopeResourceTypeGroupGenerator
- Defined in:
- lib/us_core_test_kit/generator/granular_scope_resource_type_group_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.
-
#ig_metadata ⇒ Object
Returns the value of attribute ig_metadata.
Class Method Summary collapse
Instance Method Summary collapse
- #base_metadata_file_name ⇒ Object
- #base_output_file_name ⇒ Object
- #class_name ⇒ Object
- #description ⇒ Object
- #generate ⇒ Object
- #group_dir ⇒ Object
- #group_id ⇒ Object
-
#initialize(group_metadata, ig_metadata, base_output_dir, group_number) ⇒ GranularScopeResourceTypeGroupGenerator
constructor
A new instance of GranularScopeResourceTypeGroupGenerator.
- #metadata_file_name ⇒ Object
- #module_name ⇒ Object
- #output ⇒ Object
- #output_file_name ⇒ Object
- #required_searches ⇒ Object
- #resource_type ⇒ Object
- #scopes ⇒ Object
- #scopes_string ⇒ Object
- #search_param_name_string ⇒ Object
- #short_description ⇒ Object
- #template ⇒ Object
- #test_file_list ⇒ Object
- #test_id_list ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(group_metadata, ig_metadata, base_output_dir, group_number) ⇒ GranularScopeResourceTypeGroupGenerator
29 30 31 32 33 34 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 29 def initialize(, , base_output_dir, group_number) self. = self. = self.base_output_dir = base_output_dir self.group_number = group_number 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_resource_type_group_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_resource_type_group_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_resource_type_group_generator.rb', line 27 def group_number @group_number end |
#ig_metadata ⇒ Object
Returns the value of attribute ig_metadata.
27 28 29 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 27 def @ig_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_resource_type_group_generator.rb', line 9 def generate(, base_output_dir) return if .ig_version[1].to_i < 6 [1, 2].each do |group_number| groups = .groups.select { |group| group.granular_scope_tests.present? } scopes = SmartScopesConstants .const_get("SMART_GRANULAR_SCOPES_GROUP#{group_number}")[.reformatted_version] groups.each do || next if scopes.none? { |scope| scope.start_with? "patient/#{.resource}" } new(GroupMetadata.new(.to_hash), , base_output_dir, group_number).generate end end end |
Instance Method Details
#base_metadata_file_name ⇒ Object
48 49 50 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 48 def "metadata.yml" end |
#base_output_file_name ⇒ Object
44 45 46 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 44 def base_output_file_name "#{class_name.underscore}.rb" end |
#class_name ⇒ Object
52 53 54 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 52 def class_name "#{resource_type}GranularScope#{group_number}Group" end |
#description ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 133 def description <<~DESCRIPTION The tests in this group repeat all of the searches from the US Core FHIR API tests, and verify that the resources returned are filtered based on the following granular scopes: #{scopes_string} DESCRIPTION end |
#generate ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 88 def generate FileUtils.mkdir_p(group_dir) File.open(output_file_name, 'w') { |f| f.write(output) } .id = group_id .file_name = base_output_file_name .granular_scope_resource_type_groups[resource_type] << .to_hash.slice(:granular_scope_resource_type_groups, :id, :file_name) File.open(, 'w') { |f| f.write(YAML.dump(.to_hash)) } end |
#group_dir ⇒ Object
72 73 74 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 72 def group_dir File.join(base_output_dir, 'granular_scope_tests', resource_type.underscore) end |
#group_id ⇒ Object
80 81 82 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 80 def group_id "us_core_#{.reformatted_version}_#{resource_type.underscore}_granular_scope_#{group_number}_group" end |
#metadata_file_name ⇒ Object
76 77 78 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 76 def File.join(group_dir, ) end |
#module_name ⇒ Object
56 57 58 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 56 def module_name "USCore#{.reformatted_version.upcase}" end |
#output ⇒ Object
40 41 42 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 40 def output @output ||= ERB.new(template).result(binding) end |
#output_file_name ⇒ Object
68 69 70 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 68 def output_file_name File.join(base_output_dir, base_output_file_name) end |
#required_searches ⇒ Object
110 111 112 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 110 def required_searches .searches.select { |search| search[:expectation] == 'SHALL' } end |
#resource_type ⇒ Object
84 85 86 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 84 def resource_type .resource end |
#scopes ⇒ Object
121 122 123 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 121 def scopes SmartScopesConstants.const_get("SMART_GRANULAR_SCOPES_GROUP#{group_number}")[.reformatted_version] end |
#scopes_string ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 125 def scopes_string scopes .map { |scope| scope.delete_prefix 'patient/' } .select { |scope| scope.start_with? resource_type } .map { |scope| "* `#{scope}`" } .join("\n") end |
#search_param_name_string ⇒ Object
114 115 116 117 118 119 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 114 def search_param_name_string required_searches .map { |search| search[:names].join(' + ') } .map { |names| "* #{names}" } .join("\n") end |
#short_description ⇒ Object
64 65 66 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 64 def short_description .short_description end |
#template ⇒ Object
36 37 38 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 36 def template @template ||= File.read(File.join(__dir__, 'templates', 'granular_scope_resource_type_group.rb.erb')) end |
#test_file_list ⇒ Object
103 104 105 106 107 108 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 103 def test_file_list @test_file_list ||= .granular_scope_tests.map do |test| "./granular_scope_tests/#{resource_type.underscore}/#{test[:file_name].delete_suffix('.rb')}" end end |
#test_id_list ⇒ Object
98 99 100 101 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 98 def test_id_list @test_id_list ||= .granular_scope_tests.map { |test| test[:id] } end |
#title ⇒ Object
60 61 62 |
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 60 def title "#{resource_type} Granular Scope" end |