Class: Inferno::Terminology::Tasks::ProcessUMLS

Inherits:
Object
  • Object
show all
Includes:
DownloadUMLSNotice, TempDir
Defined in:
lib/inferno/terminology/tasks/process_umls.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DownloadUMLSNotice

#download_umls_notice

Methods included from TempDir

#pipe_files, #umls_dir, #umls_subset_dir, #umls_zip_path, #versioned_temp_dir

Constructor Details

#initialize(version:) ⇒ ProcessUMLS

Returns a new instance of ProcessUMLS.



15
16
17
# File 'lib/inferno/terminology/tasks/process_umls.rb', line 15

def initialize(version:)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/inferno/terminology/tasks/process_umls.rb', line 13

def version
  @version
end

Instance Method Details

#runObject

rubocop:disable Metrics/CyclomaticComplexity



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/inferno/terminology/tasks/process_umls.rb', line 19

def run # rubocop:disable Metrics/CyclomaticComplexity
  Inferno.logger.info 'Looking for `./tmp/terminology/MRCONSO.RRF`...'
  input_file = Find.find(versioned_temp_dir).find { |f| /MRCONSO.RRF$/ =~f }
  if input_file
    start = Time.now
    output_filename = File.join(versioned_temp_dir, 'terminology_umls.txt')
    output = File.open(output_filename, 'w:UTF-8')
    line = 0
    excluded = 0
    excluded_systems = Hash.new(0)
    begin
      Inferno.logger.info "Writing to #{output_filename}..."
      CSV.foreach(input_file, headers: false, col_sep: '|', quote_char: "\x00") do |row|
        line += 1
        include_code = false
        code_system = row[11]
        code = row[13]
        description = row[14]
        case code_system
        when 'SNOMEDCT_US'
          code_system = 'SNOMED'
          include_code = (row[4] == 'PF' && ['FN', 'OAF'].include?(row[12]))
        when 'LNC'
          code_system = 'LOINC'
          include_code = true
        when 'ICD10CM', 'ICD10PCS'
          code_system = 'ICD10'
          include_code = (row[12] == 'PT')
        when 'ICD9CM'
          code_system = 'ICD9'
          include_code = (row[12] == 'PT')
        when 'CPT', 'HCPCS'
          include_code = (row[12] == 'PT')
        when 'MTHICD9'
          code_system = 'ICD9'
          include_code = true
        when 'RXNORM'
          include_code = true
        when 'CVX'
          include_code = ['PT', 'OP'].include?(row[12])
        when 'SRC'
          # 'SRC' rows define the data sources in the file
          include_code = false
        else
          include_code = false
          excluded_systems[code_system] += 1
        end
        if include_code
          output.write("#{code_system}|#{code}|#{description}\n")
        else
          excluded += 1
        end
      end
    rescue StandardError => e
      Inferno.logger.info "Error at line #{line}"
      Inferno.logger.info e.message
    end
    output.close
    Inferno.logger.info "Processed #{line} lines, excluding #{excluded} redundant entries."
    Inferno.logger.info "Excluded code systems: #{excluded_systems}" unless excluded_systems.empty?
    finish = Time.now
    minutes = ((finish - start) / 60)
    seconds = (minutes - minutes.floor) * 60
    Inferno.logger.info "Completed in #{minutes.floor} minute(s) #{seconds.floor} second(s)."
    Inferno.logger.info 'Done.'
  else
    download_umls_notice
  end
end