This commit is contained in:
Ross
2026-07-13 10:03:33 +01:00
parent 89bf6eedc0
commit 3a3ec75b1d
18 changed files with 514 additions and 24 deletions
+14 -14
View File
@@ -842,23 +842,23 @@ class CaseForm(ModelForm):
self.save_m2m = save_m2m
# Do we need to save all changes now?
# if commit:
instance.save()
self.save_m2m()
if commit:
instance.save()
self.save_m2m()
logger.debug(f"{self.collection=}")
if self.collection is not None:
logger.debug(f"{self.collection=}")
case_no = self.collection.cases.count() + 1
logger.debug(f"{case_no=}")
logger.debug(f"{instance=}")
# Create through model
# cd = CaseDetail(case=instance, collection=exam, sort_order=case_no)
self.collection.cases.add(
instance, through_defaults={"sort_order": case_no}
)
if self.collection is not None:
logger.debug(f"{self.collection=}")
case_no = self.collection.cases.count() + 1
logger.debug(f"{case_no=}")
logger.debug(f"{instance=}")
# Create through model
# cd = CaseDetail(case=instance, collection=exam, sort_order=case_no)
self.collection.cases.add(
instance, through_defaults={"sort_order": case_no}
)
return instance
+44
View File
@@ -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:
@@ -16,6 +16,13 @@
{% for ss in case.subspecialty.all %}
{% if ss.name %}<span class="badge bg-secondary" title="Subspecialty: {{ ss.name }}">{{ ss.name }}</span>{% endif %}
{% endfor %}
{% with case.get_series_info as series_info %}
{% if series_info.in_series %}
<span class="badge bg-info text-dark ms-1" title="Linked case series position: {{ series_info.position }} of {{ series_info.total }}">
Series ({{ series_info.position }}/{{ series_info.total }})
</span>
{% endif %}
{% endwith %}
</div>
<p class="mb-1 text-truncate">{% if case.description %}{{ case.description|truncatechars:140 }}{% endif %}</p>
</div>