Class: Pipeline::BSI::Importer::SpecimenImporter

Inherits:
Importer::Base
  • Object
show all
Defined in:
lib/bsi-pipeline/importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ SpecimenImporter

Returns a new instance of SpecimenImporter.



84
85
86
87
88
# File 'lib/bsi-pipeline/importer.rb', line 84

def initialize(key, options={})
  @bsi              = RBC.new(key, options)
  @specimens        = specimens
  @batches          = Array.new
end

Instance Attribute Details

#batch_delimiterObject

Returns the value of attribute batch_delimiter.



82
83
84
# File 'lib/bsi-pipeline/importer.rb', line 82

def batch_delimiter
  @batch_delimiter
end

#batchesObject

Returns the value of attribute batches.



82
83
84
# File 'lib/bsi-pipeline/importer.rb', line 82

def batches
  @batches
end

#specimensObject

Returns the value of attribute specimens.



82
83
84
# File 'lib/bsi-pipeline/importer.rb', line 82

def specimens
  @specimens
end

Instance Method Details

#import(all_specimens, options = {}) ⇒ Object



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
# File 'lib/bsi-pipeline/importer.rb', line 90

def import(all_specimens, options={})
  @specimens = all_specimens
  study_ids   = @specimens.map{|e| e.study_id}.uniq
  subject_ids = @specimens.map{|e| e.subject_id}.uniq

  study_ids.each do |study|
    subject_ids.each_with_index do |sid, i|
      # Filter by subject_id and study_id
      subset = @specimens.select{|e| e.study_id == study && e.subject_id == sid}

      batch_properties = {
        'batch.description' => "Subject: #{sid}",
        'batch.study_id'    => study.to_s
      }

      @batch = AddBatch.new(@bsi, batch_properties)
      @batch.add_specimens(subset)
      @batch.commit if options['commit']

      @batches << @batch
    end
  end

  @bsi.common.logoff
end