Skip to content

Commit

Permalink
Improve mip rna messages (#3987)
Browse files Browse the repository at this point in the history
### Added

- Error raising for when no matching DNA cases are found.

### Changed

- Simplified code structure.
  • Loading branch information
beatrizsavinhas authored Dec 3, 2024
1 parent 1d4ace3 commit f514384
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
33 changes: 10 additions & 23 deletions cg/services/delivery_message/messages/rna_delivery_message.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from abc import abstractmethod, ABC
from abc import ABC, abstractmethod

from cg.services.delivery_message.messages.utils import (
get_scout_links_row_separated,
get_caesar_delivery_path,
get_scout_links_row_separated,
)
from cg.store.models import Case

Expand Down Expand Up @@ -51,31 +51,18 @@ def __init__(self, store, strategy: RNAUploadMessageStrategy):
self.strategy = strategy

def create_message(self, cases: list[Case]) -> str:
if len(cases) == 1:
return self._get_case_message(cases[0])
return self._get_cases_message(cases)
message = "Hello,\n\n"
for case in cases:
scout_message = self._get_scout_message_for_case(case=case)
message += scout_message
delivery_path = get_caesar_delivery_path(cases[0])
file_upload_message = self.strategy.get_file_upload_message(delivery_path)
return message + file_upload_message

def _get_case_message(self, case: Case) -> str:
def _get_scout_message_for_case(self, case: Case) -> str:
related_uploaded_dna_cases = self.store.get_uploaded_related_dna_cases(rna_case=case)
scout_links = get_scout_links_row_separated(cases=related_uploaded_dna_cases)
delivery_path = get_caesar_delivery_path(case)
file_upload_message = self.strategy.get_file_upload_message(delivery_path)
return (
f"Hello,\n\n"
f"The analysis for case {case.name} has been uploaded to the corresponding DNA case(s) on Scout at:\n\n"
f"{scout_links}\n\n"
f"{file_upload_message}"
)

def _get_cases_message(self, cases: list[Case]) -> str:
message = "Hello,\n\n"
for case in cases:
related_uploaded_dna_cases = self.store.get_uploaded_related_dna_cases(rna_case=case)
scout_links = get_scout_links_row_separated(cases=related_uploaded_dna_cases)
message += (
f"The analysis for case {case.name} has been uploaded to the corresponding DNA case(s) on Scout at:\n\n"
f"{scout_links}\n\n"
)
delivery_path = get_caesar_delivery_path(cases[0])
file_upload_message = self.strategy.get_file_upload_message(delivery_path)
return message + file_upload_message
5 changes: 4 additions & 1 deletion cg/store/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,5 +1655,8 @@ def get_uploaded_related_dna_cases(self, rna_case: Case) -> list[Case]:
)

related_dna_cases.extend([case for case in uploaded_dna_cases])

if not related_dna_cases:
raise CaseNotFoundError(
f"No matching uploaded DNA cases for case {rna_case.internal_id} ({rna_case.name})."
)
return related_dna_cases

0 comments on commit f514384

Please sign in to comment.