From 1107b45efeeb6f2820d228dc3d64c09b2a8d5ab6 Mon Sep 17 00:00:00 2001 From: ChristianOertlin Date: Mon, 13 Jan 2025 13:05:46 +0100 Subject: [PATCH] fix(assignment maf cases to special order) (#4053) (patch) # Description Put newly generated MAF cases on fixed cust000 owned order --- cg/services/orders/store_order_services/constants.py | 2 ++ .../store_order_services/store_fastq_order_service.py | 11 +++++++---- cg/store/crud/create.py | 2 ++ tests/conftest.py | 4 ++++ tests/meta/orders/conftest.py | 1 + tests/meta/orders/test_meta_orders_api.py | 2 +- .../order_store_service/test_fastq_order_service.py | 7 ++++++- 7 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 cg/services/orders/store_order_services/constants.py diff --git a/cg/services/orders/store_order_services/constants.py b/cg/services/orders/store_order_services/constants.py new file mode 100644 index 0000000000..7adf027cf1 --- /dev/null +++ b/cg/services/orders/store_order_services/constants.py @@ -0,0 +1,2 @@ +# Hardcoded constant for special order to assign MAF cases to +MAF_ORDER_ID: int = 12377 diff --git a/cg/services/orders/store_order_services/store_fastq_order_service.py b/cg/services/orders/store_order_services/store_fastq_order_service.py index 8699c7a4b4..18ec1d0044 100644 --- a/cg/services/orders/store_order_services/store_fastq_order_service.py +++ b/cg/services/orders/store_order_services/store_fastq_order_service.py @@ -8,6 +8,7 @@ from cg.models.orders.order import OrderIn from cg.models.orders.sample_base import StatusEnum from cg.services.orders.order_lims_service.order_lims_service import OrderLimsService +from cg.services.orders.store_order_services.constants import MAF_ORDER_ID from cg.services.orders.submitters.order_submitter import StoreOrderService from cg.store.models import ApplicationVersion, Case, CaseSample, Customer, Order, Sample from cg.store.store import Store @@ -62,12 +63,14 @@ def order_to_status(order: OrderIn) -> dict: } return status_data - def create_maf_case(self, sample_obj: Sample, order: Order) -> None: + def create_maf_case(self, sample_obj: Sample, order: Order, case: Case) -> None: """Add a MAF case to the Status database.""" + maf_order = self.status_db.get_order_by_id(MAF_ORDER_ID) case: Case = self.status_db.add_case( + comment=f"MAF case for {case.internal_id} original order id {order.id}", data_analysis=Workflow(Workflow.MIP_DNA), data_delivery=DataDelivery(DataDelivery.NO_DELIVERY), - name="_".join([sample_obj.name, "MAF"]), + name="_".join([sample_obj.internal_id, "MAF"]), panels=[GenePanelMasterList.OMIM_AUTO], priority=Priority.research, ticket=sample_obj.original_ticket, @@ -78,7 +81,7 @@ def create_maf_case(self, sample_obj: Sample, order: Order) -> None: relationship: CaseSample = self.status_db.relate_sample( case=case, sample=sample_obj, status=StatusEnum.unknown ) - order.cases.append(case) + maf_order.cases.append(case) self.status_db.session.add_all([case, relationship]) def store_items_in_status( @@ -137,7 +140,7 @@ def store_items_in_status( not new_sample.is_tumour and new_sample.prep_category == SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING ): - self.create_maf_case(sample_obj=new_sample, order=status_db_order) + self.create_maf_case(sample_obj=new_sample, order=status_db_order, case=case) case.customer = customer new_relationship = self.status_db.relate_sample( case=case, sample=new_sample, status=StatusEnum.unknown diff --git a/cg/store/crud/create.py b/cg/store/crud/create.py index 40b0f72c83..e26140f995 100644 --- a/cg/store/crud/create.py +++ b/cg/store/crud/create.py @@ -246,11 +246,13 @@ def add_case( priority: Priority | None = Priority.standard, synopsis: str | None = None, customer_id: int | None = None, + comment: str | None = None, ) -> Case: """Build a new Case record.""" internal_id: str = self.generate_readable_case_id() return Case( + comment=comment, cohorts=cohorts, data_analysis=str(data_analysis), data_delivery=str(data_delivery), diff --git a/tests/conftest.py b/tests/conftest.py index 79b389e3dd..e53ff46ea5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -59,6 +59,7 @@ from cg.services.deliver_files.rsync.service import DeliveryRsyncService from cg.services.illumina.backup.encrypt_service import IlluminaRunEncryptionService from cg.services.illumina.data_transfer.data_transfer_service import IlluminaDataTransferService +from cg.services.orders.store_order_services.constants import MAF_ORDER_ID from cg.store.database import create_all_tables, drop_all_tables, initialize_database from cg.store.models import ( Application, @@ -1649,6 +1650,9 @@ def base_store( store.session.add(organism) store.session.commit() + order: Order = Order(customer_id=1, id=MAF_ORDER_ID, ticket_id="100000000") + store.add_multiple_items_to_store([order]) + yield store diff --git a/tests/meta/orders/conftest.py b/tests/meta/orders/conftest.py index 5857e67a8a..ceb7665020 100644 --- a/tests/meta/orders/conftest.py +++ b/tests/meta/orders/conftest.py @@ -9,6 +9,7 @@ OrderSubmitterRegistry, setup_order_submitter_registry, ) +from cg.store.models import Order from cg.store.store import Store from tests.mocks.limsmock import MockLimsAPI diff --git a/tests/meta/orders/test_meta_orders_api.py b/tests/meta/orders/test_meta_orders_api.py index 04ffe40588..6844697337 100644 --- a/tests/meta/orders/test_meta_orders_api.py +++ b/tests/meta/orders/test_meta_orders_api.py @@ -14,7 +14,7 @@ from cg.services.orders.validate_order_services.validate_case_order import ( ValidateCaseOrderService, ) -from cg.store.models import Case, Customer, Pool, Sample +from cg.store.models import Case, Customer, Pool, Sample, Order from cg.store.store import Store from tests.store_helpers import StoreHelpers diff --git a/tests/services/orders/order_store_service/test_fastq_order_service.py b/tests/services/orders/order_store_service/test_fastq_order_service.py index 7bbc9251bb..c26c217cea 100644 --- a/tests/services/orders/order_store_service/test_fastq_order_service.py +++ b/tests/services/orders/order_store_service/test_fastq_order_service.py @@ -6,8 +6,9 @@ from cg.constants.sequencing import SeqLibraryPrepCategory from cg.exc import OrderError from cg.models.orders.order import OrderIn, OrderType +from cg.services.orders.store_order_services.constants import MAF_ORDER_ID from cg.services.orders.store_order_services.store_fastq_order_service import StoreFastqOrderService -from cg.store.models import Application, Case, Sample +from cg.store.models import Application, Case, Sample, Order from cg.store.store import Store @@ -63,6 +64,10 @@ def test_store_samples( assert family_link.case.data_analysis assert family_link.case.data_delivery in [DataDelivery.FASTQ, DataDelivery.NO_DELIVERY] + # THEN a MAF case should be added to the MAF orders + maf_order: Order = base_store.get_order_by_id(MAF_ORDER_ID) + assert len(maf_order.cases) == 1 + def test_store_samples_sex_stored( base_store: Store,