-
Notifications
You must be signed in to change notification settings - Fork 34
Y26 031 labware location report by retention instructions #5637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
a5b5a47
e446636
99653c3
67bc87f
fc408a1
31159ad
0b1e94f
77a9e04
a2a9912
7e4e26f
8a8178f
81e643c
ef88f72
9b13bb4
c010b3d
d767076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ class LocationReport < ApplicationRecord | |
| serialize :faculty_sponsor_ids, type: Array, coder: YAML | ||
| serialize :plate_purpose_ids, type: Array, coder: YAML | ||
| serialize :barcodes, type: Array, coder: YAML | ||
| serialize :retention_instructions, type: Array, coder: YAML | ||
| self.per_page = 20 | ||
| enum :report_type, { type_selection: 0, type_labwhere: 1 } | ||
|
|
||
|
|
@@ -49,7 +50,7 @@ def check_location_barcode | |
| end | ||
|
|
||
| def check_any_select_field_present | ||
| attr_list = %i[faculty_sponsor_ids study_id start_date end_date plate_purpose_ids barcodes] | ||
| attr_list = %i[faculty_sponsor_ids study_id start_date end_date plate_purpose_ids barcodes retention_instructions] | ||
| if attr_list.all? { |attr| send(attr).blank? } | ||
| errors.add(:base, I18n.t('location_reports.errors.no_selection_fields_filled')) | ||
| end | ||
|
|
@@ -119,7 +120,6 @@ def generate_report_rows # rubocop:todo Metrics/MethodLength | |
| end | ||
|
|
||
| yield column_headers | ||
|
|
||
| labware_list.each do |cur_labware| | ||
| if cur_labware.studies.present? | ||
| cur_labware.studies.each { |cur_study| yield(generate_report_row(cur_labware, cur_study)) } | ||
|
|
@@ -176,14 +176,30 @@ def generate_study_cols_for_row(cur_study) | |
| end | ||
|
|
||
| def search_for_labware_by_selection | ||
| params = { faculty_sponsor_ids:, study_id:, start_date:, end_date:, plate_purpose_ids:, barcodes: } | ||
| params = { faculty_sponsor_ids:, study_id:, start_date:, end_date:, plate_purpose_ids:, barcodes:, | ||
| retention_instructions: } | ||
| validate_result_size(params) | ||
|
|
||
| # Only plates and tubes are currently supported by this report | ||
| labwares = Labware.search_for_labware(params).filter { |labware| labware.is_a?(Plate) || labware.is_a?(Tube) } | ||
|
|
||
| filter_labware_by_retention_instructions(labwares) | ||
|
Comment on lines
178
to
+186
|
||
| end | ||
|
|
||
| def filter_labware_by_retention_instructions(labwares) | ||
| return labwares if retention_instructions.blank? | ||
|
|
||
| labwares.select do |lw| | ||
| retention_instructions.include?(normalize_retention_instruction(lw.retention_instructions)) | ||
| end | ||
| end | ||
|
|
||
| def validate_result_size(params) | ||
| count = Labware.search_for_count_of_labware(params) | ||
| if count > configatron.fetch(:location_reports_fetch_count_max, 25000) | ||
| errors.add(:base, I18n.t('location_reports.errors.too_many_labwares_found', count:)) | ||
| return [] | ||
| [] | ||
| end | ||
| # Only plates and tubes are currently supported by this report | ||
| Labware.search_for_labware(params).filter { |labware| labware.is_a?(Plate) || labware.is_a?(Tube) } | ||
| end | ||
|
Comment on lines
+197
to
203
|
||
|
|
||
| def search_for_labware_by_labwhere_locn_bc | ||
|
|
@@ -208,5 +224,9 @@ def get_labwares_per_location(curr_locn_bc) | |
| curr_locn_children = LabWhereClient::Location.children(curr_locn_bc) | ||
| curr_locn_children.each { |curr_locn| get_labwares_per_location(curr_locn.barcode) } if curr_locn_children.present? | ||
| end | ||
|
|
||
| def normalize_retention_instruction(value) | ||
| value.to_s.parameterize(separator: '_') | ||
| end | ||
| end | ||
| # rubocop:enable Metrics/ClassLength | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,11 @@ | |
| </div> | ||
| </div> | ||
|
|
||
| <div class='form-group'> | ||
| <%= f.label 'retention_instructions', 'Retention instructions' %> | ||
| <%= f.select :retention_instructions, options_for_select(retention_instruction_option_for_select, location_report_form.retention_instructions), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want users to be able to select multiple at once? We should be able to change the options here so the labels are the readable versions (Long term storage) but the option values are the normalised long_term_storage. This would prevent us having to format them here https://github.com/sanger/sequencescape/pull/5637/changes#diff-96a48d35086a071258b6b8210f00ccf6a1092d9a4443c8c46d5c1a8765548a5aR228 |
||
| </div> | ||
|
|
||
| <div class='form-group'> | ||
| <%= f.label 'plate_purpose_ids', 'Labware purposes (can select multiple)' %> | ||
| <%= f.select :plate_purpose_ids, options_for_select(Purpose.alphabetical.pluck(:name, :id), location_report_form.plate_purpose_ids), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # frozen_string_literal: true | ||
| class AddRetentionInstructionsToLocationReports < ActiveRecord::Migration[7.2] | ||
| def change | ||
| add_column :location_reports, :retention_instructions, :string | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,14 +46,15 @@ | |
|
|
||
| # add retention instruction metadata to plate 1 custom metadatum collection | ||
| let(:retention_key) { 'retention_instruction' } | ||
| let(:retention_value) { 'Long term storage' } | ||
| let(:retention_value_1) { 'Long term storage' } | ||
| let(:retention_value_2) { 'Return to customer after 2 years' } | ||
| let(:plate_1_custom_metadatum_collection) { create(:custom_metadatum_collection, asset: plate_1, user: user) } | ||
| let(:plate_1_custom_metadatum) do | ||
| create( | ||
| :custom_metadatum, | ||
| custom_metadatum_collection: plate_1_custom_metadatum_collection, | ||
| key: retention_key, | ||
| value: retention_value | ||
| value: retention_value_1 | ||
| ) | ||
| end | ||
|
|
||
|
|
@@ -89,7 +90,7 @@ | |
| :custom_metadatum, | ||
| custom_metadatum_collection: plate_3_custom_metadatum_collection, | ||
| key: retention_key, | ||
| value: retention_value | ||
| value: retention_value_1 | ||
| ) | ||
| end | ||
|
|
||
|
|
@@ -110,7 +111,7 @@ | |
| :custom_metadatum, | ||
| custom_metadatum_collection: tube_1_custom_metadatum_collection, | ||
| key: retention_key, | ||
| value: retention_value | ||
| value: retention_value_1 | ||
| ) | ||
| end | ||
|
|
||
|
|
@@ -145,7 +146,8 @@ | |
| start_date:, | ||
| end_date:, | ||
| plate_purpose_ids:, | ||
| barcodes: | ||
| barcodes:, | ||
| retention_instructions: | ||
| ) | ||
| end | ||
| let(:report_type) { nil } | ||
|
|
@@ -157,6 +159,7 @@ | |
| let(:end_date) { nil } | ||
| let(:plate_purpose_ids) { nil } | ||
| let(:barcodes) { nil } | ||
| let(:retention_instructions) { nil } | ||
|
|
||
| describe 'validations' do | ||
| context 'when no report type is set' do | ||
|
|
@@ -244,7 +247,7 @@ | |
|
|
||
| let(:plt_1_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:plt_2_line_1) do | ||
|
|
@@ -259,12 +262,12 @@ | |
| end | ||
| let(:plt_3_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{plate_3.machine_barcode},#{plate_3.human_barcode},#{plt_3_purpose},#{plt_3_created},#{plt_3_received_date},#{locn_prefix} - Shelf 3,LabWhere,#{retention_value},#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" | ||
| "#{plate_3.machine_barcode},#{plate_3.human_barcode},#{plt_3_purpose},#{plt_3_created},#{plt_3_received_date},#{locn_prefix} - Shelf 3,LabWhere,#{retention_value_1},#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:tube_1_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{tube_1.machine_barcode},#{tube_1.human_barcode},#{tube_1_purpose},#{tube_1_created},#{tube_1_received_date},#{locn_prefix} - Shelf 4,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{tube_1.machine_barcode},#{tube_1.human_barcode},#{tube_1_purpose},#{tube_1_created},#{tube_1_received_date},#{locn_prefix} - Shelf 4,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
|
|
||
|
|
@@ -473,6 +476,52 @@ | |
|
|
||
| it_behaves_like 'a successful report' | ||
| end | ||
|
|
||
| context 'with retention instructions' do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test for multiple retention instructions if we are supporting it. |
||
| let(:start_date) { '2016-01-01 00:00:00' } | ||
| let(:end_date) { '2016-11-01 00:00:00' } | ||
| let(:retention_instructions) { %w[long_term_storage return_to_customer_after_2_years] } | ||
| # Only plate_1, plate_3, and tube_1 have this metadata, and the value is 'Long term storage' for all | ||
| let(:expected_lines) do | ||
| [ | ||
| headers_line, | ||
| plt_1_line, | ||
| plt_3_line, | ||
| tube_1_line | ||
| ] | ||
| end | ||
|
|
||
| it_behaves_like 'a successful report' | ||
| end | ||
|
|
||
| context 'with multiple retention instruction filters' do | ||
| let(:start_date) { '2016-01-01 00:00:00' } | ||
| let(:end_date) { '2016-11-01 00:00:00' } | ||
| let(:retention_instructions) { %w[long_term_storage return_to_customer_after_2_years] } | ||
| let(:plate_3_custom_metadatum) do | ||
| create( | ||
| :custom_metadatum, | ||
| custom_metadatum_collection: plate_3_custom_metadatum_collection, | ||
| key: retention_key, | ||
| value: retention_value_2 | ||
| ) | ||
| end | ||
| let(:plt_3_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{plate_3.machine_barcode},#{plate_3.human_barcode},#{plt_3_purpose},#{plt_3_created},#{plt_3_received_date},#{locn_prefix} - Shelf 3,LabWhere,#{retention_value_2},#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:expected_lines) do | ||
| [ | ||
| headers_line, | ||
| plt_1_line, | ||
| plt_3_line, | ||
| tube_1_line | ||
| ] | ||
| end | ||
|
|
||
| it_behaves_like 'a successful report' | ||
| end | ||
| end | ||
|
|
||
| context 'by labwhere location' do | ||
|
|
@@ -503,7 +552,7 @@ | |
| let(:location_barcode) { 'locn-1-at-lvl-1' } | ||
| let(:plt_1_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:expected_lines) { [headers_line, plt_1_line] } | ||
|
|
@@ -530,7 +579,7 @@ | |
| let(:location_barcode) { 'locn-1-at-lvl-1' } | ||
| let(:plt_1_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1 - Box 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1 - Box 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:plt_2_line_1) do | ||
|
|
@@ -545,7 +594,7 @@ | |
| end | ||
| let(:tube_1_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{tube_1.machine_barcode},#{tube_1.human_barcode},#{tube_1_purpose},#{tube_1_created},#{tube_1_received_date},#{locn_prefix} - Shelf 1 - Box 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{tube_1.machine_barcode},#{tube_1.human_barcode},#{tube_1_purpose},#{tube_1_created},#{tube_1_received_date},#{locn_prefix} - Shelf 1 - Box 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:expected_lines) { [headers_line, plt_1_line, plt_2_line_1, plt_2_line_2, tube_1_line] } | ||
|
|
@@ -607,7 +656,7 @@ | |
| let(:location_barcode) { 'locn-1-at-lvl-1' } | ||
| let(:plt_1_line) do | ||
| # rubocop:todo Layout/LineLength | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1 - Box 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1 - Box 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| # rubocop:enable Layout/LineLength | ||
| end | ||
| let(:plt_2_line_1) do | ||
|
|
@@ -675,7 +724,7 @@ | |
|
|
||
| # rubocop:todo Layout/LineLength | ||
| let(:plt_1_line) do | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{plate_1.machine_barcode},#{plate_1.human_barcode},#{plt_1_purpose},#{plt_1_created},#{plt_1_received_date},#{locn_prefix} - Shelf 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| end | ||
| let(:plt_2_line_1) do | ||
| "#{plate_2.machine_barcode},#{plate_2.human_barcode},#{plt_2_purpose},#{plt_2_created},#{plt_2_received_date},#{locn_prefix} - Shelf 1 - Tray 1,LabWhere,Unknown,#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
|
|
@@ -684,10 +733,10 @@ | |
| "#{plate_2.machine_barcode},#{plate_2.human_barcode},#{plt_2_purpose},#{plt_2_created},#{plt_2_received_date},#{locn_prefix} - Shelf 1 - Tray 1,LabWhere,Unknown,#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" | ||
| end | ||
| let(:plt_3_line) do | ||
| "#{plate_3.machine_barcode},#{plate_3.human_barcode},#{plt_3_purpose},#{plt_3_created},#{plt_3_received_date},#{locn_prefix} - Shelf 1 - Tray 1 - Box 1,LabWhere,#{retention_value},#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" | ||
| "#{plate_3.machine_barcode},#{plate_3.human_barcode},#{plt_3_purpose},#{plt_3_created},#{plt_3_received_date},#{locn_prefix} - Shelf 1 - Tray 1 - Box 1,LabWhere,#{retention_value_1},#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" | ||
| end | ||
| let(:tube_1_line) do | ||
| "#{tube_1.machine_barcode},#{tube_1.human_barcode},#{tube_1_purpose},#{tube_1_created},#{tube_1_received_date},#{locn_prefix} - Shelf 1 - Tray 1 - Box 1,LabWhere,#{retention_value},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| "#{tube_1.machine_barcode},#{tube_1.human_barcode},#{tube_1_purpose},#{tube_1_created},#{tube_1_received_date},#{locn_prefix} - Shelf 1 - Tray 1 - Box 1,LabWhere,#{retention_value_1},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" | ||
| end | ||
|
|
||
| # rubocop:enable Layout/LineLength | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
location_report_paramspermits:barcodesand:barcodes_texttwice. This duplication is redundant and can confuse future edits; remove the duplicates so each permitted key appears only once.