fix: Improve sorting and normalization of study dates in user uploads
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
+10
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user