Module: ONCCertificationG10TestKit::BulkExportValidationTester
Constant Summary
collapse
- MAX_NUM_COLLECTED_LINES =
100
- MIN_RESOURCE_COUNT =
2
- PROFILES_TO_SKIP =
[
'http://hl7.org/fhir/us/core/StructureDefinition/us-core-simple-observation'
].freeze
AllResources::ALL_RESOURCES, AllResources::V5_ALL_RESOURCES, AllResources::V6_ALL_RESOURCES, AllResources::V7_ALL_RESOURCES
Constants included
from G10Options
G10Options::BULK_DATA_1, G10Options::BULK_DATA_1_REQUIREMENT, G10Options::BULK_DATA_2, G10Options::BULK_DATA_2_REQUIREMENT, G10Options::SMART_1, G10Options::SMART_1_REQUIREMENT, G10Options::SMART_2, G10Options::SMART_2_2, G10Options::SMART_2_2_REQUIREMENT, G10Options::SMART_2_REQUIREMENT, G10Options::US_CORE_3, G10Options::US_CORE_3_REQUIREMENT, G10Options::US_CORE_4, G10Options::US_CORE_4_REQUIREMENT, G10Options::US_CORE_5, G10Options::US_CORE_5_REQUIREMENT, G10Options::US_CORE_6, G10Options::US_CORE_6_REQUIREMENT, G10Options::US_CORE_7, G10Options::US_CORE_7_REQUIREMENT, G10Options::US_CORE_VERSION_NUMBERS
Instance Attribute Summary collapse
Instance Method Summary
collapse
#all_required_resources
Methods included from G10Options
#us_core_7_and_above?, #us_core_version, #using_us_core_3?, #using_us_core_4?, #using_us_core_5?, #using_us_core_6?, #using_us_core_7?, #versioned_us_core_module
#extract_profile, #location_use_base_fhir?, #observation_contains_code?, #resource_contains_category?, #select_profile
Instance Attribute Details
Returns the value of attribute metadata.
11
12
13
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 11
def metadata
@metadata
end
|
Instance Method Details
#bearer_token ⇒ Object
39
40
41
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 39
def bearer_token
bulk_smart_auth_info.access_token
end
|
43
44
45
46
47
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 43
def (use_token)
= { accept: 'application/fhir+ndjson' }
.merge!({ authorization: "Bearer #{bearer_token}" }) if use_token == 'true'
end
|
#check_file_request(url) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
179
180
181
182
183
184
185
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 132
def check_file_request(url) line_count = 0
resources = Hash.new { |h, k| h[k] = [] }
process_line = proc do |line|
next unless lines_to_validate.blank? ||
line_count < lines_to_validate.to_i ||
(resource_type == 'Patient' && patient_ids_seen.length < MIN_RESOURCE_COUNT)
line_count += 1
begin
resource = FHIR.from_contents(line)
rescue StandardError
skip "Server response at line \"#{line_count}\" is not a processable FHIR resource."
end
if resource.resourceType != resource_type
assert false, "Resource type \"#{resource.resourceType}\" at line \"#{line_count}\" does not match type " \
"defined in output \"#{resource_type}\""
end
profile_urls = determine_profile(resource)
profile_urls.each do |profile_url|
resources[profile_url] << resource
scratch[:patient_ids_seen] = patient_ids_seen | [resource.id] if resource_type == 'Patient'
profile_with_version = versioned_profile_url(profile_url)
unless resource_is_valid?(resource:, profile_url: profile_with_version)
if first_error.key?(:line_number)
@invalid_resource_count += 1
else
@invalid_resource_count = 1
first_error[:line_number] = line_count
first_error[:messages] = messages.dup
end
end
end
end
= proc { |response|
value = (response[:headers].find { || .name.downcase == 'content-type' })&.value
unless value&.start_with?('application/fhir+ndjson')
skip "Content type must have 'application/fhir+ndjson' but found '#{value}'"
end
}
stream_ndjson(url, (requires_access_token), process_line, )
resources_from_all_files.merge!(resources) do |_key, all_resources, file_resources|
all_resources | file_resources
end
line_count
end
|
#determine_profile(resource) ⇒ Object
99
100
101
102
103
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 99
def determine_profile(resource)
return [] if resource.resourceType == 'Device' && !predefined_device_type?(resource)
select_profile(resource)
end
|
#first_error ⇒ Object
31
32
33
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 31
def first_error
@first_error ||= {}
end
|
19
20
21
22
23
24
25
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 19
def metadata_list
@metadata_list ||=
versioned_us_core_module::USCoreTestSuite
.metadata
.select { |metadata| metadata.resource == resource_type }
.reject { |metadata| PROFILES_TO_SKIP.include? metadata.profile_url }
end
|
#patient_ids_seen ⇒ Object
35
36
37
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 35
def patient_ids_seen
scratch[:patient_ids_seen] ||= []
end
|
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
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 200
def perform_bulk_export_validation
skip_if status_output.blank?, 'Could not verify this functionality when Bulk Status Output is not provided'
skip_if (requires_access_token == 'true' && bearer_token.blank?),
'Could not verify this functionality when Bearer Token is required and not provided'
assert_valid_json(status_output)
file_list = JSON.parse(status_output).select { |file| file['type'] == resource_type }
if file_list.empty?
message = "No #{resource_type} resource file item returned by server."
omit_if (all_required_resources.exclude? resource_type), "#{message} #{resource_type} resources are optional."
skip message
end
@resources_from_all_files = {}
resource_count = 0
file_list.each do |file|
resource_count += check_file_request(file['url'])
end
process_validation_errors(resource_count)
validate_conformance(resources_from_all_files)
pass "Successfully validated #{resource_count} #{resource_type} resource(s)."
end
|
#predefined_device_type?(resource) ⇒ Boolean
rubocop:disable Metrics/CyclomaticComplexity
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 87
def predefined_device_type?(resource) return true if bulk_device_types_in_group.blank?
expected = Set.new(bulk_device_types_in_group.split(',').map(&:strip))
actual = resource&.type&.coding&.filter_map do |coding|
coding.code if coding.system.nil? || coding.system == 'http://snomed.info/sct'
end
expected.intersect?(actual)
end
|
#process_validation_errors(resource_count) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 187
def process_validation_errors(resource_count)
return if @invalid_resource_count.nil? || @invalid_resource_count.zero?
first_error_message = "The line number for the first failed resource is #{first_error[:line_number]}."
messages.clear
messages.concat(first_error[:messages])
assert false,
"#{@invalid_resource_count} / #{resource_count} #{resource_type} resources failed profile validation. " \
"#{first_error_message}"
end
|
#resources_from_all_files ⇒ Object
27
28
29
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 27
def resources_from_all_files
@resources_from_all_files ||= {}
end
|
#stream_ndjson(endpoint, headers, process_chunk_line, process_response) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 49
def stream_ndjson(endpoint, , process_chunk_line, process_response) hanging_chunk = ''
process_body = proc { |chunk|
hanging_chunk << chunk
chunk_by_lines = hanging_chunk.lines
hanging_chunk = chunk_by_lines.pop || ''
chunk_by_lines.each do |elem|
process_chunk_line.call(elem)
end
}
stream(process_body, endpoint, headers:)
max_redirect = 5
while [301, 302, 303, 307].include?(response[:status]) &&
request.('location')&.value.present? &&
max_redirect.positive?
max_redirect -= 1
redirect_url = request.('location')&.value
redirect_url = URI.parse(endpoint).merge(redirect_url).to_s unless redirect_url.start_with?('http')
= .except(:authorization)
stream(process_body, redirect_url, headers: )
end
process_chunk_line.call(hanging_chunk)
process_response.call(response)
end
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 105
def validate_conformance(resources)
metadata_list.each do |meta|
next if resource_type == 'Location' && !us_core_7_and_above?
skip_if resources[meta.profile_url].blank?,
"No #{resource_type} resources found that conform to profile: #{meta.profile_url}."
@metadata = meta
@missing_elements = nil
@missing_slices = nil
@missing_extensions = nil
begin
perform_must_support_test(resources[meta.profile_url])
rescue Inferno::Exceptions::PassException
next
rescue Inferno::Exceptions::SkipException => e
e.message.concat " for `#{meta.profile_url}`"
raise e
end
end
end
|
#versioned_profile_url(profile_url) ⇒ Object
126
127
128
129
130
|
# File 'lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb', line 126
def versioned_profile_url(profile_url)
profile_version = metadata_list.find { |metadata| metadata.profile_url == profile_url }&.profile_version
profile_version ? "#{profile_url}|#{profile_version}" : profile_url
end
|