From 8201f91697fc4e97e4e28be0613fc71b799688d8 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 29 Apr 2026 21:36:20 +0100 Subject: [PATCH] fix: Improve sorting and normalization of study dates in user uploads Co-authored-by: Copilot --- atlas/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/atlas/views.py b/atlas/views.py index 4ff06c84..2c3cb102 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -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,