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

fix( parsing no delivery option) #4294

Merged
merged 16 commits into from
Mar 18, 2025
36 changes: 22 additions & 14 deletions cg/apps/orderform/excel_orderform_parser.py
Original file line number Diff line number Diff line change
@@ -175,20 +175,10 @@ def parse_data_analysis(self) -> str:
return data_analyses.pop().lower().replace(" ", "-")

def get_data_delivery(self) -> str:
"""Determine the order_data delivery type"""

data_delivery: str = self.parse_data_delivery()

try:
return DataDelivery(data_delivery)
except ValueError as error:
raise OrderFormError(f"Unsupported Data Delivery: {data_delivery}") from error

def parse_data_delivery(self) -> str:
"Get the data delivery type."
data_deliveries: set[str] = {
sample.data_delivery or self.NO_VALUE for sample in self.samples
}

if len(data_deliveries) > 1:
raise OrderFormError(f"mixed 'Data Delivery' types: {', '.join(data_deliveries)}")

@@ -203,7 +193,7 @@ def get_customer_id(self) -> str:
return customers.pop()

def parse_orderform(self, excel_path: str) -> None:
"""Parse out information from an order form"""
"""Parse out information from an order form."""

LOG.info(f"Open excel workbook from file {excel_path}")
workbook: Workbook = openpyxl.load_workbook(
@@ -233,5 +223,23 @@ def parse_orderform(self, excel_path: str) -> None:

@staticmethod
def _transform_data_delivery(data_delivery: str) -> str:
"""Transforms the data-delivery parsed in the excel file, to the ones used in cg"""
return data_delivery.lower().replace(" + ", "-").replace(" ", "_")
"""Transforms the data-delivery parsed in the excel file, to the ones used in cg."""
try:
orderform_to_internal: dict = {
"analysis": DataDelivery.ANALYSIS_FILES,
"analysis + scout": DataDelivery.ANALYSIS_SCOUT,
"bam": DataDelivery.BAM,
"fastq": DataDelivery.FASTQ,
"fastq + analysis": DataDelivery.FASTQ_ANALYSIS,
"fastq + analysis + scout": DataDelivery.FASTQ_ANALYSIS_SCOUT,
"fastq + Scout": DataDelivery.FASTQ_SCOUT,
"fastq qc": DataDelivery.FASTQ_QC,
"fastq qc + analysis": DataDelivery.FASTQ_QC_ANALYSIS,
"no delivery": DataDelivery.NO_DELIVERY,
"scout": DataDelivery.SCOUT,
"statina": DataDelivery.STATINA,
"fastq-analysis": DataDelivery.FASTQ_ANALYSIS, # Sars Cov10 orderform does not have the same options as others
}
return orderform_to_internal[data_delivery]
except KeyError as error:
raise OrderFormError(f"Unsupported Data Delivery: {data_delivery}") from error
2 changes: 2 additions & 0 deletions cg/models/orders/validators/excel_sample_validators.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ def parse_panels(panels: str) -> list[str] | None:
separator = ";" if ";" in panels else None
if ":" in panels:
separator = ":"
if not separator:
return [panels]
return panels.split(separator)


30 changes: 29 additions & 1 deletion tests/apps/orderform/test_excel_orderform_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from cg.apps.orderform.excel_orderform_parser import ExcelOrderformParser
from cg.constants.constants import DataDelivery
from cg.models.orders.constants import OrderType
from cg.models.orders.excel_sample import ExcelSample
from cg.models.orders.orderform_schema import Orderform
@@ -168,6 +169,33 @@ def test_parse_mip_orderform(mip_orderform: str, nr_samples_mip_orderform: int):
assert order_form_parser.project_type == OrderType.MIP_DNA


def test_parse_mip_orderform_no_delivery(
mip_orderform_no_delivery: str, nr_samples_mip_orderform: int
):
"""Test to parse a mip orderform in xlsx format"""
# GIVEN a orderform in excel format
assert is_excel(Path(mip_orderform_no_delivery))
# GIVEN a orderform API
order_form_parser = ExcelOrderformParser()
# GIVEN the correct orderform name
order_name: str = Path(mip_orderform_no_delivery).stem

# WHEN parsing the mip orderform
order_form_parser.parse_orderform(excel_path=mip_orderform_no_delivery)

# THEN assert that the correct name was set
assert order_form_parser.order_name == order_name

# THEN assert the number of samples parsed are correct
assert len(order_form_parser.samples) == nr_samples_mip_orderform
assert order_form_parser.samples[0].panels == ["Inherited cancer"]
assert order_form_parser.samples[1].panels == ["AID", "Inherited cancer"]
assert order_form_parser.delivery_type == DataDelivery.NO_DELIVERY

# THEN assert that the project type is correct
assert order_form_parser.project_type == OrderType.MIP_DNA


def test_parse_rml_orderform(rml_orderform: str, nr_samples_rml_orderform: int):
"""Test to parse an excel orderform in xlsx format"""
# GIVEN a orderform in excel format
@@ -228,7 +256,7 @@ def test_fastq_samples_is_correct(fastq_order_parser: ExcelOrderformParser):
assert tumour_sample and normal_sample


def test_generate_parsed_rml_orderform(rml_order_parser: ExcelOrderformParser, caplog):
def test_generate_parsed_rml_orderform(rml_order_parser: ExcelOrderformParser):
"""Test to generate a order from a parsed rml excel file"""
# GIVEN a order form parser that have parsed an excel file

Original file line number Diff line number Diff line change
@@ -234,6 +234,15 @@ def mip_orderform(orderforms: Path) -> str:
).as_posix()


@pytest.fixture(scope="session")
def mip_orderform_no_delivery(orderforms: Path) -> str:
"""Orderform fixture for MIP samples with delivery set to No delivery."""
return Path(
orderforms,
f"{Orderform.MIP_DNA}.{Orderform.get_current_orderform_version(Orderform.MIP_DNA)}.mip_no_delivery.xlsx",
).as_posix()


@pytest.fixture(scope="session")
def mip_rna_orderform(orderforms: Path) -> str:
"""Orderform fixture for MIP RNA samples."""
Binary file not shown.
Binary file not shown.

Unchanged files with check annotations Beta

FROM docker.io/library/python:3.11-slim-bullseye
ENV CG_SQL_DATABASE_URI="sqlite:///:memory:"
ENV CG_SECRET_KEY="key"

Check warning on line 4 in Dockerfile

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "CG_SECRET_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV LIMS_HOST="mocklims.scilifelab.se"
ENV LIMS_USERNAME="limsadmin"
ENV LIMS_PASSWORD="limsadminpassword"

Check warning on line 8 in Dockerfile

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "LIMS_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV MAIL_CONTAINER_URI="http://127.0.0.1:port/container"
ENV GOOGLE_OAUTH_CLIENT_ID="1"
ENV GOOGLE_OAUTH_CLIENT_SECRET="1"

Check warning on line 13 in Dockerfile

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "GOOGLE_OAUTH_CLIENT_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV TRAILBLAZER_HOST="host"
ENV TRAILBLAZER_SERVICE_ACCOUNT="service_account"
ENV TRAILBLAZER_SERVICE_ACCOUNT_AUTH_FILE="auth_file"

Check warning on line 17 in Dockerfile

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "TRAILBLAZER_SERVICE_ACCOUNT_AUTH_FILE") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
WORKDIR /home/src/app
RUN poetry install --no-interaction --no-ansi
CMD gunicorn \

Check warning on line 31 in Dockerfile

GitHub Actions / docker-image-push

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
--config gunicorn.conf.py \
cg.server.auto:app