Class: CarinForBlueButtonTestKit::Generator::IncludeSearchTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, search_param, base_output_dir) ⇒ IncludeSearchTestGenerator

Returns a new instance of IncludeSearchTestGenerator.



10
11
12
13
14
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 10

def initialize(, search_param, base_output_dir)
  self. = 
  self.search_param = search_param
  self.base_output_dir = base_output_dir
end

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 8

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 8

def 
  @group_metadata
end

#search_paramObject

Returns the value of attribute search_param.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 8

def search_param
  @search_param
end

Instance Method Details

#base_output_file_nameObject



46
47
48
49
50
51
52
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 46

def base_output_file_name
  file_name = class_name
  file_name.sub!(resource_type, '')
  file_name = file_name.underscore
  file_name.sub!("#{profile_identifier}", 'incl')
  "#{file_name}.rb"
end

#class_nameObject



62
63
64
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 62

def class_name
  "#{Naming.upper_camel_case_for_profile()}#{remove_star}SearchTest"
end

#descriptionObject



119
120
121
122
123
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 119

def description
  <<~DESCRIPTION
    Tests that the server responds correctly when using _include="#{search_param}" as a search parameter 
  DESCRIPTION
end

#generateObject



16
17
18
19
20
21
22
23
24
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 16

def generate
  FileUtils.mkdir_p(output_file_directory)
  File.open(output_file_name, 'w') { |f| f.write(output) }

  .add_test(
    id: test_id,
    file_name: base_output_file_name
  )
end

#include_parametersObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 78

def include_parameters
  case search_param
  when 'ExplanationOfBenefit:payee'
      [{path: 'payee.party', target: 'Organization'}]
  when 'ExplanationOfBenefit:*'
      search_definitions = ['patient', 'provider', 'care-team', 'coverage', 'insurer']
      include_params = []
      search_definitions.each do |search_def|
        target_paths = .search_definitions[search_def.to_sym][:target_paths]
        include_params = include_params + target_paths
      end
      include_params
  else
    .search_definitions[include_search_type.to_sym][:target_paths]
  end
end

#include_search_paramObject



115
116
117
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 115

def include_search_param
  search_param
end

#include_search_typeObject



95
96
97
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 95

def include_search_type
  search_param.sub("#{resource_type}:", "")
end

#input_descriptionObject



74
75
76
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 74

def input_description
  "#{resource_type} search parameter: _id"
end

#input_idObject



66
67
68
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 66

def input_id
  "c4bb_#{.reformatted_version}_#{profile_identifier}__id_search_test_param"
end

#input_titleObject



70
71
72
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 70

def input_title
  "#{resource_type} search parameter for _id"
end

#module_nameObject



58
59
60
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 58

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

#outputObject



30
31
32
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 30

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

#output_file_directoryObject



34
35
36
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 34

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



38
39
40
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 38

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#profile_identifierObject



42
43
44
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 42

def profile_identifier
  Naming.snake_case_for_profile()
end

#remove_colonObject



103
104
105
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 103

def remove_colon
  removed_hyphen.gsub(':', '_')
end

#remove_starObject



107
108
109
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 107

def remove_star
  remove_colon.gsub('*', 'All')
end

#removed_hyphenObject



99
100
101
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 99

def removed_hyphen
  search_param.gsub('-', '')
end

#resource_typeObject



111
112
113
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 111

def resource_type
  .resource
end

#templateObject



26
27
28
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 26

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

#test_idObject



54
55
56
# File 'lib/carin_for_blue_button_test_kit/generator/include_search_test_generator.rb', line 54

def test_id
  "c4bb_#{.reformatted_version}_#{profile_identifier}_include_#{remove_star}_search_test"
end