improved duplicate handling
This commit is contained in:
+11
-2
@@ -1,6 +1,7 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
from ninja import ModelSchema, Router, Schema, Field
|
from ninja import ModelSchema, Router, Schema, Field
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
@@ -8,6 +9,7 @@ from django.db import transaction
|
|||||||
# from .decorators import user_is_author_or_rapid_checker
|
# from .decorators import user_is_author_or_rapid_checker
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
import pydicom
|
import pydicom
|
||||||
|
from pydicom.errors import InvalidDicomError
|
||||||
|
|
||||||
from generic.decorators import check_user_in_group
|
from generic.decorators import check_user_in_group
|
||||||
from generic.constants import Group
|
from generic.constants import Group
|
||||||
@@ -54,6 +56,7 @@ class CaseSchema(ModelSchema):
|
|||||||
def upload_dicom(request, files: List[UploadedFile] = File(...)):
|
def upload_dicom(request, files: List[UploadedFile] = File(...)):
|
||||||
uploaded = []
|
uploaded = []
|
||||||
duplicate = []
|
duplicate = []
|
||||||
|
failed = []
|
||||||
for file in files:
|
for file in files:
|
||||||
# data = file.read()
|
# data = file.read()
|
||||||
try:
|
try:
|
||||||
@@ -66,8 +69,10 @@ def upload_dicom(request, files: List[UploadedFile] = File(...)):
|
|||||||
print(ud.check_for_duplicates(ud.image_blake3_hash))
|
print(ud.check_for_duplicates(ud.image_blake3_hash))
|
||||||
duplicate.append((file.name, ud.image_blake3_hash))
|
duplicate.append((file.name, ud.image_blake3_hash))
|
||||||
pass
|
pass
|
||||||
|
except InvalidDicomError:
|
||||||
|
failed.append(file.name)
|
||||||
|
|
||||||
return {"uploaded": uploaded, "duplicates": duplicate}
|
return {"uploaded": uploaded, "duplicates": duplicate, "failed": failed}
|
||||||
|
|
||||||
@router.post("/generate_image_hash", auth=django_auth)
|
@router.post("/generate_image_hash", auth=django_auth)
|
||||||
def generate_image_hash(request, id:int):
|
def generate_image_hash(request, id:int):
|
||||||
@@ -253,13 +258,17 @@ def check_images_hashes(request, hashes: List[str]):
|
|||||||
for hash in hashes:
|
for hash in hashes:
|
||||||
try:
|
try:
|
||||||
# TOOD also check against uncategorised dicoms?
|
# TOOD also check against uncategorised dicoms?
|
||||||
with transaction.atomic():
|
|
||||||
series_image = SeriesImage.objects.get(image_blake3_hash=hash)
|
series_image = SeriesImage.objects.get(image_blake3_hash=hash)
|
||||||
data = {
|
data = {
|
||||||
"id": series_image.pk,
|
"id": series_image.pk,
|
||||||
"url": series_image.series.get_absolute_url(),
|
"url": series_image.series.get_absolute_url(),
|
||||||
|
"type": "series"
|
||||||
}
|
}
|
||||||
except SeriesImage.DoesNotExist:
|
except SeriesImage.DoesNotExist:
|
||||||
|
try:
|
||||||
|
uncategorised_dicom = UncategorisedDicom.objects.get(image_blake3_hash=hash)
|
||||||
|
data = { "id":uncategorised_dicom.pk, "url": reverse("atlas:user_uploads"), "type": "uncategorised"}
|
||||||
|
except UncategorisedDicom.DoesNotExist:
|
||||||
data = { "id": False, "url": False}
|
data = { "id": False, "url": False}
|
||||||
|
|
||||||
hash_status[hash] = data
|
hash_status[hash] = data
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<a href="{% url 'atlas:categories_list' %}">Categories</a> /
|
<a href="{% url 'atlas:categories_list' %}">Categories</a> /
|
||||||
<a href="{% url 'atlas:case_create' %}" title="Create a new atlas case">Create Case</a> /
|
<a href="{% url 'atlas:case_create' %}" title="Create a new atlas case">Create Case</a> /
|
||||||
<a href="{% url 'atlas:series_create' %}" title="Create a new image series">Create Series</a> /
|
<a href="{% url 'atlas:series_create' %}" title="Create a new image series">Create Series</a> /
|
||||||
|
<a href="{% url 'atlas:user_uploads' %}" title="View unimported uploads">Uploads</a> /
|
||||||
<a href="{% url 'atlas:help' %}" title="View the atlas help pages">Help</a>
|
<a href="{% url 'atlas:help' %}" title="View the atlas help pages">Help</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% comment %} </br>
|
{% comment %} </br>
|
||||||
|
|||||||
@@ -452,7 +452,6 @@ def user_uploads(request, case_id: int | None = None, user_only: bool = True, us
|
|||||||
for series in data:
|
for series in data:
|
||||||
tags, date = data[series][0]
|
tags, date = data[series][0]
|
||||||
series_list.append((series, len(data[series]), tags, date))
|
series_list.append((series, len(data[series]), tags, date))
|
||||||
print(series_list)
|
|
||||||
|
|
||||||
series_list.sort(key=lambda l: l[-1])
|
series_list.sort(key=lambda l: l[-1])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user