Class: CarinForBlueButtonTestKit::Generator::GroupGenerator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_metadata, base_output_dir) ⇒ GroupGenerator

Returns a new instance of GroupGenerator.



18
19
20
21
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 18

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

Instance Attribute Details

#base_output_dirObject

Returns the value of attribute base_output_dir.



16
17
18
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 16

def base_output_dir
  @base_output_dir
end

#group_metadataObject

Returns the value of attribute group_metadata.



16
17
18
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 16

def 
  @group_metadata
end

Class Method Details

.generate(ig_metadata, base_output_dir) ⇒ Object



9
10
11
12
13
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 9

def generate(, base_output_dir)
  @@eob_subgroups = .eob_subgroups
  .ordered_groups
             .each { |group| new(group, base_output_dir).generate }
end

Instance Method Details

#base_metadata_file_nameObject



35
36
37
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 35

def 
  'metadata.yml'
end

#base_output_file_nameObject



31
32
33
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 31

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

#class_nameObject



39
40
41
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 39

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

#descriptionObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 193

def description
  <<~DESCRIPTION
    # Background

    The CARIN for Blue Button #{title} sequence verifies that the system under test is
    able to provide correct responses for #{resource_type} queries. These queries
    must contain resources conforming to the #{profile_name} as
    specified in the CARIN for Blue Button #{.version} Implementation Guide.

    # Testing Methodology
    #{search_description}

    ## Must Support
    Each profile contains elements marked as "must support". This test
    sequence expects to see each of these elements at least once. If at
    least one cannot be found, the test will fail. The test will look
    through the #{resource_type} resources found in the first test for these
    elements.

    ## Profile Validation
    Each resource returned from the first search is expected to conform to
    the [#{profile_name}](#{profile_url}). Each element is checked against
    terminology binding and cardinality requirements.

    Elements with a required binding are validated against their bound
    ValueSet. If the code/system in the element is not part of the ValueSet,
    then the test will fail.

    ## Reference Validation
    At least one instance of each external reference in elements marked as
    "must support" within the resources provided by the system must resolve.
    The test will attempt to read each reference found and will fail if no
    read succeeds.
  DESCRIPTION
end

#eob_subgroups_test_file_listObject



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 135

def eob_subgroups_test_file_list
  test_file_list = []
  @@eob_subgroups.each do |group|
    list = group.tests.map do |test|
      name_without_suffix = test[:file_name].delete_suffix('.rb')
      name_without_suffix.start_with?('..') ? name_without_suffix : "#{Naming.snake_case_for_profile(group)}/#{name_without_suffix}"
    end
    test_file_list.concat(list)
  end
  test_file_list.reject { |test_name| test_name.include?('search_test') }
                .reject { |test_name| test_name.include?('read_test') }
end

#eob_subgroups_test_id_listObject



111
112
113
114
115
116
117
118
119
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 111

def eob_subgroups_test_id_list
  test_id_list = []
  @@eob_subgroups.each do |group|
    test_id_list.concat(group.tests.map { |test| test[:id] })
  end

  test_id_list.reject { |test_name| test_name.include?('search_test') }
              .reject { |test_name| test_name.include?('read_test') }
end

#generateObject



91
92
93
94
95
96
97
98
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 91

def generate
  if !is_eob_subgroup?
    File.open(output_file_name, 'w') { |f| f.write(output) }
    .id = group_id
    .file_name = base_output_file_name
    File.open(, 'w') { |f| f.write(YAML.dump(.to_hash)) }
  end
end

#group_idObject



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

def group_id
  "c4bb_#{.reformatted_version}_#{profile_identifier}"
end

#is_eob_root_group?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 233

def is_eob_root_group?
  resource_type == 'ExplanationOfBenefit' && !is_eob_subgroup?
end

#is_eob_subgroup?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 229

def is_eob_subgroup?
  base_output_file_name.match(/eob_.+_group/)
end

#metadata_file_nameObject



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

def 
  File.join(base_output_dir, profile_identifier, )
end

#module_nameObject



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

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

#optional?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 87

def optional?
  .conformance_expectation != 'SHALL'
end

#outputObject



27
28
29
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 27

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

#output_file_nameObject



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

def output_file_name
  File.join(base_output_dir, base_output_file_name)
end

#profile_identifierObject



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

def profile_identifier
  Naming.snake_case_for_profile()
end

#profile_nameObject



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

def profile_name
  .profile_name
end

#profile_urlObject



83
84
85
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 83

def profile_url
  .profile_url
end

#required_searchesObject



148
149
150
151
152
153
154
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 148

def required_searches
  if !.searches.nil? && !is_eob_subgroup?
    .searches.select { |search| search[:expectation] == 'SHALL' }
  else
    []
  end
end

#resource_typeObject



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

def resource_type
  .resource
end

#search_descriptionObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 163

def search_description
  return '' if required_searches.blank?

  <<~SEARCH_DESCRIPTION
    ## Searching
    This test sequence will first perform each required search associated
    with this resource. This sequence will perform searches with the
    following parameters:

    #{search_param_name_string}

    ### Search Parameters
    The first search uses the selected patient(s) from the prior launch
    sequence. Any subsequent searches will look for its parameter values
    from the results of the first search. For example, the `identifier`
    search in the patient sequence is performed by looking for an existing
    `Patient.identifier` from any of the resources returned in the `_id`
    search. If a value cannot be found this way, the search is skipped.

    ### Search Validation
    Inferno will retrieve up to the first 20 bundle pages of the reply for
    #{search_validation_resource_type} and save them for subsequent tests.
    Each resource is then checked to see if it matches the searched
    parameters in accordance with [FHIR search
    guidelines](https://www.hl7.org/fhir/search.html). The test will fail,
    for example, if a Patient search for `gender=male` returns a `female`
    patient.
  SEARCH_DESCRIPTION
end

#search_param_name_stringObject



156
157
158
159
160
161
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 156

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

#search_validation_resource_typeObject



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

def search_validation_resource_type
  "#{resource_type} resources"
end

#short_descriptionObject



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

def short_description
  .short_description
end

#templateObject



23
24
25
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 23

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

#test_file_listObject



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 121

def test_file_list
  @test_file_list ||=
    .tests.map do |test|
      name_without_suffix = test[:file_name].delete_suffix('.rb')
      name_without_suffix.start_with?('..') ? name_without_suffix : "#{profile_identifier}/#{name_without_suffix}"
    end

  # Remove calls to search tests for EOB subgroups (all subgroup search tests handled in EOB root tests)
  @test_file_list = @test_file_list.reject { |test_name| test_name.include?('search_test') } if is_eob_subgroup?

  @test_file_list = @test_file_list.concat(eob_subgroups_test_file_list) if is_eob_root_group?
  @test_file_list
end

#test_id_listObject



100
101
102
103
104
105
106
107
108
109
# File 'lib/carin_for_blue_button_test_kit/generator/group_generator.rb', line 100

def test_id_list
  @test_id_list ||=
    .tests.map { |test| test[:id] }

  # Remove calls to search tests for EOB subgroups and merge EOB subgroup tests with the EOB root tests
  @test_id_list = @test_id_list.reject { |test_name| test_name.include?('search_test') } if is_eob_subgroup?

  @test_id_list.concat(eob_subgroups_test_id_list) if is_eob_root_group?
  @test_id_list
end

#titleObject



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

def title
  .title
end