Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Improve order flow) Add metagenome rules #3943

Open
wants to merge 3 commits into
base: improve-order-flow-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions cg/server/endpoints/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from cg.apps.orderform.excel_orderform_parser import ExcelOrderformParser
from cg.apps.orderform.json_orderform_parser import JsonOrderformParser
from cg.constants import ANALYSIS_SOURCES, METAGENOME_SOURCES
from cg.constants.constants import FileFormat, Workflow
from cg.constants.constants import FileFormat
from cg.exc import (
OrderError,
OrderExistsError,
Expand All @@ -37,6 +37,7 @@
db,
delivery_message_service,
lims,
metagenome_validation_service,
microsalt_validation_service,
mip_dna_validation_service,
order_service,
Expand Down Expand Up @@ -263,17 +264,21 @@ def get_options():
)


@ORDERS_BLUEPRINT.route("/validate_order/<workflow>", methods=["POST"])
def validate_order(workflow: str):
@ORDERS_BLUEPRINT.route("/validate_order/<order_type>", methods=["POST"])
def validate_order(order_type: OrderType):
raw_order = request.get_json()
raw_order["workflow"] = workflow
raw_order["order_type"] = order_type
raw_order["user_id"] = g.current_user.id
response = {}
if workflow == Workflow.MICROSALT:
if order_type == OrderType.TOMTE:
response = tomte_validation_service.validate(raw_order)
if order_type == OrderType.MICROSALT:
response = microsalt_validation_service.validate(raw_order)
if workflow == Workflow.MIP_DNA:
if order_type == OrderType.MIP_DNA:
response = mip_dna_validation_service.validate(raw_order)
if workflow == Workflow.RNAFUSION:
if order_type == OrderType.METAGENOME:
response = metagenome_validation_service.validate(raw_order)
if order_type == OrderType.RNAFUSION:
response = rna_fusion_validation_service.validate(raw_order)
if workflow == Workflow.TOMTE:
response = tomte_validation_service.validate(raw_order)
Expand Down
8 changes: 7 additions & 1 deletion cg/server/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from cg.server.app_config import app_config
from cg.services.application.service import ApplicationsWebService
from cg.services.delivery_message.delivery_message_service import DeliveryMessageService
from cg.services.order_validation_service.workflows.metagenome.validation_service import (
MetagenomeValidationService,
)
from cg.services.order_validation_service.workflows.microsalt.validation_service import (
MicroSaltValidationService,
)
Expand All @@ -25,7 +28,9 @@
TomteValidationService,
)
from cg.services.orders.order_service.order_service import OrderService
from cg.services.orders.order_summary_service.order_summary_service import OrderSummaryService
from cg.services.orders.order_summary_service.order_summary_service import (
OrderSummaryService,
)
from cg.services.orders.submitters.order_submitter_registry import (
OrderSubmitterRegistry,
setup_order_submitter_registry,
Expand Down Expand Up @@ -112,6 +117,7 @@ def init_app(self, app):
tomte_validation_service = TomteValidationService(store=db)
microsalt_validation_service = MicroSaltValidationService(store=db)
mip_dna_validation_service = MipDnaValidationService(store=db)
metagenome_validation_service = MetagenomeValidationService(store=db)
rna_fusion_validation_service = RnaFusionValidationService(store=db)
freshdesk_client = FreshdeskClient(
base_url=app_config.freshdesk_url, api_key=app_config.freshdesk_api_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class MetagenomeSample(Sample):
concentration_ng_ul: float | None = None
concentration_sample: float | None = None
control: ControlEnum | None = None
elution_buffer: ElutionBuffer
organism: str
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from cg.services.order_validation_service.rules.sample.rules import (
validate_application_compatibility,
validate_application_exists,
validate_applications_not_archived,
validate_container_name_required,
validate_required_volume,
validate_sample_names_available,
validate_sample_names_unique,
validate_tube_container_name_unique,
validate_volume_interval,
validate_well_position_format,
validate_well_positions_required,
validate_wells_contain_at_most_one_sample,
)

SAMPLE_RULES: list[callable] = [
validate_application_compatibility,
validate_application_exists,
validate_applications_not_archived,
validate_container_name_required,
validate_required_volume,
validate_sample_names_available,
validate_sample_names_unique,
validate_tube_container_name_unique,
validate_volume_interval,
validate_well_position_format,
validate_well_positions_required,
validate_wells_contain_at_most_one_sample,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from cg.services.order_validation_service.errors.order_errors import OrderError
from cg.services.order_validation_service.errors.sample_errors import SampleError
from cg.services.order_validation_service.errors.validation_errors import (
ValidationErrors,
)
from cg.services.order_validation_service.model_validator.model_validator import (
ModelValidator,
)
from cg.services.order_validation_service.order_validation_service import (
OrderValidationService,
)
from cg.services.order_validation_service.response_mapper import (
create_order_validation_response,
)
from cg.services.order_validation_service.utils import (
apply_order_validation,
apply_sample_validation,
)
from cg.services.order_validation_service.workflows.metagenome.models.order import (
MetagenomeOrder,
)
from cg.services.order_validation_service.workflows.metagenome.validation_rules import (
SAMPLE_RULES,
)
from cg.services.order_validation_service.workflows.order_validation_rules import (
ORDER_RULES,
)
from cg.store.store import Store


class MetagenomeValidationService(OrderValidationService):

def __init__(self, store: Store):
self.store = store

def validate(self, raw_order: dict) -> dict:
errors: ValidationErrors = self._get_errors(raw_order)
return create_order_validation_response(raw_order=raw_order, errors=errors)

def _get_errors(self, raw_order: dict) -> ValidationErrors:
order, field_errors = ModelValidator.validate(order=raw_order, model=MetagenomeOrder)

if not order:
return field_errors

order_errors: list[OrderError] = apply_order_validation(
rules=ORDER_RULES,
order=order,
store=self.store,
)
sample_errors: list[SampleError] = apply_sample_validation(
rules=SAMPLE_RULES,
order=order,
store=self.store,
)

return ValidationErrors(
order_errors=order_errors,
sample_errors=sample_errors,
)
Loading