diff --git a/atlas/filters.py b/atlas/filters.py index 608fb484..2af29a4c 100755 --- a/atlas/filters.py +++ b/atlas/filters.py @@ -49,6 +49,8 @@ def get_series(request): else: queryset = Series.objects.all() + queryset = queryset.prefetch_related("examination", "plane") + return queryset diff --git a/atlas/models.py b/atlas/models.py index 78063dac..1119ef3a 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -516,6 +516,14 @@ class Case(models.Model, AuthorMixin, QuestionMixin): def get_series(self): return self.series.all().prefetch_related("images", "examination", "plane") + def get_series_modalities(self) -> set: + """Returns a list of the modalities of the series in the case""" + series = self.series.all() + modalities = [s.modality.short_code for s in series if s.modality is not None] + + return set(modalities) + + def get_total_series_images_size(self, refresh=False): if self.total_images_series_size is not None and not refresh: return self.total_images_series_size @@ -656,6 +664,11 @@ class Series(SeriesBase): series_instance_uid = models.CharField(max_length=255, blank=True, null=True) # findings = models.TextField(null=True, blank=True, help_text="Findings on the series / stack") + def __str__(self) -> str: + if self.description: + return self.description + else: + return f"{self.examination} ({self.plane})" def get_full_str(self): if self.case: diff --git a/atlas/tables.py b/atlas/tables.py index 581c7c38..491980dc 100755 --- a/atlas/tables.py +++ b/atlas/tables.py @@ -27,6 +27,19 @@ from easy_thumbnails.exceptions import InvalidImageFormatError class CaseTable(tables.Table): + def __init__(self, data=None, *args, **kwargs): + super().__init__( + data.prefetch_related( + "author", # Many-to-many or reverse relationship + "series", # Many-to-many relationship + "series__examination", # ForeignKey in the related model + "series__plane", # ForeignKey in the related model + "series__images", # Reverse relationship + ), + *args, + **kwargs, + ) + def get_view_cell(record): if record.open_access: return format_html(f""" @@ -68,14 +81,6 @@ class CaseTable(tables.Table): sequence = ("view", )#, "series") order_by = "-created_date" - def __init__(self, data=None, *args, **kwargs): - super().__init__( - data.prefetch_related( - "author", "series",#"condition", "condition__synonym" - ), - *args, - **kwargs, - ) class PopupLinkColumn(tables.Column): def render(self, value):