fix: Improve sorting and normalization of study dates in user uploads

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Ross
2026-04-29 21:36:20 +01:00
parent 082a260757
commit 8201f91697
+10 -2
View File
@@ -2280,14 +2280,22 @@ def user_uploads(
tags, date = data[series][0]
series_list.append((series, len(data[series]), tags, date))
series_list.sort(key=lambda l: l[-1])
series_list.sort(key=lambda l: l[-1] or "")
# Group series by StudyInstanceUID for better visual grouping in the template
grouped = {}
for series_uid, count, tags, date in series_list:
study_uid = tags.get("StudyInstanceUID") or tags.get("StudyID") or "unknown"
study_desc = tags.get("StudyDescription", "")
study_date = tags.get("StudyDate", date)
# Normalise to a sortable string; DICOM StudyDate is "YYYYMMDD", fall
# back to the upload's created_date converted to the same format.
raw_study_date = tags.get("StudyDate")
if raw_study_date:
study_date = str(raw_study_date)
elif hasattr(date, "strftime"):
study_date = date.strftime("%Y%m%d")
else:
study_date = str(date)
if study_uid not in grouped:
grouped[study_uid] = {
"description": study_desc,