add some new functions to case series

This commit is contained in:
Ross
2024-02-26 13:27:54 +00:00
parent f63f4c6fa5
commit 77473a35d0
6 changed files with 95 additions and 6 deletions
+1 -3
View File
@@ -104,9 +104,7 @@ def uncategorised_dicoms(request):
return data
@logger.catch()
def import_dicoms_helper(request, case_id: int | None = None):
logger.debug(f"IMPORT {case_id}")
#dicoms = UncategorisedDicom.objects.filter(user=request.user)
if "selection" in request.POST:
dicoms = UncategorisedDicom.objects.filter(series_instance_uid__in=request.POST.getlist("selection"))
@@ -332,4 +330,4 @@ def series_order_by_tag(request, series_id: int, dicom_tag:str):
series.order_by_dicom(dicom_tag)
return [f"{series} ordered by {dicom_tag}"]
return [f"{series} ordered by {dicom_tag}"]
+11
View File
@@ -648,6 +648,17 @@ class Series(SeriesBase):
]
}
def use_date_as_description(self):
# get first image
image = self.images.first()
with pydicom.dcmread(image.image) as ds:
date = ds.get("StudyDate", "No date")
self.description = date
self.save()
class CaseCollection(ExamOrCollectionGenericBase):
app_name = "atlas"
@@ -27,6 +27,7 @@
<p class="pre-whitespace"><b>Report:</b> {{ case.report }}</p>
<div class="pre-whitespace multi-image-block"><b>Series:</b>
<form>
{% for series in case.series.all %}
<span class="series-block">
<span>
@@ -35,6 +36,7 @@
{{series.get_block}}
</a>
<br>
<input type="checkbox" name="series-ids" value="{{series.pk}}">
<span class="series-block-popup-link">
<a href="#"
onclick="return window.create_popup_window('/atlas/series/{{series.pk}}', 'Series')">Popup</a>
@@ -42,6 +44,7 @@
</span>
</span>
{% endfor %}
</form>
<span>
<a href="{% url 'atlas:series_id_create' pk=case.pk %}">Add new series</a><br />
<a href="{% url 'atlas:user_uploads_case' case_id=case.pk %}">Import new uploads</a><br />
@@ -55,6 +58,26 @@
>
Order all series dicoms by slice location
</button>
<button hx-post="{% url 'atlas:combine_series' %}"
title="merge series"
hx-include="[name='series-ids']"
hx-target="#series-merge-results"
hx-swap="innerHTML"
hx-confirm="This will merge all selected series into one"
>
Merge selected series
</button>
<button hx-post="{% url 'atlas:use_dates_as_descriptions' case.pk %}"
title="merge series"
hx-include="[name='series-ids']"
hx-target="#series-merge-results"
hx-swap="innerHTML"
hx-confirm="This will use the dicom date as the series description"
>
Use dates as description
</button>
<br/>
<span id="series-merge-results"></span>
</details>
</span>
+6
View File
@@ -158,6 +158,11 @@ urlpatterns = [
views.case_dicom_json,
name="case_dicom_json",
),
path(
"case/<int:pk>/use_dates_as_descriptions",
views.use_dates_as_descriptions,
name="use_dates_as_descriptions",
),
path(
"series/<int:pk>/dicom_json",
views.series_dicom_json,
@@ -349,4 +354,5 @@ urlpatterns = [
views.pathological_process_detail,
name="pathological_process_detail",
),
path("combine_series/", views.combine_series, name="combine_series"),
]
+46
View File
@@ -1848,6 +1848,16 @@ def collection_dicom_json(request, pk):
return JsonResponse(collection.get_ohif_dicom_json())
@user_is_author_or_atlas_editor
def use_dates_as_descriptions(request, pk):
case = get_object_or_404(Case, pk=pk)
series: Series
for series in case.series.all():
series.use_date_as_description()
return HttpResponse("Done")
def case_dicom_json(request, pk):
case = get_object_or_404(Case, pk=pk)
@@ -2194,3 +2204,39 @@ def uncategorised_dicoms(request):
data.append((d.image.name, d.get_basic_dicom_tags()))
return JsonResponse(data, safe=False)
@login_required
def combine_series(request):
"""Combines a list of series into the first series in the list
NOTE: this will only migrate images
it will not migrate other models such as SeriesFinding or other details
"""
series_ids = request.POST.getlist("series-ids")
#series = get_object_or_404(Series, pk=series_id)
if len(series_ids) < 2:
return HttpResponse("Not enough series to combine")
base_series = None
series_to_add = []
for n, series_id in enumerate(series_ids):
series = get_object_or_404(Series, pk=series_id)
if not series.check_user_can_edit(request.user):
return HttpResponse("You do not have permission to edit one of the series")
if n == 0:
base_series = series
else:
series_to_add.append(series)
for series in series_to_add:
for image in series.images.all():
image.series = base_series
image.save()
series.delete()
return HttpResponse(f"Series {series_ids} combines")
#return HttpResponse("Fail")
+8 -3
View File
@@ -432,18 +432,23 @@ class SeriesBase(models.Model):
series_html = ""
if series_number is not None:
series_html = format_html(
"<span class='series-block-series-number'>Series {}</span><br>",
series_number,
"<span class='series-block-series-number'>Series {}</span>{}<br>",
series_number
)
description = ""
if self.description:
description = format_html("{}<br/>", self.description)
return format_html(
"""{}
"""{}{}
<span>
<span class='series-block-examination'>{}</span><br/>
<span class='series-block-thumbnail'>{}</span><br/>
<span class='series-block-image-number'>Images: <span class='series-block-image-number-count'>{}</span></span>
</span>""",
series_html,
description,
examination,
thumb,
image_number,