Enhance user uploads view by grouping series by StudyInstanceUID and adding a partial template for displaying common DICOM tags
This commit is contained in:
+67
-1
@@ -1778,6 +1778,23 @@ def user_uploads(
|
||||
|
||||
series_list.sort(key=lambda l: l[-1])
|
||||
|
||||
# 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)
|
||||
if study_uid not in grouped:
|
||||
grouped[study_uid] = {
|
||||
"description": study_desc,
|
||||
"date": study_date,
|
||||
"series": [],
|
||||
}
|
||||
grouped[study_uid]["series"].append((series_uid, count, tags, date))
|
||||
|
||||
# Convert to a list preserving order sorted by group date
|
||||
grouped_series = sorted(grouped.items(), key=lambda kv: kv[1].get("date") or "")
|
||||
|
||||
case = False
|
||||
if case_id is not None:
|
||||
case = get_object_or_404(Case, pk=case_id)
|
||||
@@ -1785,7 +1802,7 @@ def user_uploads(
|
||||
return render(
|
||||
request,
|
||||
"atlas/user_uploads.html",
|
||||
{"series_list": series_list, "case": case, "user": user},
|
||||
{"series_list": series_list, "grouped_series": grouped_series, "case": case, "user": user},
|
||||
)
|
||||
|
||||
|
||||
@@ -4782,6 +4799,55 @@ def series_dicom_json(request, pk):
|
||||
return JsonResponse(series.get_ohif_dicom_json())
|
||||
|
||||
|
||||
def series_tags_partial(request, pk):
|
||||
# Accept either a numeric PK or a SeriesInstanceUID string
|
||||
series = None
|
||||
try:
|
||||
if str(pk).isdigit():
|
||||
series = Series.objects.filter(pk=int(pk)).first()
|
||||
except Exception:
|
||||
series = None
|
||||
|
||||
if series is None:
|
||||
series = Series.objects.filter(series_instance_uid=pk).first()
|
||||
|
||||
if series is None:
|
||||
return HttpResponse(status=404)
|
||||
images = list(series.images.all())
|
||||
num_images = len(images)
|
||||
|
||||
tag_values = {}
|
||||
tag_counts = {}
|
||||
|
||||
for img in images:
|
||||
ds = img.get_dicom_data()
|
||||
if not ds:
|
||||
continue
|
||||
# Iterate elements
|
||||
for elem in ds:
|
||||
kw = getattr(elem, "keyword", None) or str(elem.tag)
|
||||
try:
|
||||
val = elem.value
|
||||
except Exception:
|
||||
val = None
|
||||
if isinstance(val, pydicom.multival.MultiValue):
|
||||
sval = ",".join(map(str, val))
|
||||
else:
|
||||
sval = str(val) if val is not None else ""
|
||||
|
||||
tag_counts.setdefault(kw, 0)
|
||||
tag_counts[kw] += 1
|
||||
tag_values.setdefault(kw, set()).add(sval)
|
||||
|
||||
common_tags = {}
|
||||
for k, vals in tag_values.items():
|
||||
if tag_counts.get(k, 0) == num_images and len(vals) == 1:
|
||||
common_tags[k] = list(vals)[0]
|
||||
|
||||
html = render_to_string("atlas/partials/series_tags.html", {"common_tags": common_tags}, request=request)
|
||||
return HttpResponse(html)
|
||||
|
||||
|
||||
@user_is_collection_author_or_atlas_editor
|
||||
def delete_collection_cid_answers(request, exam_id, cid):
|
||||
collection = get_object_or_404(CaseCollection, pk=exam_id)
|
||||
|
||||
Reference in New Issue
Block a user