From 0928c911726e3d343babf660f495a4c752070f47 Mon Sep 17 00:00:00 2001 From: islean Date: Tue, 21 Jan 2025 10:27:41 +0100 Subject: [PATCH 1/2] Override microbial dump --- cg/services/orders/lims_service/service.py | 4 ---- .../storing/implementations/microbial_order_service.py | 2 +- .../orders/validation/workflows/microsalt/models/sample.py | 5 +++++ .../orders/validation/workflows/mutant/models/sample.py | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cg/services/orders/lims_service/service.py b/cg/services/orders/lims_service/service.py index ad35311301..299f6300d8 100644 --- a/cg/services/orders/lims_service/service.py +++ b/cg/services/orders/lims_service/service.py @@ -4,8 +4,6 @@ from cg.constants import DataDelivery, Workflow from cg.models.lims.sample import LimsSample from cg.services.orders.validation.models.sample import Sample -from cg.services.orders.validation.workflows.microsalt.models.sample import MicrosaltSample -from cg.services.orders.validation.workflows.mutant.models.sample import MutantSample LOG = logging.getLogger(__name__) @@ -28,8 +26,6 @@ def _build_lims_sample( dict_sample["data_analysis"] = workflow dict_sample["data_delivery"] = delivery_type dict_sample["family_name"] = sample._case_name - if isinstance(sample, MutantSample | MicrosaltSample): - dict_sample["verified_organism"] = sample._verified_organism lims_sample: LimsSample = LimsSample.parse_obj(dict_sample) samples_lims.append(lims_sample) return samples_lims diff --git a/cg/services/orders/storing/implementations/microbial_order_service.py b/cg/services/orders/storing/implementations/microbial_order_service.py index 9d7e2bdc5f..057c5dd9f7 100644 --- a/cg/services/orders/storing/implementations/microbial_order_service.py +++ b/cg/services/orders/storing/implementations/microbial_order_service.py @@ -89,7 +89,7 @@ def _fill_in_sample_verified_organism(self, samples: list[MicrobialSample]): organism_id = sample.organism reference_genome = sample.reference_genome organism: Organism = self.status.get_organism_by_internal_id(internal_id=organism_id) - is_verified = ( + is_verified: bool = ( organism and organism.reference_genome == reference_genome and organism.verified ) sample._verified_organism = is_verified diff --git a/cg/services/orders/validation/workflows/microsalt/models/sample.py b/cg/services/orders/validation/workflows/microsalt/models/sample.py index 99fe537c91..92f6dc2c52 100644 --- a/cg/services/orders/validation/workflows/microsalt/models/sample.py +++ b/cg/services/orders/validation/workflows/microsalt/models/sample.py @@ -15,3 +15,8 @@ class MicrosaltSample(Sample): priority: PriorityEnum reference_genome: str = Field(max_length=255) _verified_organism: str | None = PrivateAttr(default=None) + + def model_dump(self, **kwargs) -> dict: + data = super().model_dump(**kwargs) + data["verified_organism"] = self._verified_organism + return data diff --git a/cg/services/orders/validation/workflows/mutant/models/sample.py b/cg/services/orders/validation/workflows/mutant/models/sample.py index 2c26a80e62..d2928d3ace 100644 --- a/cg/services/orders/validation/workflows/mutant/models/sample.py +++ b/cg/services/orders/validation/workflows/mutant/models/sample.py @@ -35,7 +35,7 @@ class MutantSample(Sample): region: Region region_code: str selection_criteria: SelectionCriteria - _verified_organism: str | None = PrivateAttr(default=None) + _verified_organism: bool | None = PrivateAttr(default=None) @model_validator(mode="before") @classmethod @@ -62,4 +62,5 @@ def serialize_collection_date(self, value: date) -> str: def model_dump(self, **kwargs) -> dict: data = super().model_dump(**kwargs) data["lab_code"] = self._lab_code + data["verified_organism"] = self._verified_organism return data From c7d2f10c98065ec11bedbea0c61677cf0f8ca840 Mon Sep 17 00:00:00 2001 From: islean Date: Tue, 21 Jan 2025 10:45:59 +0100 Subject: [PATCH 2/2] Fix type hint --- .../orders/validation/workflows/microsalt/models/sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cg/services/orders/validation/workflows/microsalt/models/sample.py b/cg/services/orders/validation/workflows/microsalt/models/sample.py index 92f6dc2c52..c20c0fb870 100644 --- a/cg/services/orders/validation/workflows/microsalt/models/sample.py +++ b/cg/services/orders/validation/workflows/microsalt/models/sample.py @@ -14,7 +14,7 @@ class MicrosaltSample(Sample): organism: str priority: PriorityEnum reference_genome: str = Field(max_length=255) - _verified_organism: str | None = PrivateAttr(default=None) + _verified_organism: bool | None = PrivateAttr(default=None) def model_dump(self, **kwargs) -> dict: data = super().model_dump(**kwargs)