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