From a5b5a474d9d3e0e716389d2da433015098cd033a Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Thu, 19 Mar 2026 10:20:56 +0000 Subject: [PATCH 01/19] save changes --- app/controllers/location_reports_controller.rb | 1 + app/models/location_report/location_report_form.rb | 3 ++- .../_location_labware_selection_form.html.erb | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/location_reports_controller.rb b/app/controllers/location_reports_controller.rb index 5f49df9c1e..cd487c9604 100644 --- a/app/controllers/location_reports_controller.rb +++ b/app/controllers/location_reports_controller.rb @@ -60,6 +60,7 @@ def location_report_params # rubocop:todo Metrics/MethodLength :study_id, :start_date, :end_date, + :retention_instructions, :barcodes, :barcodes_text, faculty_sponsor_ids: [], diff --git a/app/models/location_report/location_report_form.rb b/app/models/location_report/location_report_form.rb index e501629a42..b18dbf62b8 100644 --- a/app/models/location_report/location_report_form.rb +++ b/app/models/location_report/location_report_form.rb @@ -10,7 +10,7 @@ class LocationReport::LocationReportForm include ActiveModel::AttributeMethods # Attributes - attr_accessor :user, :report_type, :faculty_sponsor_ids, :study_id, :start_date, :end_date, :plate_purpose_ids + attr_accessor :user, :report_type, :faculty_sponsor_ids, :study_id, :start_date, :end_date, :retention_instructions, :plate_purpose_ids attr_accessor :barcodes_text attr_reader :name, :location_barcode @@ -43,6 +43,7 @@ def location_report study_id: study_id, start_date: start_date&.to_datetime, end_date: end_date&.to_datetime, + retention_instructions: retention_instructions, plate_purpose_ids: plate_purpose_ids, barcodes: barcodes ) diff --git a/app/views/location_reports/_location_labware_selection_form.html.erb b/app/views/location_reports/_location_labware_selection_form.html.erb index 72f7c6fe80..af4f0c4392 100644 --- a/app/views/location_reports/_location_labware_selection_form.html.erb +++ b/app/views/location_reports/_location_labware_selection_form.html.erb @@ -31,6 +31,11 @@ +
+ <%= f.label 'retention_instructions', 'Retention instructions' %> + <%= f.select :retention_instructions, options_for_select(Purpose.alphabetical.pluck(:name, :id), location_report_form.retention_instructions), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %> +
+
<%= 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 } %> From e446636253ef30805d00a3b5f3b38af0cb9e1107 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Mon, 23 Mar 2026 12:04:30 +0000 Subject: [PATCH 02/19] save change --- .../location_reports/_location_labware_selection_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/location_reports/_location_labware_selection_form.html.erb b/app/views/location_reports/_location_labware_selection_form.html.erb index af4f0c4392..cc793dd329 100644 --- a/app/views/location_reports/_location_labware_selection_form.html.erb +++ b/app/views/location_reports/_location_labware_selection_form.html.erb @@ -33,7 +33,7 @@
<%= f.label 'retention_instructions', 'Retention instructions' %> - <%= f.select :retention_instructions, options_for_select(Purpose.alphabetical.pluck(:name, :id), location_report_form.retention_instructions), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %> + <%= f.select :retention_instructions, options_for_select(Labware.distinct.pluck(:retention_instruction), location_report_form.retention_instructions), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %>
From 99653c3b2ed1ed742aa7820cf3e343e6c1afc423 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Mon, 23 Mar 2026 19:06:45 +0000 Subject: [PATCH 03/19] remove retention instruction param --- app/controllers/location_reports_controller.rb | 1 - .../location_reports/_location_labware_selection_form.html.erb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/location_reports_controller.rb b/app/controllers/location_reports_controller.rb index cd487c9604..5f49df9c1e 100644 --- a/app/controllers/location_reports_controller.rb +++ b/app/controllers/location_reports_controller.rb @@ -60,7 +60,6 @@ def location_report_params # rubocop:todo Metrics/MethodLength :study_id, :start_date, :end_date, - :retention_instructions, :barcodes, :barcodes_text, faculty_sponsor_ids: [], diff --git a/app/views/location_reports/_location_labware_selection_form.html.erb b/app/views/location_reports/_location_labware_selection_form.html.erb index cc793dd329..7378ed111e 100644 --- a/app/views/location_reports/_location_labware_selection_form.html.erb +++ b/app/views/location_reports/_location_labware_selection_form.html.erb @@ -33,7 +33,7 @@
<%= f.label 'retention_instructions', 'Retention instructions' %> - <%= f.select :retention_instructions, options_for_select(Labware.distinct.pluck(:retention_instruction), location_report_form.retention_instructions), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %> + <%= 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 } %>
From 67bc87f26c074ac482f8dbc5299604cc7e7d4dd6 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Wed, 25 Mar 2026 14:46:20 +0000 Subject: [PATCH 04/19] save changes --- app/controllers/location_reports_controller.rb | 1 + app/models/labware.rb | 11 +++++++++++ app/models/location_report.rb | 8 ++++---- app/models/location_report/location_report_form.rb | 4 ++-- ...7_add_retention_instructions_to_lcation_reports.rb | 5 +++++ db/schema.rb | 4 +++- 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb diff --git a/app/controllers/location_reports_controller.rb b/app/controllers/location_reports_controller.rb index 5f49df9c1e..a8716857d9 100644 --- a/app/controllers/location_reports_controller.rb +++ b/app/controllers/location_reports_controller.rb @@ -62,6 +62,7 @@ def location_report_params # rubocop:todo Metrics/MethodLength :end_date, :barcodes, :barcodes_text, + retention_instructions: [], faculty_sponsor_ids: [], plate_purpose_ids: [] ) diff --git a/app/models/labware.rb b/app/models/labware.rb index dc8aa19dd7..66fdf69438 100644 --- a/app/models/labware.rb +++ b/app/models/labware.rb @@ -142,6 +142,15 @@ def receptacle_proxy end } + scope :filter_by_retention_instructions, + lambda { |retention_instructions| + if retention_instructions.blank? + all + else + where(retention_instruction: retention_instructions) + end + } + scope :source_assets_from_machine_barcode, lambda { |destination_barcode| destination_asset = find_by_barcode(destination_barcode) @@ -160,6 +169,7 @@ def self.search_for_labware(params) .with_plate_purpose_ids(params[:plate_purpose_ids] || nil) .created_between(params[:start_date], params[:end_date]) .filter_by_barcode(params[:barcodes] || nil) + .filter_by_retention_instructions(params[:retention_instructions] || nil) .distinct end @@ -169,6 +179,7 @@ def self.search_for_count_of_labware(params) .with_plate_purpose_ids(params[:plate_purpose_ids] || nil) .created_between(params[:start_date], params[:end_date]) .filter_by_barcode(params[:barcodes] || nil) + .filter_by_retention_instructions(params[:retention_instructions] || nil) .distinct .count end diff --git a/app/models/location_report.rb b/app/models/location_report.rb index bb39e0f675..f3264fb8ab 100644 --- a/app/models/location_report.rb +++ b/app/models/location_report.rb @@ -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,14 @@ 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: } 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) } + labwares = Labware.search_for_labware(params).filter { |labware| labware.is_a?(Plate) || labware.is_a?(Tube) } end def search_for_labware_by_labwhere_locn_bc diff --git a/app/models/location_report/location_report_form.rb b/app/models/location_report/location_report_form.rb index b18dbf62b8..97f7c76d2c 100644 --- a/app/models/location_report/location_report_form.rb +++ b/app/models/location_report/location_report_form.rb @@ -43,9 +43,9 @@ def location_report study_id: study_id, start_date: start_date&.to_datetime, end_date: end_date&.to_datetime, - retention_instructions: retention_instructions, plate_purpose_ids: plate_purpose_ids, - barcodes: barcodes + barcodes: barcodes, + retention_instructions: retention_instructions ) end diff --git a/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb b/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb new file mode 100644 index 0000000000..41626ea04d --- /dev/null +++ b/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb @@ -0,0 +1,5 @@ +class AddRetentionInstructionsToLcationReports < ActiveRecord::Migration[7.2] + def change + add_column :location_reports, :retention_instructions, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 86b570b4f7..b04d2e0426 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2025_11_20_204342) do +ActiveRecord::Schema[7.2].define(version: 2026_03_25_134057) do create_table "accession_sample_statuses", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "sample_id", null: false t.string "status", null: false @@ -592,6 +592,7 @@ t.datetime "updated_at", precision: nil, null: false t.integer "retention_instruction" t.index ["labware_type_id"], name: "fk_rails_32b35f8bf9" + t.index ["name"], name: "index_labware_on_name" t.index ["plate_purpose_id"], name: "fk_rails_745455e964" t.index ["sti_type", "plate_purpose_id"], name: "index_labware_on_sti_type_and_plate_purpose_id" t.index ["sti_type", "updated_at"], name: "index_labware_on_sti_type_and_updated_at" @@ -636,6 +637,7 @@ t.string "report_filename" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false + t.text "retention_instructions" t.index ["study_id"], name: "index_location_reports_on_study_id" t.index ["user_id"], name: "index_location_reports_on_user_id" end From fc408a129d31872792e8cacd9e89428fe47794ab Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Thu, 26 Mar 2026 18:37:22 +0000 Subject: [PATCH 05/19] save changes --- app/models/labware.rb | 11 ----------- app/models/location_report.rb | 16 ++++++++++++++-- .../location_report/location_report_form.rb | 3 ++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/models/labware.rb b/app/models/labware.rb index 66fdf69438..dc8aa19dd7 100644 --- a/app/models/labware.rb +++ b/app/models/labware.rb @@ -142,15 +142,6 @@ def receptacle_proxy end } - scope :filter_by_retention_instructions, - lambda { |retention_instructions| - if retention_instructions.blank? - all - else - where(retention_instruction: retention_instructions) - end - } - scope :source_assets_from_machine_barcode, lambda { |destination_barcode| destination_asset = find_by_barcode(destination_barcode) @@ -169,7 +160,6 @@ def self.search_for_labware(params) .with_plate_purpose_ids(params[:plate_purpose_ids] || nil) .created_between(params[:start_date], params[:end_date]) .filter_by_barcode(params[:barcodes] || nil) - .filter_by_retention_instructions(params[:retention_instructions] || nil) .distinct end @@ -179,7 +169,6 @@ def self.search_for_count_of_labware(params) .with_plate_purpose_ids(params[:plate_purpose_ids] || nil) .created_between(params[:start_date], params[:end_date]) .filter_by_barcode(params[:barcodes] || nil) - .filter_by_retention_instructions(params[:retention_instructions] || nil) .distinct .count end diff --git a/app/models/location_report.rb b/app/models/location_report.rb index f3264fb8ab..4bde0cecd4 100644 --- a/app/models/location_report.rb +++ b/app/models/location_report.rb @@ -9,7 +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 + serialize :retention_instructions, type: Array, coder: YAML self.per_page = 20 enum :report_type, { type_selection: 0, type_labwhere: 1 } @@ -176,7 +176,8 @@ 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:, retention_instructions: } + params = { faculty_sponsor_ids:, study_id:, start_date:, end_date:, plate_purpose_ids:, barcodes:, + retention_instructions: } 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:)) @@ -184,6 +185,13 @@ def search_for_labware_by_selection end # 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) } + + # add filtering by retention instructions + return labwares if retention_instructions.blank? + + labwares.select do |lw| + retention_instructions.include?(normalize_retention_instruction(lw.retention_instructions)) + end end def search_for_labware_by_labwhere_locn_bc @@ -208,5 +216,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 diff --git a/app/models/location_report/location_report_form.rb b/app/models/location_report/location_report_form.rb index 97f7c76d2c..c016e8d760 100644 --- a/app/models/location_report/location_report_form.rb +++ b/app/models/location_report/location_report_form.rb @@ -10,7 +10,8 @@ class LocationReport::LocationReportForm include ActiveModel::AttributeMethods # Attributes - attr_accessor :user, :report_type, :faculty_sponsor_ids, :study_id, :start_date, :end_date, :retention_instructions, :plate_purpose_ids + attr_accessor :user, :report_type, :faculty_sponsor_ids, :study_id, :start_date, :end_date, :retention_instructions, + :plate_purpose_ids attr_accessor :barcodes_text attr_reader :name, :location_barcode From 31159ad4b0f71019d5148bb6c31f05abd81aab85 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Thu, 26 Mar 2026 23:02:50 +0000 Subject: [PATCH 06/19] refactor --- app/models/location_report.rb | 20 +++++++++++++------ ...tention_instructions_to_lcation_reports.rb | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/models/location_report.rb b/app/models/location_report.rb index 4bde0cecd4..4c20715116 100644 --- a/app/models/location_report.rb +++ b/app/models/location_report.rb @@ -178,15 +178,15 @@ def generate_study_cols_for_row(cur_study) def search_for_labware_by_selection params = { faculty_sponsor_ids:, study_id:, start_date:, end_date:, plate_purpose_ids:, barcodes:, retention_instructions: } - 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 + 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) } - # add filtering by retention instructions + filter_labware_by_retention_instructions(labwares) + end + + def filter_labware_by_retention_instructions(labwares) return labwares if retention_instructions.blank? labwares.select do |lw| @@ -194,6 +194,14 @@ def search_for_labware_by_selection 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:)) + [] + end + end + def search_for_labware_by_labwhere_locn_bc @labware_barcodes = [] begin diff --git a/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb b/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb index 41626ea04d..a79f225df5 100644 --- a/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb +++ b/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class AddRetentionInstructionsToLcationReports < ActiveRecord::Migration[7.2] def change add_column :location_reports, :retention_instructions, :text From 77a9e0400f04c9cdab8d9454ed0a54184b27119d Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 27 Mar 2026 13:06:29 +0000 Subject: [PATCH 07/19] add tests --- spec/models/location_report_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index 4af5d8f946..b7258684b9 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -145,7 +145,8 @@ start_date:, end_date:, plate_purpose_ids:, - barcodes: + barcodes:, + retention_instructions: ) end let(:report_type) { nil } @@ -157,6 +158,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 @@ -473,6 +475,24 @@ it_behaves_like 'a successful report' end + + context 'with retention instructions' do + let(:start_date) { '2016-01-01 00:00:00' } + let(:end_date) { '2016-11-01 00:00:00' } + let(:retention_instructions) { ['long_term_storage'] } + + # 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 end context 'by labwhere location' do From a2a99120cec41a3cf5fa479ef42ba6c34349cef4 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 27 Mar 2026 13:30:05 +0000 Subject: [PATCH 08/19] fix the typo --- ...60325134057_add_retention_instructions_to_lcation_reports.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb b/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb index a79f225df5..7152b2b86a 100644 --- a/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb +++ b/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class AddRetentionInstructionsToLcationReports < ActiveRecord::Migration[7.2] +class AddRetentionInstructionsToLocationReports < ActiveRecord::Migration[7.2] def change add_column :location_reports, :retention_instructions, :text end From 7e4e26f6fe8f4548adf94cbe5fc62b90c020d25f Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 27 Mar 2026 13:38:49 +0000 Subject: [PATCH 09/19] fix the typo --- ...60325134057_add_retention_instructions_to_location_reports.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/migrate/{20260325134057_add_retention_instructions_to_lcation_reports.rb => 20260325134057_add_retention_instructions_to_location_reports.rb} (100%) diff --git a/db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb b/db/migrate/20260325134057_add_retention_instructions_to_location_reports.rb similarity index 100% rename from db/migrate/20260325134057_add_retention_instructions_to_lcation_reports.rb rename to db/migrate/20260325134057_add_retention_instructions_to_location_reports.rb From 8a8178f0d6932db97db83d4cf4cdc96eb12463f6 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 10 Apr 2026 08:55:32 +0100 Subject: [PATCH 10/19] refactor test --- spec/models/location_report_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index b7258684b9..a72bddd884 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -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_2 ) 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 @@ -479,7 +480,7 @@ context 'with retention instructions' do let(:start_date) { '2016-01-01 00:00:00' } let(:end_date) { '2016-11-01 00:00:00' } - let(:retention_instructions) { ['long_term_storage'] } + let(:retention_instructions) { ['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 From 81e643cf33ab1f679b3ae4ba753a66fba025b48b Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 10 Apr 2026 16:36:49 +0100 Subject: [PATCH 11/19] update the new column type --- ...325134057_add_retention_instructions_to_location_reports.rb | 2 +- db/schema.rb | 2 +- spec/models/location_report_spec.rb | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/db/migrate/20260325134057_add_retention_instructions_to_location_reports.rb b/db/migrate/20260325134057_add_retention_instructions_to_location_reports.rb index 7152b2b86a..60ad428001 100644 --- a/db/migrate/20260325134057_add_retention_instructions_to_location_reports.rb +++ b/db/migrate/20260325134057_add_retention_instructions_to_location_reports.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true class AddRetentionInstructionsToLocationReports < ActiveRecord::Migration[7.2] def change - add_column :location_reports, :retention_instructions, :text + add_column :location_reports, :retention_instructions, :string end end diff --git a/db/schema.rb b/db/schema.rb index b04d2e0426..179ab7a596 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -637,7 +637,7 @@ t.string "report_filename" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.text "retention_instructions" + t.string "retention_instructions" t.index ["study_id"], name: "index_location_reports_on_study_id" t.index ["user_id"], name: "index_location_reports_on_user_id" end diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index a72bddd884..11658d2401 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -480,8 +480,7 @@ context 'with retention instructions' do let(:start_date) { '2016-01-01 00:00:00' } let(:end_date) { '2016-11-01 00:00:00' } - let(:retention_instructions) { ['long_term_storage'],['return_to_customer_after_2_years'] } - + 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 [ From ef88f723b7a326e8f1521118c07c4760527a69d9 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 10 Apr 2026 16:52:51 +0100 Subject: [PATCH 12/19] fix the test --- spec/models/location_report_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index 11658d2401..f09791efd8 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -247,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 @@ -262,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 @@ -523,7 +523,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] } @@ -550,7 +550,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 @@ -565,7 +565,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] } @@ -627,7 +627,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 @@ -695,7 +695,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}" @@ -704,10 +704,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 From 9b13bb4f647b6f4a38cdd599e6ab0c21214ca939 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Fri, 10 Apr 2026 21:09:51 +0100 Subject: [PATCH 13/19] fix tests --- spec/models/location_report_spec.rb | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index f09791efd8..def624c6b9 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -90,7 +90,7 @@ :custom_metadatum, custom_metadatum_collection: plate_3_custom_metadatum_collection, key: retention_key, - value: retention_value_2 + value: retention_value_1 ) end @@ -493,6 +493,35 @@ 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 From 1f6391366fbde0b806d8a4e80ee372b762820bc0 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Tue, 5 May 2026 13:06:21 +0100 Subject: [PATCH 14/19] move filter in the scope --- app/controllers/location_reports_controller.rb | 2 -- app/models/labware.rb | 13 +++++++++++++ app/models/location_report.rb | 16 +--------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/controllers/location_reports_controller.rb b/app/controllers/location_reports_controller.rb index a8716857d9..96bfe28a0d 100644 --- a/app/controllers/location_reports_controller.rb +++ b/app/controllers/location_reports_controller.rb @@ -60,8 +60,6 @@ def location_report_params # rubocop:todo Metrics/MethodLength :study_id, :start_date, :end_date, - :barcodes, - :barcodes_text, retention_instructions: [], faculty_sponsor_ids: [], plate_purpose_ids: [] diff --git a/app/models/labware.rb b/app/models/labware.rb index bbcfb32bf3..c08689f9f9 100644 --- a/app/models/labware.rb +++ b/app/models/labware.rb @@ -155,12 +155,21 @@ def receptacle_proxy } # Used for location report + def self.map_retention_instructions(values) + return if values.blank? + + values.filter_map { |v| Labware.retention_instructions[v] } + end + def self.search_for_labware(params) with_faculty_sponsor_ids(params[:faculty_sponsor_ids] || nil) .with_study_id(params[:study_id] || nil) .with_plate_purpose_ids(params[:plate_purpose_ids] || nil) .created_between(params[:start_date], params[:end_date]) .filter_by_barcode(params[:barcodes] || nil) + .with_retention_instructions( + map_retention_instructions(params[:retention_instructions]) + ) .distinct end @@ -186,6 +195,10 @@ def self.search_for_count_of_labware(params) scope :with_plate_purpose_ids, ->(plate_purpose_ids) { where(plate_purpose_id: plate_purpose_ids) if plate_purpose_ids.present? } + scope :with_retention_instructions, ->(retention_instructions) { + where(retention_instruction: retention_instructions) if retention_instructions.present? + } + scope :created_between, ->(start_date, end_date) do where(created_at: (start_date.midnight..(end_date || Time.current).end_of_day)) if start_date.present? diff --git a/app/models/location_report.rb b/app/models/location_report.rb index 4c20715116..effa458602 100644 --- a/app/models/location_report.rb +++ b/app/models/location_report.rb @@ -181,17 +181,7 @@ def search_for_labware_by_selection 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) - 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 + Labware.search_for_labware(params).filter { |labware| labware.is_a?(Plate) || labware.is_a?(Tube) } end def validate_result_size(params) @@ -224,9 +214,5 @@ 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 From 2b9a0cfcf731d5cfad1dd2c523d469325ac2837c Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Tue, 5 May 2026 20:41:51 +0100 Subject: [PATCH 15/19] refactor search_for_labware_by_selection --- app/models/location_report.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/models/location_report.rb b/app/models/location_report.rb index effa458602..1404fe204c 100644 --- a/app/models/location_report.rb +++ b/app/models/location_report.rb @@ -175,21 +175,17 @@ def generate_study_cols_for_row(cur_study) cols << (cur_study.study_metadata.faculty_sponsor&.name || 'Unknown') end - def search_for_labware_by_selection + def search_for_labware_by_selection # rubocop:todo Metrics/AbcSize 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 - Labware.search_for_labware(params).filter { |labware| labware.is_a?(Plate) || labware.is_a?(Tube) } - 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 def search_for_labware_by_labwhere_locn_bc From b572c92f199498941c860e402c642a2ad6ca8681 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Tue, 5 May 2026 21:56:20 +0100 Subject: [PATCH 16/19] fix the test --- spec/models/location_report_spec.rb | 75 ++++++++--------------------- 1 file changed, 21 insertions(+), 54 deletions(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index def624c6b9..b1ee4e86b0 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -44,19 +44,10 @@ let(:plt_1_created) { plate_1.created_at.strftime('%Y-%m-%d %H:%M:%S') } let(:plt_1_received_date) { plt_1_asset_audit.created_at.strftime('%Y-%m-%d %H:%M:%S') } - # add retention instruction metadata to plate 1 custom metadatum collection - let(:retention_key) { 'retention_instruction' } - 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_1 - ) - end + # use the labware retention_instruction enum column directly + let(:retention_value_1) { 'long_term_storage' } + let(:retention_value_2) { 'return_to_customer_after_2_years' } + let(:plate_1_retention_instruction) { plate_1.update!(retention_instruction: :long_term_storage) } let(:plate_2) do create( @@ -83,16 +74,7 @@ let(:plt_3_created) { plate_3.created_at.strftime('%Y-%m-%d %H:%M:%S') } let(:plt_3_received_date) { 'Unknown' } - # add retention instruction metadata to plate 3 custom metadatum collection - let(:plate_3_custom_metadatum_collection) { create(:custom_metadatum_collection, asset: plate_3, user: user) } - let(:plate_3_custom_metadatum) do - create( - :custom_metadatum, - custom_metadatum_collection: plate_3_custom_metadatum_collection, - key: retention_key, - value: retention_value_1 - ) - end + let(:plate_3_retention_instruction) { plate_3.update!(retention_instruction: :long_term_storage) } let(:tube_1) do create( @@ -105,15 +87,7 @@ let(:tube_1_purpose) { tube_1.purpose.name } let(:tube_1_created) { tube_1.created_at.strftime('%Y-%m-%d %H:%M:%S') } let(:tube_1_received_date) { 'Unknown' } - let(:tube_1_custom_metadatum_collection) { create(:custom_metadatum_collection, asset: tube_1, user: user) } - let(:tube_1_custom_metadatum) do - create( - :custom_metadatum, - custom_metadatum_collection: tube_1_custom_metadatum_collection, - key: retention_key, - value: retention_value_1 - ) - end + let(:tube_1_retention_instruction) { tube_1.update!(retention_instruction: :long_term_storage) } let(:tube_rack) { create(:tube_rack, size: 96) } @@ -229,7 +203,7 @@ shared_examples 'a successful report' do it 'generates the expected report rows' do expect(location_report.save).to be_truthy - + lines = [] location_report.generate_report_rows { |fields| lines.push(fields.join(',')) } @@ -283,9 +257,9 @@ stub_lwclient_labware_find_by_bc(lw_barcode:, lw_locn_name:, lw_locn_parentage:) end - plate_1_custom_metadatum - plate_3_custom_metadatum - tube_1_custom_metadatum + plate_1_retention_instruction + plate_3_retention_instruction + tube_1_retention_instruction end context 'dates only' do @@ -481,7 +455,7 @@ 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 + # Only plate_1, plate_3, and tube_1 have retention instructions set let(:expected_lines) do [ headers_line, @@ -498,14 +472,7 @@ 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(:plate_3_retention_instruction) { plate_3.update!(retention_instruction: :return_to_customer_after_2_years) } 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}" @@ -541,8 +508,8 @@ stub_lwclient_locn_children(location_barcode, []) stub_lwclient_locn_labwares(location_barcode, []) - plate_1_custom_metadatum - plate_3_custom_metadatum + plate_1_retention_instruction + plate_3_retention_instruction end it_behaves_like 'a successful report' @@ -569,7 +536,7 @@ stub_lwclient_locn_labwares(location_barcode, [p1]) stub_lwclient_labware_find_by_bc(p1) - plate_1_custom_metadatum + plate_1_retention_instruction end it_behaves_like 'a successful report' @@ -645,8 +612,8 @@ stub_lwclient_labware_find_by_bc(p2) stub_lwclient_labware_find_by_bc(t1) - plate_1_custom_metadatum - tube_1_custom_metadatum + plate_1_retention_instruction + tube_1_retention_instruction end it_behaves_like 'a successful report' @@ -713,7 +680,7 @@ stub_lwclient_locn_labwares(locn_lvl2_b2[:locn_barcode], [p2]) stub_lwclient_labware_find_by_bc(p2) - plate_1_custom_metadatum + plate_1_retention_instruction end it_behaves_like 'a successful report' @@ -793,9 +760,9 @@ stub_lwclient_labware_find_by_bc(p3) stub_lwclient_labware_find_by_bc(t1) - plate_1_custom_metadatum - plate_3_custom_metadatum - tube_1_custom_metadatum + plate_1_retention_instruction + plate_3_retention_instruction + tube_1_retention_instruction end it_behaves_like 'a successful report' From eab5820582c567d87616f77bcf105036f5455871 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Tue, 5 May 2026 21:59:12 +0100 Subject: [PATCH 17/19] fix linting --- spec/models/location_report_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index b1ee4e86b0..7a43ad6bac 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -203,7 +203,7 @@ shared_examples 'a successful report' do it 'generates the expected report rows' do expect(location_report.save).to be_truthy - + lines = [] location_report.generate_report_rows { |fields| lines.push(fields.join(',')) } @@ -472,7 +472,9 @@ 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_retention_instruction) { plate_3.update!(retention_instruction: :return_to_customer_after_2_years) } + let(:plate_3_retention_instruction) do + plate_3.update!(retention_instruction: :return_to_customer_after_2_years) + 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}" From d233cf9f414e2a60cb4da82dd0c362ff96fbac14 Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Thu, 7 May 2026 16:30:43 +0100 Subject: [PATCH 18/19] refactor the tests --- spec/models/location_report_spec.rb | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index 7a43ad6bac..c88237b443 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -45,9 +45,9 @@ let(:plt_1_received_date) { plt_1_asset_audit.created_at.strftime('%Y-%m-%d %H:%M:%S') } # use the labware retention_instruction enum column directly - let(:retention_value_1) { 'long_term_storage' } - let(:retention_value_2) { 'return_to_customer_after_2_years' } - let(:plate_1_retention_instruction) { plate_1.update!(retention_instruction: :long_term_storage) } + let(:retention_value_long_term) { 'long_term_storage' } + let(:retention_value_return_after_two_years) { 'return_to_customer_after_2_years' } + let(:plate_1_set_long_term_storage) { plate_1.update!(retention_instruction: :long_term_storage) } let(:plate_2) do create( @@ -74,7 +74,7 @@ let(:plt_3_created) { plate_3.created_at.strftime('%Y-%m-%d %H:%M:%S') } let(:plt_3_received_date) { 'Unknown' } - let(:plate_3_retention_instruction) { plate_3.update!(retention_instruction: :long_term_storage) } + let(:plate_3_return_customer) { plate_3.update!(retention_instruction: :return_to_customer_after_2_years) } let(:tube_1) do create( @@ -87,7 +87,7 @@ let(:tube_1_purpose) { tube_1.purpose.name } let(:tube_1_created) { tube_1.created_at.strftime('%Y-%m-%d %H:%M:%S') } let(:tube_1_received_date) { 'Unknown' } - let(:tube_1_retention_instruction) { tube_1.update!(retention_instruction: :long_term_storage) } + let(:tube_1_set_long_term_storage) { tube_1.update!(retention_instruction: :long_term_storage) } let(:tube_rack) { create(:tube_rack, size: 96) } @@ -221,7 +221,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_1},#{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_long_term},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" # rubocop:enable Layout/LineLength end let(:plt_2_line_1) do @@ -236,12 +236,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_1},#{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_return_after_two_years},#{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_1},#{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_long_term},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" # rubocop:enable Layout/LineLength end @@ -257,9 +257,9 @@ stub_lwclient_labware_find_by_bc(lw_barcode:, lw_locn_name:, lw_locn_parentage:) end - plate_1_retention_instruction - plate_3_retention_instruction - tube_1_retention_instruction + plate_1_set_long_term_storage + plate_3_return_customer + tube_1_set_long_term_storage end context 'dates only' do @@ -454,13 +454,13 @@ context 'with retention instructions' 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] } - # Only plate_1, plate_3, and tube_1 have retention instructions set + let(:retention_instructions) { %w[long_term_storage] } + # Only plate_1, tube_1 have retention instructions set longterm_storage, + # plate_3 is set to return_to_customer_after_2_years so should not be included let(:expected_lines) do [ headers_line, plt_1_line, - plt_3_line, tube_1_line ] end @@ -472,12 +472,12 @@ 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_retention_instruction) do + let(:plate_3_return_customer) do plate_3.update!(retention_instruction: :return_to_customer_after_2_years) 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}" + "#{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_return_after_two_years},#{study_2.name},#{study_2.id},#{study_2_sponsor.name}" # rubocop:enable Layout/LineLength end let(:expected_lines) do @@ -510,8 +510,8 @@ stub_lwclient_locn_children(location_barcode, []) stub_lwclient_locn_labwares(location_barcode, []) - plate_1_retention_instruction - plate_3_retention_instruction + plate_1_set_long_term_storage + plate_3_return_customer end it_behaves_like 'a successful report' @@ -521,7 +521,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_1},#{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_long_term},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" # rubocop:enable Layout/LineLength end let(:expected_lines) { [headers_line, plt_1_line] } @@ -538,7 +538,7 @@ stub_lwclient_locn_labwares(location_barcode, [p1]) stub_lwclient_labware_find_by_bc(p1) - plate_1_retention_instruction + plate_1_set_long_term_storage end it_behaves_like 'a successful report' @@ -548,7 +548,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_1},#{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_long_term},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" # rubocop:enable Layout/LineLength end let(:plt_2_line_1) do @@ -563,7 +563,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_1},#{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_long_term},#{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] } @@ -614,8 +614,8 @@ stub_lwclient_labware_find_by_bc(p2) stub_lwclient_labware_find_by_bc(t1) - plate_1_retention_instruction - tube_1_retention_instruction + plate_1_set_long_term_storage + tube_1_set_long_term_storage end it_behaves_like 'a successful report' @@ -625,7 +625,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_1},#{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_long_term},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" # rubocop:enable Layout/LineLength end let(:plt_2_line_1) do @@ -682,7 +682,7 @@ stub_lwclient_locn_labwares(locn_lvl2_b2[:locn_barcode], [p2]) stub_lwclient_labware_find_by_bc(p2) - plate_1_retention_instruction + plate_1_set_long_term_storage end it_behaves_like 'a successful report' @@ -693,7 +693,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_1},#{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_long_term},#{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}" @@ -702,10 +702,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_1},#{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_return_after_two_years},#{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_1},#{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_long_term},#{study_1.name},#{study_1.id},#{study_1_sponsor.name}" end # rubocop:enable Layout/LineLength @@ -762,9 +762,9 @@ stub_lwclient_labware_find_by_bc(p3) stub_lwclient_labware_find_by_bc(t1) - plate_1_retention_instruction - plate_3_retention_instruction - tube_1_retention_instruction + plate_1_set_long_term_storage + plate_3_return_customer + tube_1_set_long_term_storage end it_behaves_like 'a successful report' From b91b6cae2bdb095c8292ed3acd32c3a13fbb421f Mon Sep 17 00:00:00 2001 From: Wendy Yang Date: Thu, 7 May 2026 21:09:21 +0100 Subject: [PATCH 19/19] rename the plate_3_return_customer --- spec/models/location_report_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/models/location_report_spec.rb b/spec/models/location_report_spec.rb index c88237b443..cec00c5b81 100644 --- a/spec/models/location_report_spec.rb +++ b/spec/models/location_report_spec.rb @@ -74,7 +74,7 @@ let(:plt_3_created) { plate_3.created_at.strftime('%Y-%m-%d %H:%M:%S') } let(:plt_3_received_date) { 'Unknown' } - let(:plate_3_return_customer) { plate_3.update!(retention_instruction: :return_to_customer_after_2_years) } + let(:plate_3_return_after_two_years) { plate_3.update!(retention_instruction: :return_to_customer_after_2_years) } let(:tube_1) do create( @@ -258,7 +258,7 @@ end plate_1_set_long_term_storage - plate_3_return_customer + plate_3_return_after_two_years tube_1_set_long_term_storage end @@ -472,7 +472,7 @@ 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_return_customer) do + let(:plate_3_return_after_two_years) do plate_3.update!(retention_instruction: :return_to_customer_after_2_years) end let(:plt_3_line) do @@ -511,7 +511,7 @@ stub_lwclient_locn_labwares(location_barcode, []) plate_1_set_long_term_storage - plate_3_return_customer + plate_3_return_after_two_years end it_behaves_like 'a successful report' @@ -763,7 +763,7 @@ stub_lwclient_labware_find_by_bc(t1) plate_1_set_long_term_storage - plate_3_return_customer + plate_3_return_after_two_years tube_1_set_long_term_storage end