add the ablitiy to truncate series on the site
This commit is contained in:
+77
-16
@@ -188,16 +188,27 @@ class SeriesImageBase(models.Model):
|
||||
(larger) original file will be deleted but the model object will be persisted so that
|
||||
the duplicate check continues to function.
|
||||
"""
|
||||
|
||||
position = models.IntegerField(default=0)
|
||||
upload_filename = models.CharField(max_length=255, blank=True)
|
||||
series = models.ForeignKey(
|
||||
"Series", related_name="images", on_delete=models.SET_NULL, null=True
|
||||
)
|
||||
dicom_tags_ohif = models.JSONField(help_text="Holds the dicom tags required for the OHIF viewer", blank=True, null=True)
|
||||
dicom_tags_ohif = models.JSONField(
|
||||
help_text="Holds the dicom tags required for the OHIF viewer",
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
image_md5_hash = models.CharField(max_length=32, null=True, blank=True)
|
||||
is_dicom = models.BooleanField(default=False)
|
||||
|
||||
removed = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Set to true if the file this object refers to has been removed (either from series truncation or merging)",
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
ordering = ["position"]
|
||||
abstract = True
|
||||
@@ -219,26 +230,31 @@ class SeriesImageBase(models.Model):
|
||||
def save(self, *args, **kwargs):
|
||||
"""Override save method to add image hash"""
|
||||
if self.image:
|
||||
|
||||
if not self.image_md5_hash:
|
||||
image_hash, is_dicom = get_image_hash(self.image)
|
||||
|
||||
self.is_dicom = is_dicom
|
||||
self.image_md5_hash = image_hash
|
||||
|
||||
|
||||
# Hack for tests
|
||||
if image_hash != "12345ABCD":
|
||||
super().save(*args, **kwargs) # Call the "real" save() method.
|
||||
|
||||
super().save(*args, **kwargs) # Call the "real" save() method.
|
||||
|
||||
|
||||
class SeriesBase(models.Model):
|
||||
info = models.TextField(
|
||||
blank=True,
|
||||
help_text="Description of stack, for admin organisation, will not be visible when taking",
|
||||
)
|
||||
|
||||
description = models.CharField(null=True, blank=True, max_length=255, help_text="Description of the series. This is usually visable to the user (as the name of the stack)")
|
||||
description = models.CharField(
|
||||
null=True,
|
||||
blank=True,
|
||||
max_length=255,
|
||||
help_text="Description of the series. This is usually visable to the user (as the name of the stack)",
|
||||
)
|
||||
|
||||
open_access = models.BooleanField(
|
||||
help_text="If a series should be freely available to browse", default=True
|
||||
@@ -247,12 +263,29 @@ class SeriesBase(models.Model):
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
modified_date = models.DateTimeField(auto_now=True)
|
||||
|
||||
class SeriesModifiedChocies(models.TextChoices):
|
||||
NO = "NO", "Not modified",
|
||||
TR = "TR", "Truncated",
|
||||
RE = "RE", "Resliced/resampled",
|
||||
|
||||
|
||||
modified = models.CharField(max_length=2, default=SeriesModifiedChocies.NO, choices=SeriesModifiedChocies.choices)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.pk}:{self.description}"
|
||||
|
||||
def check_user_can_edit(self, user: User):
|
||||
if user.is_superuser:
|
||||
return True
|
||||
|
||||
if user in self.get_author_objects():
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def get_author_objects(self):
|
||||
"""Returns a comma seperated text list of authors"""
|
||||
if self.author:
|
||||
@@ -280,25 +313,47 @@ class SeriesBase(models.Model):
|
||||
contrast = " {}".format(self.contrast)
|
||||
return "{}{}{}".format(examination, plane, contrast)
|
||||
|
||||
def get_images(self, include_removed=False):
|
||||
if include_removed:
|
||||
return self.images.all()
|
||||
else:
|
||||
return self.images.filter(removed=False)
|
||||
|
||||
def get_image_count(self):
|
||||
return self.images.filter(removed=False).count()
|
||||
|
||||
def get_image_urls(self):
|
||||
images = [f"{REMOTE_URL}{i.image.url}" for i in self.images.all()]
|
||||
images = [
|
||||
f"{REMOTE_URL}{i.image.url}" for i in self.images.filter(removed=False)
|
||||
]
|
||||
|
||||
return ",".join(images)
|
||||
|
||||
def get_image_url_array_not_json(self):
|
||||
return self.get_image_url_array(json_output=False)
|
||||
|
||||
def get_image_url_array(self, json_output=True):
|
||||
images = [f"{REMOTE_URL}{i.image.url}" for i in self.images.all()]
|
||||
def get_image_url_array_and_count(self, json_output=True):
|
||||
return self.get_image_url_array(json_output=json_output, count=True)
|
||||
|
||||
def get_image_url_array(self, json_output=True, count=False):
|
||||
images = [
|
||||
f"{REMOTE_URL}{i.image.url}" for i in self.images.filter(removed=False)
|
||||
]
|
||||
|
||||
if json_output:
|
||||
return json.dumps(images)
|
||||
if count:
|
||||
return (json.dumps(images), len(images))
|
||||
else:
|
||||
return json.dumps(images)
|
||||
else:
|
||||
# This is a mess...
|
||||
return format_html('", "'.join(images))
|
||||
if count:
|
||||
return (format_html('", "'.join(images)), len(images))
|
||||
else:
|
||||
return format_html('", "'.join(images))
|
||||
|
||||
def get_thumbnail(self):
|
||||
images = self.images.all()
|
||||
images = self.images.filter(removed=False)
|
||||
|
||||
if len(images) < 1:
|
||||
return "No images", 0
|
||||
@@ -343,7 +398,7 @@ class SeriesBase(models.Model):
|
||||
)
|
||||
|
||||
def order_by_upload_filename(self):
|
||||
images = self.images.all()
|
||||
images = self.images.filter(removed=False)
|
||||
|
||||
filenames = []
|
||||
map = {}
|
||||
@@ -362,7 +417,7 @@ class SeriesBase(models.Model):
|
||||
n = n + 1
|
||||
|
||||
def order_by_dicom(self, field="SliceLocation"):
|
||||
images = self.images.all()
|
||||
images = self.images.filter(removed=False)
|
||||
|
||||
files = []
|
||||
|
||||
@@ -400,7 +455,7 @@ class SeriesBase(models.Model):
|
||||
n = n + 1
|
||||
|
||||
def get_total_image_size(self):
|
||||
images = self.images.all()
|
||||
images = self.images.filter(removed=False)
|
||||
|
||||
size = 0
|
||||
|
||||
@@ -415,7 +470,7 @@ class SeriesBase(models.Model):
|
||||
# even with the same dicom...
|
||||
anonymizer = dicognito.anonymizer.Anonymizer()
|
||||
|
||||
for series_image in self.images.all():
|
||||
for series_image in self.images.filter(removed=False):
|
||||
file_path = os.path.join(settings.MEDIA_ROOT, series_image.image.name)
|
||||
|
||||
try:
|
||||
@@ -1288,6 +1343,7 @@ USER_EXAM_TYPES = (
|
||||
# ("CaseCollection", "user_casecollection_exams"),
|
||||
)
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
supervisor = models.ForeignKey(
|
||||
@@ -1306,7 +1362,13 @@ class UserProfile(models.Model):
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
peninsula_trainee = models.BooleanField(default=False)
|
||||
site = models.ForeignKey("Site", on_delete=models.SET_NULL, blank=True, null=True, help_text="Primary site / rotation location")
|
||||
site = models.ForeignKey(
|
||||
"Site",
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text="Primary site / rotation location",
|
||||
)
|
||||
|
||||
def getusername(self):
|
||||
return self.user.username
|
||||
@@ -1374,4 +1436,3 @@ def create_user_profile(sender, instance, created, **kwargs):
|
||||
@receiver(post_save, sender=User)
|
||||
def save_user_profile(sender, instance, **kwargs):
|
||||
instance.userprofile.save()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user