This commit is contained in:
Ross
2021-11-21 10:56:20 +00:00
parent f57da9ec49
commit e213593467
+3 -2
View File
@@ -457,11 +457,12 @@ class RapidImage(models.Model):
if self.image:
# Try and read the file as a dicom
try:
# and generate a hash from the pixel data
hash = ",".join(pydicom.dcmread(self.image.path).pixel_array.tostring())
self.is_dicom = True
except pydicom.errors.InvalidDicomError:
with self.image.open("r") as f:
hash = hashlib.md5(f).hexdigest()
self.image.file.open()
hash = hashlib.md5(self.image.file).hexdigest()
self.image_md5_hash = hash
super().save(*args, **kwargs) # Call the "real" save() method.