diff --git a/atlas/api.py b/atlas/api.py index 4a443e71..dedaf4b8 100644 --- a/atlas/api.py +++ b/atlas/api.py @@ -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}"] \ No newline at end of file + return [f"{series} ordered by {dicom_tag}"] diff --git a/atlas/models.py b/atlas/models.py index 9eb56f7c..4cc064a0 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -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" diff --git a/atlas/templates/atlas/case_display_block.html b/atlas/templates/atlas/case_display_block.html index 0bbd4484..08718652 100755 --- a/atlas/templates/atlas/case_display_block.html +++ b/atlas/templates/atlas/case_display_block.html @@ -27,6 +27,7 @@

Report: {{ case.report }}

Series: +
{% for series in case.series.all %} @@ -35,6 +36,7 @@ {{series.get_block}}
+ Popup @@ -42,6 +44,7 @@
{% endfor %} + Add new series
Import new uploads
@@ -55,6 +58,26 @@ > Order all series dicoms by slice location + + +
+
diff --git a/atlas/urls.py b/atlas/urls.py index 8e114a8f..6cbb0d2e 100755 --- a/atlas/urls.py +++ b/atlas/urls.py @@ -158,6 +158,11 @@ urlpatterns = [ views.case_dicom_json, name="case_dicom_json", ), + path( + "case//use_dates_as_descriptions", + views.use_dates_as_descriptions, + name="use_dates_as_descriptions", + ), path( "series//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"), ] diff --git a/atlas/views.py b/atlas/views.py index 9d9d89a1..7bd8dac5 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -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") \ No newline at end of file diff --git a/generic/models.py b/generic/models.py index ccb37a47..012221b6 100644 --- a/generic/models.py +++ b/generic/models.py @@ -432,18 +432,23 @@ class SeriesBase(models.Model): series_html = "" if series_number is not None: series_html = format_html( - "Series {}
", - series_number, + "Series {}{}
", + series_number ) + description = "" + if self.description: + description = format_html("{}
", self.description) + return format_html( - """{} + """{}{} {}
{}
Images: {}
""", series_html, + description, examination, thumb, image_number,