Class: USCoreTestKit::Generator::GroupGenerator
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::GroupGenerator
show all
- Defined in:
- lib/us_core_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.
17
18
19
20
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 17
def initialize(group_metadata, base_output_dir)
self.group_metadata = group_metadata
self.base_output_dir = base_output_dir
end
|
Instance Attribute Details
#base_output_dir ⇒ Object
Returns the value of attribute base_output_dir.
15
16
17
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 15
def base_output_dir
@base_output_dir
end
|
Returns the value of attribute group_metadata.
15
16
17
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 15
def group_metadata
@group_metadata
end
|
Class Method Details
.generate(ig_metadata, base_output_dir) ⇒ Object
8
9
10
11
12
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 8
def generate(ig_metadata, base_output_dir)
ig_metadata.ordered_groups
.reject { |group| SpecialCases.exclude_group? group }
.each { |group| new(group, base_output_dir).generate }
end
|
Instance Method Details
#add_special_tests ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 108
def add_special_tests
return if group_metadata.reformatted_version == 'v311'
return unless group_metadata.resource == 'DocumentReference'
if group_metadata.profile_url.end_with?('us-core-adi-documentreference')
group_metadata.add_test(
id: 'us_core_v800_adi_document_reference_custodian_test',
file_name: '../../custom_groups/v8.0.0/adi_document_reference_custodian_test.rb'
)
else
group_metadata.add_test(
id: 'us_core_v400_document_reference_custodian_test',
file_name: '../../custom_groups/v4.0.0/document_reference_custodian_test.rb'
)
end
end
|
34
35
36
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 34
def base_metadata_file_name
'metadata.yml'
end
|
#base_output_file_name ⇒ Object
30
31
32
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 30
def base_output_file_name
"#{class_name.underscore}.rb"
end
|
#description ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 180
def description
<<~DESCRIPTION
# Background
The US Core #{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 US Core #{group_metadata.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
teminology 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
|
#generate ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 100
def generate
add_special_tests
File.write(output_file_name, output)
group_metadata.id = group_id
group_metadata.file_name = base_output_file_name
File.write(metadata_file_name, YAML.dump(group_metadata.to_hash))
end
|
#group_id ⇒ Object
66
67
68
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 66
def group_id
"us_core_#{group_metadata.reformatted_version}_#{profile_identifier}"
end
|
58
59
60
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 58
def metadata_file_name
File.join(base_output_dir, profile_identifier, base_metadata_file_name)
end
|
#module_name ⇒ Object
42
43
44
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 42
def module_name
"USCore#{group_metadata.reformatted_version.upcase}"
end
|
#optional? ⇒ Boolean
96
97
98
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 96
def optional?
SpecialCases::OPTIONAL_RESOURCES.include?(resource_type) || group_metadata.optional_profile?
end
|
#output ⇒ Object
26
27
28
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 26
def output
@output ||= ERB.new(template, trim_mode: '-').result(binding)
end
|
#output_file_name ⇒ Object
54
55
56
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 54
def output_file_name
File.join(base_output_dir, base_output_file_name)
end
|
#profile_identifier ⇒ Object
62
63
64
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 62
def profile_identifier
Naming.snake_case_for_profile(group_metadata)
end
|
#profile_name ⇒ Object
88
89
90
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 88
def profile_name
group_metadata.profile_name
end
|
#profile_url ⇒ Object
92
93
94
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 92
def profile_url
group_metadata.profile_url
end
|
#required_searches ⇒ Object
139
140
141
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 139
def required_searches
group_metadata.searches.select { |search| search[:expectation] == 'SHALL' }
end
|
#resource_type ⇒ Object
70
71
72
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 70
def resource_type
group_metadata.resource
end
|
#search_description ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 150
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 of
these resources 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_string ⇒ Object
143
144
145
146
147
148
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 143
def search_param_name_string
required_searches
.map { |search| search[:names].join(' + ') }
.map { |names| "* #{names}" }
.join("\n")
end
|
#search_validation_resource_type ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 74
def search_validation_resource_type
text = "#{resource_type} resources"
if resource_type == 'Condition' && group_metadata.reformatted_version == 'v501'
case profile_url
when 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition-encounter-diagnosis'
text.concat(' with category `encounter-diagnosis`')
when 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition-problems-health-concerns'
text.concat(' with category `problem-list-item | health-concern`')
end
end
text
end
|
#short_description ⇒ Object
50
51
52
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 50
def short_description
group_metadata.short_description
end
|
#template ⇒ Object
22
23
24
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 22
def template
@template ||= File.read(File.join(__dir__, 'templates', 'group.rb.erb'))
end
|
#test_file_list ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 131
def test_file_list
@test_file_list ||=
group_metadata.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
end
|
#test_id_list ⇒ Object
126
127
128
129
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 126
def test_id_list
@test_id_list ||=
group_metadata.tests.map { |test| test[:id] }
end
|
#title ⇒ Object
46
47
48
|
# File 'lib/us_core_test_kit/generator/group_generator.rb', line 46
def title
group_metadata.title
end
|