Class: ONCCertificationG10TestKit::G10CertificationSuite

Inherits:
Inferno::TestSuite
  • Object
show all
Defined in:
lib/onc_certification_g10_test_kit/g10_certification_suite.rb

Constant Summary collapse

WARNING_INCLUSION_FILTERS =
[
  /Unknown CodeSystem/,
  /Unknown ValueSet/
].freeze
ERROR_FILTERS =
[
  /\A\S+: \S+: Unknown [Cc]ode/,
  /\A\S+: \S+: None of the codings provided are in the value set/,
  /\A\S+: \S+: The code provided \(\S*\) is not in the value set/,
  /\A\S+: \S+: The Coding provided \(\S*\) is not in the value set/,
  /\A\S+: \S+: The Coding provided \(\S*\) was not found in the value set/,
  /\A\S+: \S+: A definition for CodeSystem '.*' could not be found, so the code cannot be validated/,
  /\A\S+: \S+: URL value '.*' does not resolve/,
  /\A\S+: \S+: .*\[No server available\]/, # Catch-all for certain errors when TX server is disabled
  %r{\A\S+: \S+: .*\[Error from https?://tx.fhir.org/r4:}, # Catch-all for TX server errors that slip through
  # This is a strange error introduced by FHIR validator core 6.5.28.
  %r{\A\S+: \S+: The System URI could not be determined for the code '.*' in the ValueSet 'http://hl7.org/fhir/ValueSet/mimetypes|4.0.1'}
].freeze

Class Method Summary collapse

Class Method Details

.jwks_jsonObject



241
242
243
244
245
246
247
248
249
# File 'lib/onc_certification_g10_test_kit/g10_certification_suite.rb', line 241

def self.jwks_json
  bulk_data_jwks =
    JSON.parse(
      File.read(ENV.fetch('G10_BULK_DATA_JWKS', File.join(__dir__, 'bulk_data_jwks.json')))
    )
  @jwks_json ||= JSON.pretty_generate(
    { keys: bulk_data_jwks['keys'].select { |key| key['key_ops']&.include?('verify') } }
  )
end

.setup_validator(us_core_version_requirement) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/onc_certification_g10_test_kit/g10_certification_suite.rb', line 149

def self.setup_validator(us_core_version_requirement) # rubocop:disable Metrics/CyclomaticComplexity
  fhir_resource_validator :default, required_suite_options: us_core_version_requirement do
    cli_context do
      txServer nil
      displayWarnings true
      disableDefaultResourceFetcher true
    end

    us_core_version_num = G10Options::US_CORE_VERSION_NUMBERS[us_core_version_requirement[:us_core_version]]

    igs("hl7.fhir.us.core##{us_core_version_num}")

    us_core_message_filters =
      case us_core_version_requirement[:us_core_version]
      when G10Options::US_CORE_3
        USCoreTestKit::USCoreV311::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
      when G10Options::US_CORE_4
        USCoreTestKit::USCoreV400::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
      when G10Options::US_CORE_5
        USCoreTestKit::USCoreV501::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
      when G10Options::US_CORE_6
        USCoreTestKit::USCoreV610::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
      when G10Options::US_CORE_7
        USCoreTestKit::USCoreV700::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
      end

    exclude_message do |message|
      if message.type == 'info' ||
         (message.type == 'warning' && WARNING_INCLUSION_FILTERS.none? do |filter|
            filter.match? message.message
          end) ||
         us_core_message_filters.any? { |filter| filter.match? message.message } ||
         (message.type == 'error' && ERROR_FILTERS.any? { |filter| message.message.match? filter })
        true
      else
        false
      end
    end

    perform_additional_validation do |resource, profile_url|
      versionless_profile_url, profile_version = profile_url.split('|')
      profile_version = case profile_version
                        when '6.1.0'
                          '610'
                        when '4.0.0'
                          '400'
                        when '5.0.1'
                          '501'
                        else
                          # This open-ended else is primarily for Vital Signs profiles in v3.1.1, which are tagged
                          # with the base FHIR version (4.0.1).  The profiles were migrated to US Core in later
                          # versions.
                          '311'
                        end

      us_core_suite = USCoreTestKit.const_get("USCoreV#{profile_version}")::USCoreTestSuite
       = us_core_suite..find do ||
        .profile_url == versionless_profile_url
      end
      next if .nil?

      validation_messages = if resource.instance_of?(FHIR::Provenance)
                              USCoreTestKit::ProvenanceValidator.validate(resource)
                            else
                              []
                            end

      terminology_validation_messages = .bindings
        .select { |binding_definition| binding_definition[:strength] == 'required' }
        .flat_map do |binding_definition|
          TerminologyBindingValidator.validate(resource, binding_definition)
      rescue Inferno::UnknownValueSetException, Inferno::UnknownCodeSystemException => e
        { type: 'warning', message: e.message }
        end.compact

      validation_messages.concat(terminology_validation_messages)
      validation_messages
    end
  end
end

.well_known_route_handlerObject



251
252
253
# File 'lib/onc_certification_g10_test_kit/g10_certification_suite.rb', line 251

def self.well_known_route_handler
  ->(_env) { [200, { 'Content-Type' => 'application/json' }, [jwks_json]] }
end