Sha256: 91394e1f88f36293d3ec3dcb86c0bd25531acba9bea26358c98dee7c842a2759

Contents?: true

Size: 1.78 KB

Versions: 23

Compression:

Stored size: 1.78 KB

Contents

require_relative 'terminology_configuration'

module Inferno
  module Terminology
    class Validator
      attr_reader :url, :concept_count, :type, :code_systems, :file_name, :bloom_filter

      def initialize(metadata)
        @url = metadata[:url]
        @concept_count = metadata[:count]
        @type = metadata[:type]
        @code_systems = metadata[:code_systems]
        @file_name = metadata[:file]
        @bloom_filter = metadata[:bloom_filter]
      end

      def validate(code:, system: nil)
        if system
          raise ProhibitedSystemException, system if TerminologyConfiguration.system_prohibited?(system)

          coding_in_filter?(code:, system:)
        elsif contains_prohibited_systems?
          raise ProhibitedSystemException, prohibited_systems.join(', ') unless code_in_allowed_system?(code)

          true
        else
          code_in_any_system?(code)
        end
      end

      def contains_prohibited_systems?
        prohibited_systems.present?
      end

      def prohibited_systems
        @prohibited_systems ||=
          code_systems.select { |system| TerminologyConfiguration.system_prohibited?(system) }
      end

      def allowed_systems
        @allowed_systems ||=
          code_systems.select { |system| TerminologyConfiguration.system_allowed?(system) }
      end

      def code_in_allowed_system?(code)
        code_in_systems?(code, allowed_systems)
      end

      def code_in_any_system?(code)
        code_in_systems?(code, code_systems)
      end

      def code_in_systems?(code, possible_systems)
        possible_systems.any? do |possible_system|
          coding_in_filter?(code:, system: possible_system)
        end
      end

      def coding_in_filter?(code:, system:)
        bloom_filter.include? "#{system}|#{code}"
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
onc_certification_g10_test_kit-3.3.2 lib/inferno/terminology/validator.rb
onc_certification_g10_test_kit-3.3.1 lib/inferno/terminology/validator.rb
onc_certification_g10_test_kit-3.3.0 lib/inferno/terminology/validator.rb