.
This commit is contained in:
@@ -32,6 +32,8 @@ from generic.models import Examination, Condition, Sign, ExamBase, Plane, Contra
|
||||
from easy_thumbnails.files import get_thumbnailer
|
||||
from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||
|
||||
import pydicom
|
||||
|
||||
|
||||
|
||||
image_storage = FileSystemStorage(
|
||||
@@ -283,6 +285,39 @@ class LongSeries(models.Model):
|
||||
"<div>{}<br/>{}<br/>Images: {}</div>", examination, thumb, image_number
|
||||
)
|
||||
|
||||
def order_by_dicom_location(self):
|
||||
images = self.images.all()
|
||||
|
||||
files = []
|
||||
|
||||
for i in images:
|
||||
files.append((i, pydicom.dcmread(i.image.path)))
|
||||
|
||||
#print("file count: {}".format(len(files)))
|
||||
|
||||
# skip files with no SliceLocation (eg scout views)
|
||||
slices = []
|
||||
map = {}
|
||||
skipcount = 0
|
||||
for i, f in files:
|
||||
if hasattr(f, 'SliceLocation'):
|
||||
slices.append(f)
|
||||
map[f.SliceLocation] = i
|
||||
else:
|
||||
skipcount = skipcount + 1
|
||||
|
||||
print("skipped, no SliceLocation: {}".format(skipcount))
|
||||
|
||||
# ensure they are in the correct order
|
||||
slices = sorted(slices, key=lambda s: s.SliceLocation)
|
||||
|
||||
#print(slices)
|
||||
n = 1
|
||||
for f in slices:
|
||||
i = map[f.SliceLocation]
|
||||
i.position = n
|
||||
i.save()
|
||||
n = n + 1
|
||||
|
||||
# class LongImage(models.Model):
|
||||
# long = models.ForeignKey(Long,
|
||||
|
||||
Reference in New Issue
Block a user