Skip to content

Commit

Permalink
fix(assignment maf cases to special order) (#4053) (patch)
Browse files Browse the repository at this point in the history
# Description

Put newly generated MAF cases on fixed cust000 owned order
  • Loading branch information
ChrOertlin authored Jan 13, 2025
1 parent e74b9aa commit 1107b45
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cg/services/orders/store_order_services/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Hardcoded constant for special order to assign MAF cases to
MAF_ORDER_ID: int = 12377
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cg/store/crud/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions tests/meta/orders/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/meta/orders/test_meta_orders_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1107b45

Please sign in to comment.