-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
189 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
from cg.services.order_validation_service.workflows.microsalt.models.sample import MicrosaltSample | ||
from cg.services.order_validation_service.workflows.mip_dna.models.case import MipDnaCase | ||
from cg.services.order_validation_service.workflows.mip_dna.models.sample import MipDnaSample | ||
from cg.services.order_validation_service.workflows.mutant.models.sample import MutantSample | ||
from cg.services.order_validation_service.workflows.tomte.models.case import TomteCase | ||
from cg.services.order_validation_service.workflows.tomte.models.sample import TomteSample | ||
|
||
|
||
SampleWithRelatives = TomteSample | MipDnaSample | ||
CaseContainingRelatives = TomteCase | MipDnaCase | ||
|
||
NonHumanSample = MutantSample | MicrosaltSample |
11 changes: 11 additions & 0 deletions
11
cg/services/order_validation_service/models/order_with_samples.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from cg.services.order_validation_service.models.aliases import NonHumanSample | ||
from cg.services.order_validation_service.models.order import Order | ||
from cg.services.order_validation_service.models.sample import Sample | ||
|
||
|
||
class OrderWithNonHumanSamples(Order): | ||
samples: list[NonHumanSample] | ||
|
||
@property | ||
def enumerated_samples(self) -> enumerate[NonHumanSample]: | ||
return enumerate(self.samples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
from cg.constants.constants import PrepCategory, Workflow | ||
from cg.services.order_validation_service.constants import WORKFLOW_PREP_CATEGORIES | ||
from cg.services.order_validation_service.errors.sample_errors import ( | ||
ApplicationArchivedError, | ||
ApplicationNotCompatibleError, | ||
ApplicationNotValidError, | ||
ElutionBufferMissingError, | ||
ExtractionMethodMissingError, | ||
InvalidVolumeError, | ||
OccupiedWellError, | ||
OrganismDoesNotExistError, | ||
SampleNameRepeatedError, | ||
) | ||
from cg.services.order_validation_service.rules.utils import ( | ||
is_application_not_compatible, | ||
is_volume_invalid, | ||
) | ||
from cg.services.order_validation_service.workflows.microsalt.models.order import ( | ||
OrderWithNonHumanSamples, | ||
) | ||
from cg.services.order_validation_service.rules.sample.utils import ( | ||
PlateSamplesValidator, | ||
get_indices_for_repeated_sample_names, | ||
) | ||
from cg.store.store import Store | ||
|
||
|
||
def validate_application_exists( | ||
order: OrderWithNonHumanSamples, store: Store, **kwargs | ||
) -> list[ApplicationNotValidError]: | ||
errors: list[ApplicationNotValidError] = [] | ||
for sample_index, sample in order.enumerated_samples: | ||
if not store.get_application_by_tag(sample.application): | ||
error = ApplicationNotValidError(sample_index=sample_index) | ||
errors.append(error) | ||
return errors | ||
|
||
|
||
def validate_applications_not_archived( | ||
order: OrderWithNonHumanSamples, store: Store, **kwargs | ||
) -> list[ApplicationArchivedError]: | ||
errors: list[ApplicationArchivedError] = [] | ||
for sample_index, sample in order.enumerated_samples: | ||
if store.is_application_archived(sample.application): | ||
error = ApplicationArchivedError(sample_index=sample_index) | ||
errors.append(error) | ||
return errors | ||
|
||
|
||
def validate_volume_interval(order: OrderWithNonHumanSamples, **kwargs) -> list[InvalidVolumeError]: | ||
errors: list[InvalidVolumeError] = [] | ||
for sample_index, sample in order.enumerated_samples: | ||
if is_volume_invalid(sample): | ||
error = InvalidVolumeError(sample_index=sample_index) | ||
errors.append(error) | ||
return errors | ||
|
||
|
||
def validate_organism_exists( | ||
order: OrderWithNonHumanSamples, store: Store, **kwargs | ||
) -> list[OrganismDoesNotExistError]: | ||
errors: list[OrganismDoesNotExistError] = [] | ||
for sample_index, sample in order.enumerated_samples: | ||
if not store.get_organism_by_internal_id(sample.organism): | ||
error = OrganismDoesNotExistError(sample_index=sample_index) | ||
errors.append(error) | ||
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, | ||
**kwargs, | ||
) -> list[ApplicationNotCompatibleError]: | ||
errors: list[ApplicationNotCompatibleError] = [] | ||
workflow: Workflow = order.workflow | ||
allowed_prep_categories: list[PrepCategory] = WORKFLOW_PREP_CATEGORIES[workflow] | ||
for sample_index, sample in order.enumerated_samples: | ||
incompatible: bool = is_application_not_compatible( | ||
allowed_prep_categories=allowed_prep_categories, | ||
application_tag=sample.application, | ||
store=store, | ||
) | ||
if incompatible: | ||
error = ApplicationNotCompatibleError(sample_index=sample_index) | ||
errors.append(error) | ||
return errors | ||
|
||
|
||
def validate_wells_contain_at_most_one_sample( | ||
order: OrderWithNonHumanSamples, | ||
**kwargs, | ||
) -> list[OccupiedWellError]: | ||
plate_samples = PlateSamplesValidator(order) | ||
return plate_samples.get_occupied_well_errors() | ||
|
||
|
||
def validate_well_positions_required( | ||
order: OrderWithNonHumanSamples, | ||
**kwargs, | ||
) -> list[OccupiedWellError]: | ||
plate_samples = PlateSamplesValidator(order) | ||
return plate_samples.get_well_position_missing_errors() | ||
|
||
|
||
def validate_sample_names_unique( | ||
order: OrderWithNonHumanSamples, **kwargs | ||
) -> list[SampleNameRepeatedError]: | ||
sample_indices: list[int] = get_indices_for_repeated_sample_names(order) | ||
return [SampleNameRepeatedError(sample_index=sample_index) for sample_index in sample_indices] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file removed
0
cg/services/order_validation_service/workflows/microsalt/rules/sample/__init__.py
Empty file.
128 changes: 0 additions & 128 deletions
128
cg/services/order_validation_service/workflows/microsalt/rules/sample/rules.py
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
cg/services/order_validation_service/workflows/microsalt/validation_rules.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.