Class: IpaTestKit::Generator::ProvenanceRevincludeSearchTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, search_metadata, base_output_dir) ⇒ ProvenanceRevincludeSearchTestGenerator

Returns a new instance of ProvenanceRevincludeSearchTestGenerator.



19
20
21
22
23
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 19

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

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



17
18
19
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 17

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



17
18
19
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 17

def 
  @group_metadata
end

#search_metadataObject

Returns the value of attribute search_metadata.



17
18
19
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 17

def 
  @search_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



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

def generate(, base_output_dir)
  .groups
    .reject { |group| SpecialCases.exclude_group? group }
    .select { |group| group.revincludes.include? 'Provenance:target' }
    .select { |group| group.searches.any? }
    .each { |group| new(group, group.searches.first, base_output_dir).generate }
end

Instance Method Details

#array_of_strings(array) ⇒ Object



158
159
160
161
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 158

def array_of_strings(array)
  quoted_strings = array.map { |element| "'#{element}'" }
  "[#{quoted_strings.join(', ')}]"
end

#base_output_file_nameObject



33
34
35
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 33

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

#class_nameObject



61
62
63
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 61

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

#first_search?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 83

def first_search?
  .searches.first == 
end

#fixed_value_search?Boolean

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 87

def fixed_value_search?
  [:names] != ['patient'] &&
    !.delayed? && resource_type != 'Patient'
end

#fixed_value_search_param_nameObject



92
93
94
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 92

def fixed_value_search_param_name
  ([:names] - [:patient]).first
end

#generateObject



177
178
179
180
181
182
183
184
185
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 177

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

#module_nameObject



65
66
67
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 65

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

#needs_patient_id?Boolean

Returns:

  • (Boolean)


101
102
103
104
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 101

def needs_patient_id?
  [:names].include?('patient') ||
    (resource_type == 'Patient' && [:names].include?('_id'))
end

#outputObject



29
30
31
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 29

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

#output_file_directoryObject



37
38
39
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 37

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



41
42
43
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 41

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#path_for_value(path) ⇒ Object



114
115
116
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 114

def path_for_value(path)
  path == 'class' ? 'local_class' : path
end

#profile_identifierObject



45
46
47
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 45

def profile_identifier
  Naming.snake_case_for_profile()
end

#required_comparatorsObject



122
123
124
125
126
127
128
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 122

def required_comparators
  @required_comparators ||=
    search_param_names.each_with_object({}) do |name, comparators|
      required_comparators = required_comparators_for_param(name)
      comparators[name] = required_comparators if required_comparators.present?
    end
end

#required_comparators_for_param(name) ⇒ Object



118
119
120
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 118

def required_comparators_for_param(name)
  search_definition(name)[:comparators].select { |_comparator, expectation| expectation == 'SHALL' }
end

#required_comparators_stringObject



154
155
156
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 154

def required_comparators_string
  array_of_strings(required_comparators.keys)
end

#resource_typeObject



69
70
71
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 69

def resource_type
  .resource
end

#saves_delayed_references?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 139

def saves_delayed_references?
  first_search? && .delayed_references.present?
end

#search_definition(name) ⇒ Object

def patient_id_param?(param)

param[:name] == 'patient' ||
  (resource_type == 'Patient' && param[:name] == '_id')

end



135
136
137
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 135

def search_definition(name)
  .search_definitions[name.to_sym]
end

#search_identifierObject



53
54
55
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 53

def search_identifier
  'provenance_revinclude'
end

#search_param_name_stringObject



96
97
98
99
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 96

def search_param_name_string
  binding.pry if .nil?
  [:names].join(' + ') + ' + revInclude:Provenance:target'
end

#search_param_namesObject



106
107
108
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 106

def search_param_names
  search_params.map { |param| param[:name] }
end

#search_param_names_arrayObject



110
111
112
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 110

def search_param_names_array
  array_of_strings(search_param_names)
end

#search_paramsObject



73
74
75
76
77
78
79
80
81
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 73

def search_params
  @search_params ||=
    [:names].map do |name|
      {
        name: name,
        path: search_definition(name)[:path]
      }
    end
end

#search_propertiesObject



163
164
165
166
167
168
169
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 163

def search_properties
  {}.tap do |properties|
    properties[:fixed_value_search] = 'true' if fixed_value_search?
    properties[:resource_type] = "'#{resource_type}'"
    properties[:search_param_names] = search_param_names_array
  end
end

#search_test_properties_stringObject



171
172
173
174
175
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 171

def search_test_properties_string
  search_properties
    .map { |key, value| "#{' ' * 8}#{key}: #{value}" }
    .join(",\n")
end

#search_titleObject



57
58
59
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 57

def search_title
  search_identifier.camelize
end

#templateObject



25
26
27
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 25

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

#test_idObject



49
50
51
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 49

def test_id
  "ipa_#{.reformatted_version}_#{profile_identifier}_#{search_identifier}_search_test"
end

#token_search_paramsObject



143
144
145
146
147
148
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 143

def token_search_params
  @token_search_params ||=
    search_param_names.select do |name|
      ['Identifier', 'CodeableConcept', 'Coding'].include? .search_definitions[name.to_sym][:type]
    end
end

#token_search_params_stringObject



150
151
152
# File 'lib/ipa_test_kit/generator/provenance_revinclude_search_test_generator.rb', line 150

def token_search_params_string
  array_of_strings(token_search_params)
end