Class: USCoreTestKit::Generator::GranularScopeGroupGenerator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ig_metadata, base_output_dir, group_number) ⇒ GranularScopeGroupGenerator

Returns a new instance of GranularScopeGroupGenerator.



19
20
21
22
23
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 19

def initialize(, base_output_dir, group_number)
  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.



17
18
19
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 17

def base_output_dir
  @base_output_dir
end

#group_numberObject

Returns the value of attribute group_number.



17
18
19
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 17

def group_number
  @group_number
end

#ig_metadataObject

Returns the value of attribute ig_metadata.



17
18
19
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 17

def 
  @ig_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 8

def generate(, base_output_dir)
  return unless ['6', '7'].include? .ig_version[1]

  [1, 2].each do |group_number|
    new(, base_output_dir, group_number).generate
  end
end

Instance Method Details

#base_metadata_file_nameObject



37
38
39
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 37

def 
  "metadata.yml"
end

#base_output_file_nameObject



33
34
35
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 33

def base_output_file_name
  "#{class_name.underscore}.rb"
end

#class_nameObject



41
42
43
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 41

def class_name
  "GranularScopes#{group_number}Group"
end

#descriptionObject



116
117
118
119
120
121
122
123
124
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 116

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



69
70
71
72
73
74
75
76
77
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 69

def generate
  FileUtils.mkdir_p(group_dir)
  File.open(output_file_name, 'w') { |f| f.write(output) }
  .granular_scope_groups <<
    {
      id: group_id,
      file_name: base_output_file_name
    }
end

#group_dirObject



61
62
63
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 61

def group_dir
  File.join(base_output_dir, 'granular_scope_tests')
end

#group_file_listObject



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 89

def group_file_list
  @group_file_list ||=
    .granular_scope_resource_type_groups
      .values
      .flatten
      .select { |group| group[:file_name].include? "scope#{group_number}" }
      .map do |group|
        name_without_suffix = group[:file_name].delete_suffix('.rb')
        "./#{name_without_suffix}"
      end
end

#group_idObject



65
66
67
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 65

def group_id
  "us_core_#{.reformatted_version}_smart_granular_scopes_#{group_number}"
end

#group_id_listObject



79
80
81
82
83
84
85
86
87
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 79

def group_id_list
  @group_id_list ||=
    
      .granular_scope_resource_type_groups
      .values
      .flatten
      .map { |group| group[:id] }
      .select { |id| id.include? "scope_#{group_number}" }
end

#module_nameObject



45
46
47
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 45

def module_name
  "USCore#{.reformatted_version.upcase}"
end

#outputObject



29
30
31
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 29

def output
  @output ||= ERB.new(template).result(binding)
end

#output_file_nameObject



57
58
59
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 57

def output_file_name
  File.join(base_output_dir, base_output_file_name)
end

#scopes_stringObject



108
109
110
111
112
113
114
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 108

def scopes_string
  SmartScopesConstants.const_get("SMART_GRANULAR_SCOPES_GROUP#{group_number}")
    .dig(.reformatted_version)
    .map { |scope| scope.delete_prefix 'patient/' }
    .map { |scope| "* `#{scope}`" }
    .join("\n")
end

#search_param_name_stringObject



101
102
103
104
105
106
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 101

def search_param_name_string
  required_searches
    .map { |search| search[:names].join(' + ') }
    .map { |names| "* #{names}" }
    .join("\n")
end

#short_descriptionObject



53
54
55
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 53

def short_description
  # TODO
end

#templateObject



25
26
27
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 25

def template
  @template ||= File.read(File.join(__dir__, 'templates', 'granular_scope_group.rb.erb'))
end

#titleObject



49
50
51
# File 'lib/us_core_test_kit/generator/granular_scope_group_generator.rb', line 49

def title
  "#US Core FHIR API w/Granular Scopes #{group_number}"
end