basic support for bulk series uploading

This commit is contained in:
Ross
2023-08-14 12:39:26 +01:00
parent 9ae1874073
commit d4eda9fdfb
10 changed files with 259 additions and 12 deletions
+26 -3
View File
@@ -32,7 +32,7 @@ from sortedm2m.fields import SortedManyToManyField
import string
from collections import defaultdict
from helpers.images import image_as_base64, pretty_print_dicom
from helpers.images import get_image_hash, image_as_base64, pretty_print_dicom
from generic.models import (
@@ -452,6 +452,7 @@ class Series(SeriesBase):
related_name="atlas_series_modality",
on_delete=models.SET_NULL,
null=True,
blank=True,
)
examination = models.ForeignKey(
Examination,
@@ -459,6 +460,7 @@ class Series(SeriesBase):
related_name="atlas_series_examination",
on_delete=models.SET_NULL,
null=True,
blank=True,
)
plane = models.ForeignKey(
Plane,
@@ -483,6 +485,8 @@ class Series(SeriesBase):
related_name="series",
)
series_instance_uid = models.CharField(max_length=255, blank=True, null=True)
# findings = models.TextField(null=True, blank=True, help_text="Findings on the series / stack")
def get_full_str(self):
@@ -811,6 +815,22 @@ class UncategorisedDicom(models.Model):
)
image_md5_hash = models.CharField(max_length=32, null=True, blank=True)
is_dicom = models.BooleanField(default=False)
def save(self, *args, **kwargs):
"""Override save method to add image hash"""
if self.image:
image_hash, is_dicom = get_image_hash(self.image)
self.is_dicom = is_dicom
self.image_md5_hash = image_hash
if UncategorisedDicom.objects.filter(image_md5_hash=image_hash):
raise DuplicateDicom
# Hack for tests
if image_hash != "12345ABCD":
super().save(*args, **kwargs) # Call the "real" save() method.
def get_dicom_info(self):
try:
@@ -837,10 +857,13 @@ class UncategorisedDicom(models.Model):
for tag in to_include:
if tag in ds:
tags[tag] = ds[tag]
tags[tag] = ds[tag].value
else:
tags[tag] = ""
return ds
return tags
except pydicom.errors.InvalidDicomError:
return None
class DuplicateDicom(Exception):
pass