Skip to content

Commit

Permalink
Add sample name validation (#4019) (patch)
Browse files Browse the repository at this point in the history
### Changed

- Microbial fastq orders containing samples which the customer has used in a previous order do not pass validation.
  • Loading branch information
islean authored Dec 17, 2024
1 parent eea3e7e commit d1004b4
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cg.exc import OrderError
from cg.models.orders.constants import OrderType
from cg.models.orders.order import OrderIn
from cg.models.orders.samples import SarsCov2Sample
from cg.models.orders.samples import MicrobialFastqSample, SarsCov2Sample
from cg.services.orders.submitters.order_submitter import ValidateOrderService
from cg.store.models import Customer
from cg.store.store import Store
Expand All @@ -15,18 +15,25 @@ def __init__(self, status_db: Store):
def validate_order(self, order: OrderIn) -> None:
if order.order_type == OrderType.SARS_COV_2:
self._validate_sample_names_are_available(
samples=order.samples, customer_id=order.customer
samples=order.samples, customer_id=order.customer, is_sars_cov_2=True
)
elif order.order_type == OrderType.MICROBIAL_FASTQ:
self._validate_sample_names_are_available(
samples=order.samples, customer_id=order.customer, is_sars_cov_2=False
)

def _validate_sample_names_are_available(
self, samples: list[SarsCov2Sample], customer_id: str
self,
samples: list[SarsCov2Sample] | list[MicrobialFastqSample],
customer_id: str,
is_sars_cov_2: bool,
) -> None:
"""Validate names of all samples are not already in use."""
customer: Customer = self.status_db.get_customer_by_internal_id(
customer_internal_id=customer_id
)
for sample in samples:
if sample.control:
if is_sars_cov_2 and sample.control:
continue
if self.status_db.get_sample_by_customer_and_name(
customer_entry_id=[customer.id], sample_name=sample.name
Expand Down

0 comments on commit d1004b4

Please sign in to comment.