Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/models/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ def active_for?(labware)
end
end

def active_for_in_progress_requests?(labware)
return false unless purpose_in_relationships?(labware.purpose)
return true if filters.blank?

# NB. do not include completed requests here
labware.incomplete_requests.any? do |request|
# For each attribute (eg. library_type) check that the matching property
# on request is included in the list of permitted values.
filters.all? do |request_attribute, permitted_values|
permitted_values.include? request.public_send(request_attribute)
end
end
end

def filters=(filters)
# Convert any singlular values to an array to provide a consistent interface
@filters = filters.transform_values { |value| Array(value) }
Expand Down
9 changes: 9 additions & 0 deletions app/models/pipeline_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ def active_pipelines_for(labware)
@list.select { |pipeline| pipeline.active_for?(labware) }
end

# This version of active pipelines does not consider completed requests when determining whether
# a pipeline is active for a piece of labware.
# NB. added to resolve confusion in Bioscan where the PCR 1 button was showing on repeat runs,
# despite no new active library prep submission being made yet. Then in the next page, quad stamping,
# you would have no wells to transfer into the new PCR 1.
def active_pipelines_for_in_progress_requests(labware)
@list.select { |pipeline| pipeline.active_for_in_progress_requests?(labware) }
end

# For the given pipeline group
# return a object with key: group, and value: list of the pipeline names in that group
# e.g {"Bespoke Chromium 3pv2"=>["Bespoke Chromium 3pv2", "Bespoke Chromium 3pv2 MX"]}
Expand Down
14 changes: 14 additions & 0 deletions app/models/presenters/bioscan_submission_plate_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Presenters
#
# This version of the SubmissionPlatePresenter only displays the child creation button
# if it has active requests which match the pipeline filters.
# Used specifically for Bioscan PCR 1 plate creation.
#
class BioscanSubmissionPlatePresenter < SubmissionPlatePresenter
def active_pipelines
Settings.pipelines.active_pipelines_for_in_progress_requests(labware)
end
end
end
2 changes: 1 addition & 1 deletion config/purposes/bioscan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LBSN-96 Lysate Input:
:label_template: plate_96_lysate
:creator_class: LabwareCreators::Uncreatable
:size: 96
:presenter_class: Presenters::SubmissionPlatePresenter
:presenter_class: Presenters::BioscanSubmissionPlatePresenter
:submission_options:
Bioscan Library Prep:
template_name: 'Limber-Htp - Bioscan Library Prep - Automated'
Expand Down
84 changes: 84 additions & 0 deletions spec/models/presenters/bioscan_submission_plate_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# frozen_string_literal: true

require 'spec_helper'
require_relative 'shared_labware_presenter_examples'

RSpec.describe Presenters::BioscanSubmissionPlatePresenter do
describe '#active_pipelines' do
let(:purpose_name) { 'Bioscan Purpose' }
let(:study) { create :study, name: 'Submission Study' }
let(:project) { create :project, name: 'Submission Project' }

let(:labware) do
create :plate,
well_count: 2,
purpose_name: purpose_name,
barcode_number: 2,
aliquots_without_requests: 2,
study: study,
project: project
end
let(:presenter) { described_class.new(labware:) }

let(:library_type_name) { 'LibTypeA' }
let(:request_type_a) { create :request_type, key: 'rt_a' }
let(:request_in_progress) do
create :library_request,
request_type: request_type_a,
uuid: 'request-0',
library_type: library_type_name,
state: 'pending'
end

let(:request_completed) do
create :library_request,
request_type: request_type_a,
uuid: 'request-1',
library_type: library_type_name,
state: 'passed'
end

let(:filters) { { request_type_key: ['rt_a'] } }
let(:pipelines_config) do
{
'bioscan_pipeline' => {
pipeline_group: 'Group A',
relationships: {
'parent' => 'Bioscan Purpose'
},
filters: filters
}
}
end

before do
Settings.pipelines = PipelineList.new(pipelines_config)

allow(labware.wells.first).to receive(:requests_as_source).and_return(requests_as_source_list)
end

context 'when there is an active request' do
let(:requests_as_source_list) { [request_in_progress] }

it 'returns a pipeline when there is an active request' do
expect(presenter.active_pipelines).to include(have_attributes(name: 'bioscan_pipeline'))
end
end

context 'when no requests as source' do
let(:requests_as_source_list) { [] }

it 'does not return a pipeline when there are no active requests' do
expect(presenter.active_pipelines).to be_empty
end
end

context 'when only completed requests' do
let(:requests_as_source_list) { [request_completed] }

it 'does not return a pipeline when the only requests are completed' do
expect(presenter.active_pipelines).to be_empty
end
end
end
end
Loading