add some new functions to case series
This commit is contained in:
@@ -104,9 +104,7 @@ def uncategorised_dicoms(request):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@logger.catch()
|
|
||||||
def import_dicoms_helper(request, case_id: int | None = None):
|
def import_dicoms_helper(request, case_id: int | None = None):
|
||||||
logger.debug(f"IMPORT {case_id}")
|
|
||||||
#dicoms = UncategorisedDicom.objects.filter(user=request.user)
|
#dicoms = UncategorisedDicom.objects.filter(user=request.user)
|
||||||
if "selection" in request.POST:
|
if "selection" in request.POST:
|
||||||
dicoms = UncategorisedDicom.objects.filter(series_instance_uid__in=request.POST.getlist("selection"))
|
dicoms = UncategorisedDicom.objects.filter(series_instance_uid__in=request.POST.getlist("selection"))
|
||||||
|
|||||||
@@ -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):
|
class CaseCollection(ExamOrCollectionGenericBase):
|
||||||
app_name = "atlas"
|
app_name = "atlas"
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
<p class="pre-whitespace"><b>Report:</b> {{ case.report }}</p>
|
<p class="pre-whitespace"><b>Report:</b> {{ case.report }}</p>
|
||||||
|
|
||||||
<div class="pre-whitespace multi-image-block"><b>Series:</b>
|
<div class="pre-whitespace multi-image-block"><b>Series:</b>
|
||||||
|
<form>
|
||||||
{% for series in case.series.all %}
|
{% for series in case.series.all %}
|
||||||
<span class="series-block">
|
<span class="series-block">
|
||||||
<span>
|
<span>
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
{{series.get_block}}
|
{{series.get_block}}
|
||||||
</a>
|
</a>
|
||||||
<br>
|
<br>
|
||||||
|
<input type="checkbox" name="series-ids" value="{{series.pk}}">
|
||||||
<span class="series-block-popup-link">
|
<span class="series-block-popup-link">
|
||||||
<a href="#"
|
<a href="#"
|
||||||
onclick="return window.create_popup_window('/atlas/series/{{series.pk}}', 'Series')">Popup</a>
|
onclick="return window.create_popup_window('/atlas/series/{{series.pk}}', 'Series')">Popup</a>
|
||||||
@@ -42,6 +44,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</form>
|
||||||
<span>
|
<span>
|
||||||
<a href="{% url 'atlas:series_id_create' pk=case.pk %}">Add new series</a><br />
|
<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 />
|
<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
|
Order all series dicoms by slice location
|
||||||
</button>
|
</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>
|
</details>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -158,6 +158,11 @@ urlpatterns = [
|
|||||||
views.case_dicom_json,
|
views.case_dicom_json,
|
||||||
name="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(
|
path(
|
||||||
"series/<int:pk>/dicom_json",
|
"series/<int:pk>/dicom_json",
|
||||||
views.series_dicom_json,
|
views.series_dicom_json,
|
||||||
@@ -349,4 +354,5 @@ urlpatterns = [
|
|||||||
views.pathological_process_detail,
|
views.pathological_process_detail,
|
||||||
name="pathological_process_detail",
|
name="pathological_process_detail",
|
||||||
),
|
),
|
||||||
|
path("combine_series/", views.combine_series, name="combine_series"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1848,6 +1848,16 @@ def collection_dicom_json(request, pk):
|
|||||||
|
|
||||||
return JsonResponse(collection.get_ohif_dicom_json())
|
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):
|
def case_dicom_json(request, pk):
|
||||||
case = get_object_or_404(Case, pk=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()))
|
data.append((d.image.name, d.get_basic_dicom_tags()))
|
||||||
|
|
||||||
return JsonResponse(data, safe=False)
|
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
@@ -432,18 +432,23 @@ class SeriesBase(models.Model):
|
|||||||
series_html = ""
|
series_html = ""
|
||||||
if series_number is not None:
|
if series_number is not None:
|
||||||
series_html = format_html(
|
series_html = format_html(
|
||||||
"<span class='series-block-series-number'>Series {}</span><br>",
|
"<span class='series-block-series-number'>Series {}</span>{}<br>",
|
||||||
series_number,
|
series_number
|
||||||
)
|
)
|
||||||
|
description = ""
|
||||||
|
if self.description:
|
||||||
|
description = format_html("{}<br/>", self.description)
|
||||||
|
|
||||||
|
|
||||||
return format_html(
|
return format_html(
|
||||||
"""{}
|
"""{}{}
|
||||||
<span>
|
<span>
|
||||||
<span class='series-block-examination'>{}</span><br/>
|
<span class='series-block-examination'>{}</span><br/>
|
||||||
<span class='series-block-thumbnail'>{}</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 class='series-block-image-number'>Images: <span class='series-block-image-number-count'>{}</span></span>
|
||||||
</span>""",
|
</span>""",
|
||||||
series_html,
|
series_html,
|
||||||
|
description,
|
||||||
examination,
|
examination,
|
||||||
thumb,
|
thumb,
|
||||||
image_number,
|
image_number,
|
||||||
|
|||||||
Reference in New Issue
Block a user