Class: CarinForBlueButtonTestKit::Generator::SearchTestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/carin_for_blue_button_test_kit/generator/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) ⇒ SearchTestGenerator

Returns a new instance of SearchTestGenerator.



23
24
25
26
27
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 23

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.



21
22
23
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 21

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



21
22
23
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 21

def 
  @group_metadata
end

#search_metadataObject

Returns the value of attribute search_metadata.



21
22
23
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 21

def 
  @search_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 9

def generate(, base_output_dir)
  .groups
             .select { |group| group.searches.present? }
             .each do |group|
    group.searches.each { |search| new(group, search, base_output_dir).generate }
    group.include_params.each do |param|
      IncludeSearchTestGenerator.new(group, param, base_output_dir).generate
    end
  end
end

Instance Method Details

#all_search_paramsObject



93
94
95
96
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 93

def all_search_params
  .searches.map { |param| param[:names] }
                .flatten
end

#array_of_strings(array) ⇒ Object



195
196
197
198
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 195

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

#base_output_file_nameObject



37
38
39
40
41
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 37

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

#class_nameObject



67
68
69
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 67

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

#conformance_expectationObject



79
80
81
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 79

def conformance_expectation
  [:expectation]
end

#descriptionObject



287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 287

def description
  <<~DESCRIPTION.gsub(/\n{3,}/, "\n\n")
    A server #{conformance_expectation} support searching by
    #{search_param_name_string} on the #{resource_type} resource. This test
    will pass if resources are returned and match the search criteria. If
    none are returned, the test is skipped.

    #{reference_search_description}
    #{first_search_description}
    #{post_search_description}

  DESCRIPTION
end

#first_search?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 98

def first_search?
  # Mark patient the first search for EOB
  if all_search_params.include?('patient')
    search_param_name_string == 'patient'
  else
    .searches.first == 
  end
end

#first_search_descriptionObject



267
268
269
270
271
272
273
274
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 267

def first_search_description
  return '' unless first_search?

  <<~FIRST_SEARCH_DESCRIPTION
    Because this is the first search of the sequence, resources in the
    response will be used for subsequent tests.
  FIRST_SEARCH_DESCRIPTION
end

#fixed_value_search?Boolean

Returns:

  • (Boolean)


107
108
109
110
111
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 107

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

#fixed_value_search_param_nameObject



113
114
115
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 113

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

#generateObject



247
248
249
250
251
252
253
254
255
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 247

def generate
  FileUtils.mkdir_p(output_file_directory)
  File.write(output_file_name, output)

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

#input_descriptionObject



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 317

def input_description
  desc_content = if needs_patient_id?
                   "
                    Comma separated list of patient IDs that in sum
                    contain all MUST SUPPORT elements
                    "
                 else
                   "
                    This input is optional. If running all tests, the search will look for
                    its parameter values from the results returned in the EOB tests. If no
                    #{resource_type} resource was returned in previous EOB tests and this
                    input is not provided, the search is skipped.

                    When running just the #{resource_type} Test group, this input is
                    required to perform the search, otherwise the search is skipped.
                    "
                 end

  <<~INPUT_DESCRIPTION
    #{desc_content}
  INPUT_DESCRIPTION
end

#input_idObject



301
302
303
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 301

def input_id
  needs_patient_id? ? 'patient_ids' : "#{test_id}_param"
end

#input_titleObject



305
306
307
308
309
310
311
312
313
314
315
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 305

def input_title
  title_content = if needs_patient_id?
                    'Patient IDs'
                  else
                    "#{resource_type} search parameter for #{search_param_name_string}"
                  end

  <<~INPUT_TITLE
    #{title_content.strip}
  INPUT_TITLE
end

#module_nameObject



71
72
73
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 71

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

#needs_patient_id?Boolean

Returns:

  • (Boolean)


121
122
123
124
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 121

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

#optional?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 152

def optional?
  conformance_expectation != 'SHALL' || ![:must_support_or_mandatory]
end

#outputObject



33
34
35
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 33

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

#output_file_directoryObject



43
44
45
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 43

def output_file_directory
  File.join(base_output_dir, profile_identifier)
end

#output_file_nameObject



47
48
49
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 47

def output_file_name
  File.join(output_file_directory, base_output_file_name)
end

#path_for_value(path) ⇒ Object



134
135
136
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 134

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

#possible_status_search?Boolean

Returns:

  • (Boolean)


164
165
166
167
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 164

def possible_status_search?
  [:names].none? { |name| name.include? 'status' } &&
    .search_definitions.keys.any? { |key| key.to_s.include? 'status' }
end

#post_search_descriptionObject



276
277
278
279
280
281
282
283
284
285
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 276

def post_search_description
  return '' unless test_post_search?

  <<~POST_SEARCH_DESCRIPTION
    Additionally, this test will check that GET and POST search methods
    return the same number of results. Search by POST is required by the
    FHIR R4 specification, and these tests interpret search by GET as a
    requirement of CARIN IG for Blue ButtonĀ® #{.version}.
  POST_SEARCH_DESCRIPTION
end

#profile_identifierObject



51
52
53
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 51

def profile_identifier
  Naming.snake_case_for_profile()
end

#reference_search_descriptionObject



257
258
259
260
261
262
263
264
265
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 257

def reference_search_description
  return '' unless test_reference_variants?

  <<~REFERENCE_SEARCH_DESCRIPTION
    This test verifies that the server supports searching by reference using
    the form `patient=[id]` as well as `patient=Patient/[id]`. The two
    different forms are expected to return the same number of results. CARIN requires that both forms are supported by CARIN for Blue Button responders.
  REFERENCE_SEARCH_DESCRIPTION
end

#required_comparatorsObject



144
145
146
147
148
149
150
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 144

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



138
139
140
141
142
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 138

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

#required_comparators_stringObject



191
192
193
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 191

def required_comparators_string
  array_of_strings(required_comparators.keys)
end

#required_multiple_or_search_paramsObject



180
181
182
183
184
185
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 180

def required_multiple_or_search_params
  @required_multiple_or_search_params ||=
    search_param_names.select do |name|
      search_definition(name)[:multiple_or] == 'SHALL'
    end
end

#required_multiple_or_search_params_stringObject



187
188
189
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 187

def required_multiple_or_search_params_string
  array_of_strings(required_multiple_or_search_params)
end

#resource_typeObject



75
76
77
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 75

def resource_type
  .resource
end

#saves_delayed_references?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 160

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

#search_definition(name) ⇒ Object



156
157
158
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 156

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

#search_identifierObject



59
60
61
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 59

def search_identifier
  [:names].join('_').tr('-', '_')
end

#search_param_name_stringObject



117
118
119
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 117

def search_param_name_string
  [:names].join(' + ')
end

#search_param_namesObject



126
127
128
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 126

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

#search_param_names_arrayObject



130
131
132
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 130

def search_param_names_array
  array_of_strings(search_param_names)
end

#search_paramsObject



83
84
85
86
87
88
89
90
91
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 83

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

#search_propertiesObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 212

def search_properties
  {}.tap do |properties|
    properties[:first_search] = 'true' if first_search?
    properties[:fixed_value_search] = 'true' if fixed_value_search?
    properties[:resource_type] = "'#{resource_type}'"
    properties[:search_param_names] = search_param_names_array
    properties[:saves_delayed_references] = 'true' if saves_delayed_references?
    properties[:possible_status_search] = 'true' if possible_status_search?
    properties[:test_medication_inclusion] = 'true' if test_medication_inclusion?
    properties[:token_search_params] = token_search_params_string if token_search_params.present?
    properties[:test_reference_variants] = 'true' if test_reference_variants?
    properties[:params_with_comparators] = required_comparators_string if required_comparators.present?
    if required_multiple_or_search_params.present?
      properties[:multiple_or_search_params] =
        required_multiple_or_search_params_string
    end
    properties[:test_post_search] = 'true' if first_search?
  end
end

#search_test_properties_stringObject



241
242
243
244
245
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 241

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

#search_titleObject



63
64
65
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 63

def search_title
  search_identifier.camelize
end

#templateObject



29
30
31
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 29

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

#test_idObject



55
56
57
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 55

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

#test_medication_inclusion?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 204

def test_medication_inclusion?
  resource_type == 'MedicationRequest'
end

#test_post_search?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 208

def test_post_search?
  first_search?
end

#test_reference_variants?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 200

def test_reference_variants?
  first_search? && search_param_names.include?('patient')
end

#token_search_paramsObject



169
170
171
172
173
174
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 169

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

#token_search_params_stringObject



176
177
178
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 176

def token_search_params_string
  array_of_strings(token_search_params)
end

#url_versionObject



232
233
234
235
236
237
238
239
# File 'lib/carin_for_blue_button_test_kit/generator/search_test_generator.rb', line 232

def url_version
  case .version
  when 'v3.1.1'
    'STU3.1.1'
  when 'v4.0.0'
    'STU4'
  end
end