fake SOPInsanceUID
This commit is contained in:
+21
-16
@@ -351,7 +351,7 @@ class Case(models.Model):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def extract_image_dicom_json_from_ds(ds, url):
|
def extract_image_dicom_json_from_ds(ds, url, image_index):
|
||||||
to_keep = [
|
to_keep = [
|
||||||
"Columns",
|
"Columns",
|
||||||
"Rows",
|
"Rows",
|
||||||
@@ -388,6 +388,9 @@ def extract_image_dicom_json_from_ds(ds, url):
|
|||||||
else:
|
else:
|
||||||
d[key] = val
|
d[key] = val
|
||||||
|
|
||||||
|
if d == {}:
|
||||||
|
d["SOPInstanceUID"] = f"1.2.840.1111.{image_index}"
|
||||||
|
|
||||||
return {"metadata": d, "url": f"dicomweb:{url}"}
|
return {"metadata": d, "url": f"dicomweb:{url}"}
|
||||||
|
|
||||||
|
|
||||||
@@ -397,7 +400,7 @@ 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_extra_dicom_data(self):
|
def get_dicom_data(self):
|
||||||
print(self.image)
|
print(self.image)
|
||||||
try:
|
try:
|
||||||
with pydicom.dcmread(self.image) as d:
|
with pydicom.dcmread(self.image) as d:
|
||||||
@@ -405,14 +408,16 @@ class SeriesImage(SeriesImageBase):
|
|||||||
except InvalidDicomError:
|
except InvalidDicomError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_image_dicom_json(self):
|
#def get_image_dicom_json(self, image_index):
|
||||||
try:
|
# try:
|
||||||
with pydicom.dcmread(self.image) as ds:
|
# with pydicom.dcmread(self.image) as ds:
|
||||||
return extract_image_dicom_json_from_ds(ds, url=f"{REMOTE_URL}{self.image.url}")
|
# return extract_image_dicom_json_from_ds(ds, url=f"{REMOTE_URL}{self.image.url}")
|
||||||
except FileNotFoundError:
|
# except FileNotFoundError:
|
||||||
return []
|
# return []
|
||||||
except InvalidDicomError:
|
# except InvalidDicomError:
|
||||||
return {"url": f"dicomweb:{REMOTE_URL}{self.image.url}"}
|
# return {"url": f"dicomweb:{REMOTE_URL}{self.image.url}", "metadata": {
|
||||||
|
# "SOPInstanceUID" : f"1.2.840.1111.{image_index}"
|
||||||
|
# }}
|
||||||
|
|
||||||
|
|
||||||
class SeriesFinding(models.Model):
|
class SeriesFinding(models.Model):
|
||||||
@@ -503,8 +508,8 @@ class Series(SeriesBase):
|
|||||||
# TODO: clean up (this is rather convoluted....)
|
# TODO: clean up (this is rather convoluted....)
|
||||||
image: SeriesImage
|
image: SeriesImage
|
||||||
for series_n, image in enumerate(self.images.all()):
|
for series_n, image in enumerate(self.images.all()):
|
||||||
|
ds = image.get_dicom_data()
|
||||||
if series_n == 0:
|
if series_n == 0:
|
||||||
ds = image.get_extra_dicom_data()
|
|
||||||
|
|
||||||
for tag in to_keep:
|
for tag in to_keep:
|
||||||
if tag in ds:
|
if tag in ds:
|
||||||
@@ -515,11 +520,11 @@ class Series(SeriesBase):
|
|||||||
else:
|
else:
|
||||||
series_json[tag] = val
|
series_json[tag] = val
|
||||||
|
|
||||||
instances.append(
|
instances.append(
|
||||||
extract_image_dicom_json_from_ds(ds, url=f"{REMOTE_URL}{image.image.url}")
|
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())
|
# instances.append(image.get_image_dicom_json(image_index))
|
||||||
|
|
||||||
description = f"{self.examination} ({self.plane})"
|
description = f"{self.examination} ({self.plane})"
|
||||||
if self.contrast:
|
if self.contrast:
|
||||||
|
|||||||
Reference in New Issue
Block a user