-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
137 lines (120 loc) · 3.66 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
begin
require "bundler/gem_tasks"
rescue LoadError
end
ENV['CONCEPTQL_DATA_MODEL'] ||= ConceptQL::DEFAULT_DATA_MODEL.to_s
run_spec = lambda do |data_model|
sh "CONCEPTQL_DATA_MODEL=#{data_model} #{FileUtils::RUBY} test/all.rb"
end
desc "Run tests with omopv4_plus data model"
task :test_omopv4_plus do
run_spec.call(:omopv4_plus)
end
desc "Run tests with gdm data model"
task :test_gdm do
run_spec.call(:gdm)
end
desc "Run tests with omopv4 data model with coverage"
task :test_cov do
ENV['COVERAGE'] = '1'
run_spec.call(:omopv4_plus)
end
desc "Run tests with omopv4 data model"
task :default => :test_omopv4_plus
desc "Ingests client's CSV file for custom vocabularies"
task :make_vocabs_csv, [:csv_path] do |t, args|
require "conceptql"
require "csv"
require "open-uri"
known_vocabs = CSV.foreach(ConceptQL.vocabularies_file_path, headers: true, header_converters: :symbol).each_with_object({}) do |row, h|
h[row[:id].downcase] = row.to_hash
end
amgen_vocabs = open(args.csv_path) do |amgen_csv_file|
CSV.parse(amgen_csv_file.read, headers: true, header_converters: :symbol).each_with_object({}) do |row, h|
h[row[:vocabulary_short_name].downcase] = row.to_hash
end
end
new_from_amgen = amgen_vocabs.keys - known_vocabs.keys
new_vocabs = new_from_amgen.each_with_object({}) do |key, h|
amgen_vocab = amgen_vocabs[key]
new_vocab = {
id: amgen_vocab[:vocabulary_short_name],
omopv4_vocabulary_id: amgen_vocab[:vocabulary_id],
vocabulary_full_name: amgen_vocab[:vocabulary_long_name],
vocabulary_short_name: amgen_vocab[:vocabulary_short_name],
domain: amgen_vocab[:omop_table],
hidden: nil,
format_regexp: nil
}
h[new_vocab[:id]] = new_vocab
end
headers = new_vocabs.first.last.keys
CSV.open(ConceptQL.custom_vocabularies_file_path, "w") do |csv|
csv << headers
new_vocabs.sort_by { |k, v| v[:id] }.map { |k, v| v.values_at(*headers) }.each do |row|
csv << row
end
end
end
desc "Show which columns can be ignored"
task :ignorables, [:data_model] do |t, args|
require 'conceptql'
dm = args[:data_model].to_sym
ignorables = ConceptQL::DataModel.get(dm).schema.each_with_object([]) do |(table, table_info), iggies|
if table_info[:ignorable]
iggies << [table.to_s, "all columns"]
next
else
table_info[:columns].map do |column_name, column_info|
if column_info[:ignorable]
iggies << [table.to_s, column_name.to_s]
end
end
end
end
additional = Pathname.new("schemas") + "#{dm}_more_ignorables.tsv"
if additional.exist?
ignorables += CSV.readlines(additional, col_sep: "\t")
end
puts ignorables.sort.map{ |arr| arr.join("\t") }.join("\n")
end
desc "Drop all tables/columns which can be ignored"
task :drop_ignorables, [:data_model] do |t, args|
require 'conceptql'
require 'sequelizer'
include Sequelizer
dm = args[:data_model].to_sym
db.set(search_path: "#{dm}_250")
ConceptQL::DataModel.get(dm).schema.each do |table, table_info|
if table_info[:ignorable]
puts "#{table}\tall_columns"
db.drop_table(table, if_exists: true)
next
end
table_info[:columns].each do |column_name, column_info|
if column_info[:ignorable]
puts "#{table}\t#{column_name}"
db.drop_column(table, column_name)
end
end
end
end
desc "Dump a set of diagnostics"
task :diagnostics do
require "sequelizer"
require "pp"
puts "*" * 80
puts "Free Space"
pp `df -h`
puts "*" * 80
puts "Environment"
pp ENV
puts "*" * 80
puts "Sequelizer"
system("bundle exec sequelizer config")
puts "*" * 80
puts "Database"
include Sequelizer
pp db
pp db.tables
end