Skip to content
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

Remove unnecessary rules #3664

Merged
merged 3 commits into from
Aug 29, 2024
Merged
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
10 changes: 0 additions & 10 deletions cg/services/order_validation_service/errors/case_sample_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class MotherNotInCaseError(CaseSampleError):
message: str = "Mother must be in the same case"


class StatusMissingError(CaseSampleError):
field: str = "status"
message: str = "Carrier status is required"


class SampleDoesNotExistError(CaseSampleError):
field: str = "internal_id"
message: str = "The sample does not exist"
Expand All @@ -94,11 +89,6 @@ class SexMissingError(CaseSampleError):
message: str = "Sex is required"


class SourceMissingError(CaseSampleError):
field: str = "source"
message: str = "Source is required"


class SubjectIdSameAsCaseNameError(CaseSampleError):
field: str = "subject_id"
message: str = "Subject id must be different from the case name"
Expand Down
10 changes: 0 additions & 10 deletions cg/services/order_validation_service/errors/sample_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ class OrganismDoesNotExistError(SampleError):
message: str = "Organism does not exist"


class ElutionBufferMissingError(SampleError):
field: str = "elution_buffer"
message: str = "Buffer is required"


class ExtractionMethodMissingError(SampleError):
field: str = "extraction_method"
message: str = "Extraction method is required"


class SampleNameNotAvailableError(SampleError):
field: str = "name"
message: str = "Sample name already used in previous order"
13 changes: 8 additions & 5 deletions cg/services/order_validation_service/models/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
from cg.services.order_validation_service.models.existing_sample import ExistingSample
from cg.services.order_validation_service.models.sample import Sample

NewSample = Annotated[Sample, Tag("new")]
ExistingSampleType = Annotated[ExistingSample, Tag("existing")]


class Case(BaseModel):
name: str = Field(pattern=NAME_PATTERN, min_length=2, max_length=128)
priority: PriorityTerms = PriorityTerms.STANDARD
samples: list[
Annotated[
Annotated[Sample, Tag("new")] | Annotated[ExistingSample, Tag("existing")],
NewSample | ExistingSampleType,
Discriminator(has_internal_id),
]
]

@property
def enumerated_samples(self):
return enumerate(self.samples)

@property
def is_new(self) -> bool:
return True

@property
def enumerated_samples(self):
return enumerate(self.samples)

@property
def enumerated_new_samples(self):
samples: list[tuple[int, Sample]] = []
Expand Down
22 changes: 0 additions & 22 deletions cg/services/order_validation_service/rules/case_sample/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
SampleDoesNotExistError,
SampleNameRepeatedError,
SexMissingError,
SourceMissingError,
StatusMissingError,
SubjectIdSameAsCaseNameError,
SubjectIdSameAsSampleNameError,
WellPositionMissingError,
Expand Down Expand Up @@ -232,16 +230,6 @@ def validate_sex_required_for_new_samples(order: OrderWithCases, **kwargs) -> li
return errors


def validate_source_required(order: OrderWithCases, **kwargs) -> list[SourceMissingError]:
errors: list[SourceMissingError] = []
for case_index, case in order.enumerated_new_cases:
for sample_index, sample in case.enumerated_new_samples:
if not sample.source:
error = SourceMissingError(case_index=case_index, sample_index=sample_index)
errors.append(error)
return errors


def validate_wells_contain_at_most_one_sample(
order: OrderWithCases, **kwargs
) -> list[OccupiedWellError]:
Expand Down Expand Up @@ -350,13 +338,3 @@ def validate_concentration_interval_if_skip_rc(
)
errors.extend(case_errors)
return errors


def validate_status_required_if_new(order: OrderWithCases, **kwargs) -> list[StatusMissingError]:
errors: list[StatusMissingError] = []
for case_index, case in order.enumerated_new_cases:
for sample_index, sample in case.enumerated_new_samples:
if not sample.status:
error = StatusMissingError(case_index=case_index, sample_index=sample_index)
errors.append(error)
return errors
25 changes: 0 additions & 25 deletions cg/services/order_validation_service/rules/sample/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
ApplicationArchivedError,
ApplicationNotCompatibleError,
ApplicationNotValidError,
ElutionBufferMissingError,
ExtractionMethodMissingError,
InvalidVolumeError,
OccupiedWellError,
OrganismDoesNotExistError,
Expand Down Expand Up @@ -68,29 +66,6 @@ def validate_organism_exists(
return errors


def validate_buffer_required(
order: OrderWithNonHumanSamples,
**kwargs,
) -> list[ElutionBufferMissingError]:
errors: list[ElutionBufferMissingError] = []
for sample_index, sample in order.enumerated_samples:
if not sample.elution_buffer:
error = ElutionBufferMissingError(sample_index=sample_index)
errors.append(error)
return errors


def validate_extraction_method_required(
order: OrderWithNonHumanSamples, **kwargs
) -> list[ExtractionMethodMissingError]:
errors: list[ExtractionMethodMissingError] = []
for sample_index, sample in order.enumerated_samples:
if not sample.extraction_method:
error = ExtractionMethodMissingError(sample_index=sample_index)
errors.append(error)
return errors


def validate_application_compatibility(
order: OrderWithNonHumanSamples,
store: Store,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

class MicrosaltSample(Sample):
control: ControlEnum | None = None
elution_buffer: str | None = None
extraction_method: ExtractionMethod | None = None
organism: str | None = None
priority: PriorityEnum | None = None
elution_buffer: str
extraction_method: ExtractionMethod
organism: str
priority: PriorityEnum
quantity: int | None = None
reference_genome: str | None = Field(default=None, max_length=255)
reference_genome: str = Field(max_length=255)
sample_concentration: float | None = None
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
validate_application_compatibility,
validate_application_exists,
validate_applications_not_archived,
validate_buffer_required,
validate_organism_exists,
validate_sample_names_available,
validate_sample_names_unique,
Expand All @@ -15,7 +14,6 @@
validate_application_compatibility,
validate_application_exists,
validate_applications_not_archived,
validate_buffer_required,
validate_organism_exists,
validate_sample_names_available,
validate_sample_names_unique,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
validate_sample_names_not_repeated,
validate_samples_exist,
validate_sex_required_for_new_samples,
validate_source_required,
validate_status_required_if_new,
validate_subject_ids_different_from_case_names,
validate_subject_ids_different_from_sample_names,
validate_volume_interval,
Expand Down Expand Up @@ -51,8 +49,6 @@
validate_samples_exist,
validate_sample_names_not_repeated,
validate_sex_required_for_new_samples,
validate_source_required,
validate_status_required_if_new,
validate_subject_ids_different_from_case_names,
validate_subject_ids_different_from_sample_names,
validate_volume_interval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
TomteSample,
)

NewSample = Annotated[TomteSample, Tag("new")]
OldSample = Annotated[ExistingSample, Tag("existing")]


class TomteCase(Case):
cohorts: list[str] | None = None
panels: list[str]
synopsis: str | None = None
samples: list[
Annotated[
Annotated[TomteSample, Tag("new")] | Annotated[ExistingSample, Tag("existing")],
Discriminator(has_internal_id),
]
]
samples: list[Annotated[NewSample | OldSample, Discriminator(has_internal_id)]]

def get_sample(self, sample_name: str) -> TomteSample | None:
for sample in self.samples:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
)
from cg.services.order_validation_service.workflows.tomte.models.case import TomteCase

NewCase = Annotated[TomteCase, Tag("new")]
OldCase = Annotated[ExistingCase, Tag("existing")]


class TomteOrder(OrderWithCases):
cases: list[
Annotated[
Annotated[TomteCase, Tag("new")] | Annotated[ExistingCase, Tag("existing")],
Discriminator(has_internal_id),
]
]
cases: list[Annotated[NewCase | OldCase, Discriminator(has_internal_id)]]
delivery_type: TomteDeliveryType
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
validate_sample_names_not_repeated,
validate_samples_exist,
validate_sex_required_for_new_samples,
validate_source_required,
validate_status_required_if_new,
validate_subject_ids_different_from_case_names,
validate_subject_ids_different_from_sample_names,
validate_volume_interval,
validate_wells_contain_at_most_one_sample,
)


CASE_RULES: list[callable] = [
validate_case_internal_ids_exist,
validate_case_names_available,
Expand All @@ -52,8 +49,6 @@
validate_samples_exist,
validate_sample_names_not_repeated,
validate_sex_required_for_new_samples,
validate_source_required,
validate_status_required_if_new,
validate_subject_ids_different_from_case_names,
validate_subject_ids_different_from_sample_names,
validate_volume_interval,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest

from cg.constants.constants import Workflow
from cg.models.orders.sample_base import ContainerEnum
from cg.models.orders.sample_base import ContainerEnum, PriorityEnum
from cg.services.order_validation_service.constants import (
MINIMUM_VOLUME,
ElutionBuffer,
ExtractionMethod,
)
from cg.services.order_validation_service.workflows.microsalt.constants import (
Expand All @@ -25,8 +26,10 @@ def create_microsalt_sample(id: int) -> MicrosaltSample:
application="MWRNXTR003",
container=ContainerEnum.plate,
container_name="ContainerName",
elution_buffer=ElutionBuffer.WATER,
extraction_method=ExtractionMethod.MAELSTROM,
organism="C. jejuni",
priority=PriorityEnum.standard,
require_qc_ok=True,
reference_genome="NC_00001",
well_position=f"A:{id}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
ApplicationArchivedError,
ApplicationNotCompatibleError,
ApplicationNotValidError,
ElutionBufferMissingError,
ExtractionMethodMissingError,
InvalidVolumeError,
OrganismDoesNotExistError,
)
from cg.services.order_validation_service.rules.sample.rules import (
validate_application_compatibility,
validate_application_exists,
validate_applications_not_archived,
validate_buffer_required,
validate_extraction_method_required,
validate_organism_exists,
validate_volume_interval,
)
Expand Down Expand Up @@ -119,33 +115,3 @@ def test_valid_organisms(valid_order: MicrosaltOrder, base_store: Store):

# THEN no error should be returned
assert not errors


def test_buffer_required(valid_order: MicrosaltOrder):

# GIVEN an order containing a sample with missing buffer
valid_order.samples[0].elution_buffer = None

# WHEN validating that buffers are set for new samples
errors = validate_buffer_required(order=valid_order)

# THEN an error should be returned
assert errors

# THEN the error should concern the missing buffer
assert isinstance(errors[0], ElutionBufferMissingError)


def test_extraction_method_missing(valid_order: MicrosaltOrder):

# GIVEN an order containing a sample with missing extraction method
valid_order.samples[0].extraction_method = None

# WHEN validating that the extraction method is set for all new samples
errors = validate_extraction_method_required(order=valid_order)

# THEN an error should be raised
assert errors

# THEN the error should concern the missing extraction method
assert isinstance(errors[0], ExtractionMethodMissingError)
15 changes: 0 additions & 15 deletions tests/services/order_validation_service/test_data_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ApplicationNotValidError,
SampleDoesNotExistError,
SexMissingError,
SourceMissingError,
)
from cg.services.order_validation_service.models.existing_case import ExistingCase
from cg.services.order_validation_service.models.existing_sample import ExistingSample
Expand All @@ -26,7 +25,6 @@
validate_gene_panels_exist,
validate_samples_exist,
validate_sex_required_for_new_samples,
validate_source_required,
)
from cg.services.order_validation_service.workflows.tomte.models.order import TomteOrder
from cg.store.models import Application
Expand Down Expand Up @@ -172,16 +170,3 @@ def test_sex_missing_for_new_sample(valid_order: TomteOrder):

# THEN the error should concern the missing sex
assert isinstance(errors[0], SexMissingError)


def test_source_missing_for_new_sample(valid_order: TomteOrder):

# GIVEN an order with a new sample without 'source' set
valid_order.cases[0].samples[0].source = None

# WHEN validating that all new samples have 'source' set
errors = validate_source_required(order=valid_order)

assert errors

assert isinstance(errors[0], SourceMissingError)
Loading
Loading