Module: Lab::Loaders::TestResultIndicatorsLoader

Extended by:
LoaderMixin
Defined in:
lib/tasks/loaders/test_result_indicators_loader.rb

Overview

Load specimens and their tests into the database

Constant Summary

Constants included from LoaderMixin

LoaderMixin::CONCEPT_CLASS_TEST, LoaderMixin::CONCEPT_DATATYPE_CODED

Class Method Summary collapse

Methods included from LoaderMixin

add_concept_to_set, data_path, find_or_create_concept, included

Class Method Details

.add_measure_to_test(test_name, measure_concept) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/tasks/loaders/test_result_indicators_loader.rb', line 41

def add_measure_to_test(test_name, measure_concept)
  [
    add_concept_to_set(set_concept_id: find_or_create_concept(Lab::Metadata::TEST_RESULT_INDICATOR_CONCEPT_NAME).concept_id,
                       concept_id: measure_concept.concept_id),
    add_concept_to_set(set_concept_id: measure_concept.concept_id,
                       concept_id: find_or_create_concept(test_name).concept_id)
  ]
rescue StandardError => e
  raise "Failed to create measure for test `#{name}`: #{e}"
end

.create_test_type(name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/tasks/loaders/test_result_indicators_loader.rb', line 33

def create_test_type(name)
  concept_id = find_or_create_concept(name, is_set: true).concept_id

  create_concept_set(concept_set: test_type_concept_id, concept_id: concept_id)
rescue StandardError => e
  raise "Failed to create test type `#{name}`: #{e}"
end

.loadObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tasks/loaders/test_result_indicators_loader.rb', line 14

def load
  puts "------- Loading measures ------------"
  CSV.open(data_path('test-measures.csv'), headers: :first_row) do |csv|
    csv.each_with_object({}) do |row, test_measures|
      test_name = row['test_name']
      measure_name = row['measure_name']

      ActiveRecord::Base.transaction do
        measure_concept = find_or_create_concept(measure_name)
        add_measure_to_test(test_name, measure_concept)
      end

      puts "Created measure #{test_name} <--< #{measure_name}"
    rescue StandardError => e
      puts "Error: #{measure_name}: #{e}"
    end
  end
end