From 35f79795d4f5d5f4e77a2de79a1b21a221e79cf7 Mon Sep 17 00:00:00 2001 From: Sebastian Diaz Date: Fri, 17 Jan 2025 16:35:50 +0100 Subject: [PATCH] remove directory for balsamic specific rules --- .../validation/rules/case_sample/rules.py | 19 +++++++++++++++++++ .../validation/rules/case_sample/utils.py | 13 +++++++++++++ .../validation/workflows/balsamic/__init__.py | 0 .../validation/workflows/balsamic/rules.py | 16 ---------------- .../validation/workflows/balsamic/utils.py | 13 ------------- .../workflows/balsamic/validation_rules.py | 4 +--- .../workflows/balsamic/test_rules.py | 6 +++--- 7 files changed, 36 insertions(+), 35 deletions(-) delete mode 100644 cg/services/orders/validation/workflows/balsamic/__init__.py delete mode 100644 cg/services/orders/validation/workflows/balsamic/rules.py delete mode 100644 cg/services/orders/validation/workflows/balsamic/utils.py diff --git a/cg/services/orders/validation/rules/case_sample/rules.py b/cg/services/orders/validation/rules/case_sample/rules.py index edb355b6f8..65e8de98dc 100644 --- a/cg/services/orders/validation/rules/case_sample/rules.py +++ b/cg/services/orders/validation/rules/case_sample/rules.py @@ -8,6 +8,7 @@ ApplicationNotCompatibleError, ApplicationNotValidError, BufferMissingError, + CaptureKitMissingError, ConcentrationRequiredIfSkipRCError, ContainerNameMissingError, ContainerNameRepeatedError, @@ -52,6 +53,7 @@ is_concentration_missing, is_container_name_missing, is_invalid_plate_well_format, + is_sample_missing_capture_kit, is_sample_tube_name_reused, is_well_position_missing, validate_concentration_in_case, @@ -62,6 +64,7 @@ is_volume_invalid, is_volume_missing, ) +from cg.services.orders.validation.workflows.balsamic.models.order import BalsamicOrder from cg.store.models import Sample as DbSample from cg.store.store import Store @@ -438,3 +441,19 @@ def validate_buffer_required(order: OrderWithCases, **kwargs) -> list[BufferMiss error = BufferMissingError(case_index=case_index, sample_index=sample_index) errors.append(error) return errors + + +def validate_capture_kit_panel_requirement( + order: BalsamicOrder, store: Store +) -> list[CaptureKitMissingError]: + """ + Return an error for each new sample missing a capture kit, if its application requires one. + Applicable to Balsamic orders only. + """ + errors: list[CaptureKitMissingError] = [] + for case_index, case in order.enumerated_new_cases: + for sample_index, sample in case.enumerated_new_samples: + if is_sample_missing_capture_kit(sample=sample, store=store): + error = CaptureKitMissingError(case_index=case_index, sample_index=sample_index) + errors.append(error) + return errors diff --git a/cg/services/orders/validation/rules/case_sample/utils.py b/cg/services/orders/validation/rules/case_sample/utils.py index adedd92b5e..f0e1216218 100644 --- a/cg/services/orders/validation/rules/case_sample/utils.py +++ b/cg/services/orders/validation/rules/case_sample/utils.py @@ -2,6 +2,7 @@ from collections import Counter from cg.constants.constants import StatusOptions +from cg.constants.sequencing import SeqLibraryPrepCategory from cg.constants.subject import Sex from cg.models.orders.sample_base import ContainerEnum, SexEnum from cg.services.orders.validation.errors.case_errors import RepeatedCaseNameError @@ -33,6 +34,8 @@ is_sample_on_plate, is_volume_within_allowed_interval, ) +from cg.services.orders.validation.workflows.balsamic.models.sample import BalsamicSample +from cg.store.models import Application from cg.store.store import Store @@ -283,3 +286,13 @@ def is_buffer_missing(sample: SampleInCase) -> bool: sample.application.startswith(tuple(applications_requiring_buffer)) and not sample.elution_buffer ) + + +def is_sample_missing_capture_kit(sample: BalsamicSample, store: Store) -> bool: + """Returns whether a TGS sample has an application and is missing a capture kit.""" + application: Application | None = store.get_application_by_tag(sample.application) + return ( + application + and application.prep_category == SeqLibraryPrepCategory.TARGETED_GENOME_SEQUENCING + and not sample.capture_kit + ) diff --git a/cg/services/orders/validation/workflows/balsamic/__init__.py b/cg/services/orders/validation/workflows/balsamic/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cg/services/orders/validation/workflows/balsamic/rules.py b/cg/services/orders/validation/workflows/balsamic/rules.py deleted file mode 100644 index 4c7d087772..0000000000 --- a/cg/services/orders/validation/workflows/balsamic/rules.py +++ /dev/null @@ -1,16 +0,0 @@ -from cg.services.orders.validation.errors.case_sample_errors import CaptureKitMissingError -from cg.services.orders.validation.workflows.balsamic.models.order import BalsamicOrder -from cg.services.orders.validation.workflows.balsamic.utils import is_sample_missing_capture_kit -from cg.store.store import Store - - -def validate_capture_kit_panel_requirement( - order: BalsamicOrder, store: Store -) -> list[CaptureKitMissingError]: - errors: list[CaptureKitMissingError] = [] - for case_index, case in order.enumerated_new_cases: - for sample_index, sample in case.enumerated_new_samples: - if is_sample_missing_capture_kit(sample=sample, store=store): - error = CaptureKitMissingError(case_index=case_index, sample_index=sample_index) - errors.append(error) - return errors diff --git a/cg/services/orders/validation/workflows/balsamic/utils.py b/cg/services/orders/validation/workflows/balsamic/utils.py deleted file mode 100644 index b097f03f40..0000000000 --- a/cg/services/orders/validation/workflows/balsamic/utils.py +++ /dev/null @@ -1,13 +0,0 @@ -from cg.constants.sequencing import SeqLibraryPrepCategory -from cg.services.orders.validation.workflows.balsamic.models.sample import BalsamicSample -from cg.store.models import Application -from cg.store.store import Store - - -def is_sample_missing_capture_kit(sample: BalsamicSample, store: Store) -> bool: - application: Application | None = store.get_application_by_tag(sample.application) - return ( - application - and application.prep_category == SeqLibraryPrepCategory.TARGETED_GENOME_SEQUENCING - and not sample.capture_kit - ) diff --git a/cg/services/orders/validation/workflows/balsamic/validation_rules.py b/cg/services/orders/validation/workflows/balsamic/validation_rules.py index 8851992bd3..6f62aa3a0b 100644 --- a/cg/services/orders/validation/workflows/balsamic/validation_rules.py +++ b/cg/services/orders/validation/workflows/balsamic/validation_rules.py @@ -11,6 +11,7 @@ validate_application_not_archived, validate_buffer_required, validate_buffer_skip_rc_condition, + validate_capture_kit_panel_requirement, validate_concentration_interval_if_skip_rc, validate_concentration_required_if_skip_rc, validate_container_name_required, @@ -27,9 +28,6 @@ validate_well_positions_required, validate_wells_contain_at_most_one_sample, ) -from cg.services.orders.validation.workflows.balsamic.rules import ( - validate_capture_kit_panel_requirement, -) BALSAMIC_CASE_RULES: list[callable] = [ validate_at_most_two_samples_per_case, diff --git a/tests/services/orders/validation_service/workflows/balsamic/test_rules.py b/tests/services/orders/validation_service/workflows/balsamic/test_rules.py index fd6a62de7e..d98e8e18ff 100644 --- a/tests/services/orders/validation_service/workflows/balsamic/test_rules.py +++ b/tests/services/orders/validation_service/workflows/balsamic/test_rules.py @@ -9,11 +9,11 @@ validate_at_most_two_samples_per_case, validate_number_of_normal_samples, ) -from cg.services.orders.validation.workflows.balsamic.models.order import BalsamicOrder -from cg.services.orders.validation.workflows.balsamic.models.sample import BalsamicSample -from cg.services.orders.validation.workflows.balsamic.rules import ( +from cg.services.orders.validation.rules.case_sample.rules import ( validate_capture_kit_panel_requirement, ) +from cg.services.orders.validation.workflows.balsamic.models.order import BalsamicOrder +from cg.services.orders.validation.workflows.balsamic.models.sample import BalsamicSample from cg.store.models import Application from cg.store.store import Store