Module: Inferno::Terminology::TerminologyValidation

Included in:
Inferno::Terminology::Tasks::ValidateCode, ONCCertificationG10TestKit::TerminologyBindingValidator
Defined in:
lib/inferno/terminology/terminology_validation.rb

Constant Summary collapse

PREPROCESS_FUNCS =

CodeSystems/ValueSets to “preprocess” prior to validation, and the function to use

{
  'urn:ietf:bcp:13' => BCP13.method(:preprocess_code),
  'http://hl7.org/fhir/ValueSet/mimetypes' => BCP13.method(:preprocess_code)
}.freeze

Instance Method Summary collapse

Instance Method Details

#validate_code(code:, value_set_url: nil, system: nil) ⇒ Object

This function accepts a valueset URL, code, and optional system, and returns true if the code or code/system combination is valid for the valueset represented by that URL

Parameters:

  • String

    value_set_url the URL for the valueset to validate against

  • String

    code the code to validate against the valueset

  • String

    system an optional codesystem to validate against.

Returns:

  • Boolean whether the code or code/system is in the valueset



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/inferno/terminology/terminology_validation.rb', line 26

def validate_code(code:, value_set_url: nil, system: nil)
  # Before we validate the code, see if there's any preprocessing steps we have to do
  # To get the code "ready" for validation
  code = PREPROCESS_FUNCS[system].call(code) if PREPROCESS_FUNCS[system]
  code = PREPROCESS_FUNCS[value_set_url].call(code) if PREPROCESS_FUNCS[value_set_url]

  # Get the valueset from the url. Redundant if the 'system' is not nil,
  # but allows us to throw a better error if the valueset isn't known by Inferno
  validator =
    if value_set_url
      validators_repo.find(value_set_url) || raise(UnknownValueSetException, value_set_url)
    else
      validators_repo.find(system) || raise(UnknownCodeSystemException, system)
    end

  validator.validate(code:, system:)
end

#validators_repoObject



14
15
16
# File 'lib/inferno/terminology/terminology_validation.rb', line 14

def validators_repo
  @validators_repo ||= Repositories::Validators.new
end