Module: Inferno::DSL::FHIRValidation::ClassMethods

Defined in:
lib/inferno/dsl/fhir_validation.rb

Instance Method Summary collapse

Instance Method Details

#find_validator(validator_name, selected_suite_options = nil) ⇒ Object

Find a particular validator. Looks through a runnable’s parents up to the suite to find a validator with a particular name



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/inferno/dsl/fhir_validation.rb', line 219

def find_validator(validator_name, selected_suite_options = nil)
  validators = fhir_validators[validator_name] ||
               Array.wrap(parent&.find_validator(validator_name, selected_suite_options))

  validator =
    if selected_suite_options.present?
      validators.find do |possible_validator|
        possible_validator.requirements.nil? || selected_suite_options >= possible_validator.requirements
      end
    else
      validators.first
    end

  raise Exceptions::ValidatorNotFoundException, validator_name if validator.nil?

  validator
end

#validator(name = :default, required_suite_options: nil, &block) ⇒ Object

Define a validator

Examples:

validator do
  url 'http://example.com/validator'
  exclude_message { |message| message.type == 'info' }
  perform_additional_validation do |resource, profile_url|
    if something_is_wrong
      { type: 'error', message: 'something is wrong' }
    else
      { type: 'info', message: 'everything is ok' }
    end
  end
end

Parameters:

  • name (Symbol) (defaults to: :default)

    the name of the validator, only needed if you are using multiple validators

  • required_suite_options (Hash) (defaults to: nil)

    suite options that must be selected in order to use this validator



206
207
208
209
210
211
212
213
214
215
# File 'lib/inferno/dsl/fhir_validation.rb', line 206

def validator(name = :default, required_suite_options: nil, &block)
  current_validators = fhir_validators[name] || []

  new_validator = Inferno::DSL::FHIRValidation::Validator.new(required_suite_options, &block)

  current_validators.reject! { |validator| validator.requirements == required_suite_options }
  current_validators << new_validator

  fhir_validators[name] = current_validators
end