.
This commit is contained in:
+23
-10
@@ -358,6 +358,11 @@ class SeriesImage(SeriesImageBase):
|
|||||||
"Series", related_name="images", on_delete=models.SET_NULL, null=True
|
"Series", related_name="images", on_delete=models.SET_NULL, null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_series_dicom_data(self):
|
||||||
|
print(self.image)
|
||||||
|
with pydicom.dcmread(self.image) as d:
|
||||||
|
return d
|
||||||
|
|
||||||
def get_image_dicom_json(self):
|
def get_image_dicom_json(self):
|
||||||
try:
|
try:
|
||||||
with pydicom.dcmread(self.image) as ds:
|
with pydicom.dcmread(self.image) as ds:
|
||||||
@@ -396,8 +401,6 @@ class SeriesImage(SeriesImageBase):
|
|||||||
else:
|
else:
|
||||||
d[key] = val
|
d[key] = val
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {"metadata": d, "url": f"dicomweb:{REMOTE_URL}{self.image.url}"}
|
return {"metadata": d, "url": f"dicomweb:{REMOTE_URL}{self.image.url}"}
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return []
|
return []
|
||||||
@@ -484,17 +487,27 @@ class Series(SeriesBase):
|
|||||||
def get_series_dicom_json(self):
|
def get_series_dicom_json(self):
|
||||||
instances = []
|
instances = []
|
||||||
|
|
||||||
|
series_json = {}
|
||||||
|
|
||||||
|
to_keep = ["SeriesInstanceUID", "SeriesNumber", "Modality", "SliceThickness"]
|
||||||
|
|
||||||
image: SeriesImage
|
image: SeriesImage
|
||||||
for image in self.images.all():
|
for series_n, image in enumerate(self.images.all()):
|
||||||
|
if series_n == 0:
|
||||||
|
ds = image.get_series_dicom_data()
|
||||||
|
|
||||||
|
for tag in to_keep:
|
||||||
|
if tag in ds:
|
||||||
|
val = ds[tag].value
|
||||||
|
|
||||||
|
if type(val) == pydicom.multival.MultiValue:
|
||||||
|
series_json[tag] = list(val)
|
||||||
|
else:
|
||||||
|
series_json[tag] = val
|
||||||
|
|
||||||
instances.append(image.get_image_dicom_json())
|
instances.append(image.get_image_dicom_json())
|
||||||
|
|
||||||
series_json = {
|
series_json["instances"]= instances
|
||||||
"SeriesInstanceUID": "1.3.6.1.4.1.14519.5.2.1.6279.6001.179049373636438705059720603192",
|
|
||||||
"SeriesNumber": 3000566,
|
|
||||||
"Modality": "CT",
|
|
||||||
"SliceThickness": 2.5,
|
|
||||||
"instances": instances,
|
|
||||||
}
|
|
||||||
|
|
||||||
return series_json
|
return series_json
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user