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: 24 additions & 12 deletions cg/apps/orderform/excel_orderform_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,13 @@ 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
"""Determine the order_data delivery type."""
return self.parse_data_delivery()

def parse_data_delivery(self) -> str:
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)}")

Expand All @@ -203,7 +196,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(
Expand Down Expand Up @@ -233,5 +226,24 @@ 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,
"nipt viewer": DataDelivery.NIPT_VIEWER, # legacy option; keeping it for backward compatibility
"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
Expand Up @@ -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)


Expand Down
26 changes: 25 additions & 1 deletion tests/apps/orderform/test_excel_orderform_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ 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"]
# 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
Expand Down Expand Up @@ -228,7 +252,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Binary file not shown.
Binary file not shown.
Loading