start adding uncat dicom
This commit is contained in:
+60
-4
@@ -77,6 +77,10 @@ def image_directory_path(instance, filename):
|
||||
return "atlas/picture/{0}".format(filename)
|
||||
|
||||
|
||||
def uncategorised_dicom_directory_path(instance, filename):
|
||||
return "atlas/dicom/{0}".format(filename)
|
||||
|
||||
|
||||
def findMiddle(input_list):
|
||||
middle = float(len(input_list)) / 2
|
||||
if middle % 2 != 0:
|
||||
@@ -409,7 +413,7 @@ class SeriesImage(SeriesImageBase):
|
||||
except InvalidDicomError:
|
||||
return {}
|
||||
|
||||
#def get_image_dicom_json(self, image_index):
|
||||
# def get_image_dicom_json(self, image_index):
|
||||
# try:
|
||||
# with pydicom.dcmread(self.image) as ds:
|
||||
# return extract_image_dicom_json_from_ds(ds, url=f"{REMOTE_URL}{self.image.url}")
|
||||
@@ -511,7 +515,6 @@ class Series(SeriesBase):
|
||||
for series_n, image in enumerate(self.images.all()):
|
||||
ds = image.get_dicom_data()
|
||||
if series_n == 0:
|
||||
|
||||
for tag in to_keep:
|
||||
if tag in ds:
|
||||
val = ds[tag].value
|
||||
@@ -522,9 +525,11 @@ class Series(SeriesBase):
|
||||
series_json[tag] = val
|
||||
|
||||
instances.append(
|
||||
extract_image_dicom_json_from_ds(ds, url=f"{REMOTE_URL}{image.image.url}", image_index=series_n)
|
||||
extract_image_dicom_json_from_ds(
|
||||
ds, url=f"{REMOTE_URL}{image.image.url}", image_index=series_n
|
||||
)
|
||||
)
|
||||
#else:
|
||||
# else:
|
||||
# instances.append(image.get_image_dicom_json(image_index))
|
||||
|
||||
description = f"{self.examination} ({self.plane})"
|
||||
@@ -788,3 +793,54 @@ class SelfReview(models.Model):
|
||||
id=self.pk,
|
||||
edit_url=edit_url,
|
||||
)
|
||||
|
||||
|
||||
class UncategorisedDicom(models.Model):
|
||||
#We use image to maintain consitency across apps
|
||||
image = models.FileField(upload_to=uncategorised_dicom_directory_path)
|
||||
|
||||
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
help_text="The user that uploaded the file",
|
||||
)
|
||||
|
||||
series = models.ForeignKey(
|
||||
"Series", related_name="imported_dicoms", on_delete=models.SET_NULL, null=True
|
||||
)
|
||||
|
||||
image_md5_hash = models.CharField(max_length=32, null=True, blank=True)
|
||||
|
||||
def get_dicom_info(self):
|
||||
try:
|
||||
ds = pydicom.read_file(self.image)
|
||||
return ds
|
||||
except pydicom.errors.InvalidDicomError:
|
||||
return None
|
||||
|
||||
def get_basic_dicom_tags(self):
|
||||
try:
|
||||
ds = pydicom.read_file(self.image)
|
||||
|
||||
to_include = (
|
||||
"StudyDescription",
|
||||
"Modality",
|
||||
"ProtocolName",
|
||||
"SeriesDescription",
|
||||
"SeriesInstanceUID",
|
||||
"BodyPartExamined",
|
||||
"SliceThickness",
|
||||
)
|
||||
|
||||
tags = {}
|
||||
|
||||
for tag in to_include:
|
||||
if tag in ds:
|
||||
tags[tag] = ds[tag]
|
||||
else:
|
||||
tags[tag] = ""
|
||||
|
||||
return ds
|
||||
except pydicom.errors.InvalidDicomError:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user