lib/inferno/terminology/loader.rb
# Creates the valueset validators, based on the passed in parameters and
# the value_sets_repo
#
# @param type [Symbol] the type of validators to create, either :bloom or
#   :csv
# @param [String] minimum_binding_strength the lowest binding strength for
#   which we should build validators
# @param [Boolean] include_umls a flag to determine if we should build
#   validators that require UMLS
# @param [Boolean] delete_existing a flag to determine whether any
#   existing validators of `type` should be deleted before the creation
#   tasks run. Default to `true`. If `false`, the existing validators will
#   be read in and combined with the validators created in this step.
Creates the valueset validators, based on the passed in parameters and
the value_sets_repo
Creates the valueset validators based on the passed in parameters and the value_sets_repo
def create_validators(
          type: :bloom,
          minimum_binding_strength: 'example',
          include_umls: true,
          delete_existing: true
        )
          strengths = ['example', 'preferred', 'extensible', 'required'].drop_while do |s|
            s != minimum_binding_strength
          end
          umls_code_systems = Set.new(ValueSet::SAB.keys)
          root_dir = "resources/terminology/validators/#{type}"
          FileUtils.rm_r(root_dir, force: true) if delete_existing
          FileUtils.mkdir_p(root_dir)
          vs_validators = get_value_sets(strengths).map do |vs_url, vs|
            next if SKIP_SYS.include? vs_url
            next if !include_umls && !umls_code_systems.disjoint?(Set.new(vs.included_code_systems))
            Inferno.logger.debug "Processing #{vs_url}"
            filename = "#{root_dir}/#{(URI(vs.url).host + URI(vs.url).path).gsub(%r{[./]}, '_')}"
            begin
              new_count = save_to_file(vs.value_set, filename, type)
              {
                url: vs_url,
                file: name_by_type(File.basename(filename), type),
                count: new_count,
                type: type.to_s,
                code_systems: vs.included_code_systems
              }
            rescue UnknownCodeSystemException,
                   FilterOperationException,
                   UnknownValueSetException,
                   URI::InvalidURIError => e
              Inferno.logger.warn "#{e.message} for ValueSet: #{vs_url}"
              next
            end
          end
          vs_validators.compact!
          code_systems = vs_validators.flat_map { |validator| validator[:code_systems] }.uniq
          vs = ValueSet.new(@db)
          cs_validators = code_systems.map do |cs_name|
            next if SKIP_SYS.include? cs_name
            next if !include_umls && umls_code_systems.include?(cs_name)
            Inferno.logger.debug "Processing #{cs_name}"
            begin
              cs = vs.code_system_set(cs_name)
              filename = "#{root_dir}/#{bloom_file_name(cs_name)}"
              new_count = save_to_file(cs, filename, type)
              {
                url: cs_name,
                file: name_by_type(File.basename(filename), type),
                count: new_count,
                type: type.to_s,
                code_systems: cs_name
              }
            rescue UnknownCodeSystemException,
                   FilterOperationException,
                   UnknownValueSetException,
                   URI::InvalidURIError => e
              Inferno.logger.warn "#{e.message} for CodeSystem #{cs_name}"
              next
            end
          end
          validators = (vs_validators + cs_validators).compact
          File.write("#{root_dir}/manifest.yml", validators.to_yaml)
          create_code_system_metadata(cs_validators.map { |validator| validator[:url] }, root_dir)
        end
def create_validators ( type : :bloom , minimum_binding_strength : 'example' , include_umls : true , delete_existing : true ) strengths = [ 'example' , 'preferred' , 'extensible' , 'required' ] . drop_while do | s | s != minimum_binding_strength end umls_code_systems = Set . new ( ValueSet :: SAB . keys ) root_dir = "resources/terminology/validators/#{type}" FileUtils . rm_r ( root_dir , force : true ) if delete_existing FileUtils . mkdir_p ( root_dir ) vs_validators = get_value_sets ( strengths ) . map do | vs_url , vs | next if SKIP_SYS . include? vs_url next if ! include_umls && ! umls_code_systems . disjoint? ( Set . new ( vs . included_code_systems ) ) Inferno . logger . debug "Processing #{vs_url}" filename = "#{root_dir}/#{(URI(vs.url).host + URI(vs.url).path).gsub(%r{[./]}, '_')}" begin new_count = save_to_file ( vs . value_set , filename , type ) { url : vs_url , file : name_by_type ( File . basename ( filename ) , type ) , count : new_count , type : type . to_s , code_systems : vs . included_code_systems } rescue UnknownCodeSystemException , FilterOperationException , UnknownValueSetException , URI :: InvalidURIError => e Inferno . logger . warn "#{e.message} for ValueSet: #{vs_url}" next end end vs_validators . compact! code_systems = vs_validators . flat_map { | validator | validator [ :code_systems ] } . uniq vs = ValueSet . new ( @db ) cs_validators = code_systems . map do | cs_name | next if SKIP_SYS . include? cs_name next if ! include_umls && umls_code_systems . include? ( cs_name ) Inferno . logger . debug "Processing #{cs_name}" begin cs = vs . code_system_set ( cs_name ) filename = "#{root_dir}/#{bloom_file_name(cs_name)}" new_count = save_to_file ( cs , filename , type ) { url : cs_name , file : name_by_type ( File . basename ( filename ) , type ) , count : new_count , type : type . to_s , code_systems : cs_name } rescue UnknownCodeSystemException , FilterOperationException , UnknownValueSetException , URI :: InvalidURIError => e Inferno . logger . warn "#{e.message} for CodeSystem #{cs_name}" next end end validators = ( vs_validators + cs_validators ) . compact File . write ( "#{root_dir}/manifest.yml" , validators . to_yaml ) create_code_system_metadata ( cs_validators . map { | validator | validator [ :url ] } , root_dir ) end
Creates the valueset validators, based on the passed in parameters and
the value_sets_repo
Creates the valueset validators based on the passed in parameters and the value_sets_repo
# Save the validator to file, and get the "new" count of number of codes # Write manifest for loading later
type
the type of validators to create, either :bloom or :csv
the type of validators to create either : bloom or : csv
minimum_binding_strength
<not_specific>
include_umls
<not_specific>
delete_existing
<not_specific>
<not_specific>
delete_existing a flag to determine whether any existing validators of `type` should be deleted before the creation tasks run. Default to `true`. If `false`, the existing validators will be read in and combined with the validators created in this step.
delete_existing a flag to determine whether any existing validators of ` type ` should be deleted before the creation tasks run . Default to ` true ` . If ` false ` the existing validators will be read in and combined with the validators created in this step .