.
This commit is contained in:
@@ -847,6 +847,50 @@ class Case(models.Model, AuthorMixin, QuestionMixin):
|
||||
help_text="Optional manually overridden study date for linked case series.",
|
||||
)
|
||||
|
||||
def get_series_info(self):
|
||||
try:
|
||||
has_next = hasattr(self, 'next_case') and self.next_case is not None
|
||||
except Case.DoesNotExist:
|
||||
has_next = False
|
||||
|
||||
if not self.previous_case_id and not has_next:
|
||||
return {"in_series": False}
|
||||
|
||||
# Find the start of the chain (the first case)
|
||||
first_case = self
|
||||
visited = {self.pk}
|
||||
while first_case.previous_case:
|
||||
if first_case.previous_case.pk in visited:
|
||||
break
|
||||
first_case = first_case.previous_case
|
||||
visited.add(first_case.pk)
|
||||
|
||||
# Traverse the chain from the first case to find positions and count
|
||||
chain = []
|
||||
current = first_case
|
||||
visited_forward = set()
|
||||
while current:
|
||||
if current.pk in visited_forward:
|
||||
break
|
||||
chain.append(current)
|
||||
visited_forward.add(current.pk)
|
||||
try:
|
||||
current = current.next_case if hasattr(current, 'next_case') else None
|
||||
except Case.DoesNotExist:
|
||||
current = None
|
||||
|
||||
total = len(chain)
|
||||
try:
|
||||
position = chain.index(self) + 1
|
||||
except ValueError:
|
||||
position = 1
|
||||
|
||||
return {
|
||||
"in_series": True,
|
||||
"position": position,
|
||||
"total": total,
|
||||
}
|
||||
|
||||
def get_ordered_series_details(self):
|
||||
cached = getattr(self, "_ordered_series_details_cache", None)
|
||||
if cached is not None:
|
||||
|
||||
Reference in New Issue
Block a user