This commit is contained in:
Ross
2021-09-01 22:37:03 +01:00
parent 9a608aa926
commit 265f5c7830
2 changed files with 37 additions and 3 deletions
+34
View File
@@ -111,3 +111,37 @@ def get_dicom_order(path):
print(map[i.SliceLocation])
#get_dicom_order("/home/ross/Downloads/DICOM HEAD/STD4/SER1/*.dcm")
def pretty_print_dicom(dataset, indent=0):
return "\n<br/>".join(print_dicom(dataset, indent))
def print_dicom(dataset, indent=0):
"""Go through all items in the dataset and print them with custom format
Modelled after Dataset._pretty_str()
"""
dont_print = ['Pixel Data', 'File Meta Information Version']
indent_string = " " * indent
next_indent_string = " " * (indent + 1)
l = []
for data_element in dataset:
if data_element.VR == "SQ": # a sequence
l.append(f"({indent_string}{data_element.name}")
for sequence_item in data_element.value:
l.append(print_dicom(sequence_item, indent + 1))
l.append(next_indent_string + "---------")
else:
if data_element.name in dont_print:
l.append("""<item not printed -- in the "don't print" list>""")
else:
repr_value = repr(data_element.value)
if len(repr_value) > 50:
repr_value = repr_value[:50] + "..."
l.append("{0:s} {1:s} = {2:s}".format(indent_string,
data_element.name,
repr_value))
return l
+2 -2
View File
@@ -24,7 +24,7 @@ from sortedm2m.fields import SortedManyToManyField
import string
from collections import defaultdict
from helpers.images import image_as_base64
from helpers.images import image_as_base64, pretty_print_dicom
from anatomy.models import Modality
@@ -317,7 +317,7 @@ class LongSeriesImage(models.Model):
def get_dicom_info(self):
try:
info = pydicom.read_file(self.image).to_json()
info = pretty_print_dicom(pydicom.read_file(self.image))
except pydicom.errors.InvalidDicomError:
info = "File is not a dicom."
return(info)