Skip to content

Commit a783d76

Browse files
authored
(Improve order flow) Set default index sequence (#4113) (patch)
### Fixed - Default index sequence is set for RML and Fluffy orders
1 parent 66582d4 commit a783d76

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

cg/services/orders/validation/workflows/fluffy/models/sample.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
from pydantic import BeforeValidator, Field
1+
import logging
2+
3+
from pydantic import BeforeValidator, Field, model_validator
24
from typing_extensions import Annotated
35

46
from cg.models.orders.sample_base import ContainerEnum, ControlEnum, PriorityEnum
57
from cg.services.orders.validation.constants import IndexEnum
8+
from cg.services.orders.validation.index_sequences import INDEX_SEQUENCES
69
from cg.services.orders.validation.models.sample import Sample
710
from cg.services.orders.validation.utils import parse_control
811

12+
LOG = logging.getLogger(__name__)
13+
914

1015
class FluffySample(Sample):
1116
concentration: float
@@ -20,3 +25,15 @@ class FluffySample(Sample):
2025
rml_plate_name: str | None = None
2126
volume: int
2227
well_position_rml: str | None = None
28+
29+
@model_validator(mode="after")
30+
def set_default_index_sequence(self):
31+
"""Set a default index_sequence from the index and index_number."""
32+
if not self.index_sequence and (self.index and self.index_number):
33+
try:
34+
self.index_sequence = INDEX_SEQUENCES[self.index][self.index_number - 1]
35+
except Exception:
36+
LOG.warning(
37+
f"No index sequence set and no suitable sequence found for index {self.index}, number {self.index_number}"
38+
)
39+
return self

cg/services/orders/validation/workflows/rml/models/sample.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
from pydantic import BeforeValidator, Field
1+
import logging
2+
3+
from pydantic import BeforeValidator, Field, model_validator
24
from typing_extensions import Annotated
35

46
from cg.models.orders.sample_base import ContainerEnum, ControlEnum, PriorityEnum
57
from cg.services.orders.validation.constants import IndexEnum
8+
from cg.services.orders.validation.index_sequences import INDEX_SEQUENCES
69
from cg.services.orders.validation.models.sample import Sample
710
from cg.services.orders.validation.utils import parse_control
811

12+
LOG = logging.getLogger(__name__)
13+
914

1015
class RmlSample(Sample):
1116
concentration: float
@@ -20,3 +25,15 @@ class RmlSample(Sample):
2025
rml_plate_name: str | None = None
2126
volume: int
2227
well_position_rml: str | None = None
28+
29+
@model_validator(mode="after")
30+
def set_default_index_sequence(self):
31+
"""Set a default index_sequence from the index and index_number."""
32+
if not self.index_sequence and (self.index and self.index_number):
33+
try:
34+
self.index_sequence = INDEX_SEQUENCES[self.index][self.index_number - 1]
35+
except Exception:
36+
LOG.warning(
37+
f"No index sequence set and no suitable sequence found for index {self.index}, number {self.index_number}"
38+
)
39+
return self

0 commit comments

Comments
 (0)