Class: ONCCertificationG10TestKit::G10CertificationSuite

Inherits:
Inferno::TestSuite
  • Object
show all
Defined in:
lib/onc_certification_g10_test_kit.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 http://tx.fhir.org/r4:} # Catch-all for TX server errors that slip through
].freeze

Class Method Summary collapse

Class Method Details

.jwks_jsonObject



193
194
195
196
197
198
199
200
201
202
# File 'lib/onc_certification_g10_test_kit.rb', line 193

def self.jwks_json
  bulk_data_jwks = JSON.parse(File.read(
                                ENV.fetch('G10_BULK_DATA_JWKS',
                                          File.join(__dir__, 'onc_certification_g10_test_kit',
                                                    '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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
# File 'lib/onc_certification_g10_test_kit.rb', line 91

def self.setup_validator(us_core_version_requirement) # rubocop:disable Metrics/CyclomaticComplexity
  validator_method = if Feature.use_hl7_resource_validator?
                       method(:fhir_resource_validator)
                     else
                       method(:validator)
                     end

  validator_method.call :default, required_suite_options: us_core_version_requirement do
    if Feature.use_hl7_resource_validator?
      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}")
    else
      url ENV.fetch('G10_VALIDATOR_URL', 'http://validator_service:4567')
    end

    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



204
205
206
# File 'lib/onc_certification_g10_test_kit.rb', line 204

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