Class: USCoreTestKit::Generator::GranularScopeResourceTypeGroupGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_dirObject

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_metadataObject

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_numberObject

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_metadataObject

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_nameObject



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_nameObject



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_nameObject



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

#descriptionObject



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

#generateObject



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_dirObject



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_idObject



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_nameObject



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_nameObject



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

#outputObject



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_nameObject



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_searchesObject



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_typeObject



84
85
86
# File 'lib/us_core_test_kit/generator/granular_scope_resource_type_group_generator.rb', line 84

def resource_type
  .resource
end

#scopesObject



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_stringObject



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_stringObject



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_descriptionObject



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

#templateObject



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_listObject



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_listObject



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

#titleObject



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