Skip to content

Commit

Permalink
If the plate already has an aliquot, it stops the transfer of tubes w…
Browse files Browse the repository at this point in the history
…hen there

is a tube transfer by column order step.
  • Loading branch information
emrojo committed Sep 25, 2019
1 parent 7f16772 commit 25205ed
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions script/runners/transfer_tubes_to_tube_rack_by_position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ def validate_all_tubes_have_aliquot(tubes, updates)
true
end

def validate_same_aliquot_between_tubes_and_destination_plate(tubes, rack, updates)
aliquot_tubes = Fact.where(asset_id: tubes.map(&:id), predicate: 'aliquotType').map(&:object).uniq
if aliquot_tubes.length > 1
updates.set_errors(["More that one different aliquot in the source tubes"])
return false
end
aliquot_plate = rack.facts.where(predicate: 'aliquotType').map(&:object).uniq
if aliquot_plate.length > 1
updates.set_errors(["More thatn one aliquot in the destination plate"])
return false
end
if aliquot_plate.length > 0
if aliquot_tubes.first != aliquot_plate.first
updates.set_errors(["Aliquot for tubes #{aliquot_tubes.first} is different from aliquot at rack #{aliquot_plate.first}"])
return false
end
end
true
end

def process
FactChanges.new.tap do |updates|
aliquot_types = []
Expand Down Expand Up @@ -102,6 +122,7 @@ def process
if aliquot_types

return updates unless validate_all_tubes_have_aliquot(tubes, updates)
return updates unless validate_same_aliquot_between_tubes_and_destination_plate(tubes, rack, updates)

if (((aliquot_types.uniq.length) == 1) && (aliquot_types.uniq.first == 'DNA'))
purpose_name = 'DNA Stock Plate'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@
expect(purposes.first[2]).to eq("RNA Stock Plate")
end
end

context 'when the plate has already an aliquot set' do
before do
rack.facts << create(:fact, predicate: 'aliquotType', object: aliquot_rack)
end
context 'when the aliquot at source tubes is different from the aliquot already in the plate' do
let(:aliquot) { aliquot_dna }
let(:aliquot_rack) { aliquot_rna }
it 'produces an error' do
set_errors = instance.process.to_h[:set_errors]
expect(set_errors.count).not_to eq(0)
end
end
context 'when the aliquot at source tubes is equal to the aliquot already in the plate' do
let(:aliquot) { aliquot_dna }
let(:aliquot_rack) { aliquot_dna }
it 'does not produce an error' do
set_errors = instance.process.to_h[:set_errors]
expect(set_errors.nil?).to eq(true)
end
end
end
end
end

Expand Down

0 comments on commit 25205ed

Please sign in to comment.