Module: Inferno::DSL::FHIRResourceValidation::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#fhir_resource_validator(name = :default, required_suite_options: nil) ⇒ Object

Define a validator

Examples:

fhir_resource_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



692
693
694
695
696
697
698
699
700
701
# File 'lib/inferno/dsl/fhir_resource_validation.rb', line 692

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

  new_validator = Inferno::DSL::FHIRResourceValidation::Validator.new(name, id, required_suite_options, &)

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

  fhir_validators[name] = current_validators
end

#fhir_validatorsObject



670
671
672
# File 'lib/inferno/dsl/fhir_resource_validation.rb', line 670

def fhir_validators
  @fhir_validators ||= {}
end

#find_ig_and_profile(profile_url, validator_name) ⇒ Array

Find a particular profile StructureDefinition and the IG it belongs to. Looks through validators to find the profile by looking through their defined igs.

Note: Requires find_validator method which is defined elsewhere in the codebase

Parameters:

  • profile_url (String)

    the profile URL to find

  • validator_name (Symbol)

    the name of the validator to search

Returns:

  • (Array)

    the IG and profile



711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/inferno/dsl/fhir_resource_validation.rb', line 711

def find_ig_and_profile(profile_url, validator_name)
  validator = find_validator(validator_name)
  if validator.is_a? Inferno::DSL::FHIRResourceValidation::Validator
    validator.igs.each do |ig_id|
      ig = Inferno::Repositories::IGs.new.find_or_load(ig_id)
      profile = ig.profile_by_url(profile_url)
      return ig, profile if profile
    end
  end

  raise "Unable to find profile #{profile_url} in any IG defined for validator #{validator_name}"
end