Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E file read changes #151

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions oct_converter/dicom/e2e_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ def e2e_patient_meta(meta: dict) -> PatientMeta:
"""
patient = PatientMeta()

patient_data = meta.get("patient_data", [{}])

patient.first_name = patient_data[0].get("first_name")
patient.last_name = patient_data[0].get("surname")
patient.patient_id = patient_data[0].get("patient_id")
patient.patient_sex = patient_data[0].get("sex")
# TODO patient.patient_dob
# Currently, E2E's patient_dob is incorrect, see
# the E2E reader for more context.
patient_data = meta.get("patient_data")
if patient_data:
# Heidelberg's updated anonymization process wipes
# this section of metadata
patient.first_name = patient_data[0].get("first_name")
patient.last_name = patient_data[0].get("surname")
patient.patient_id = patient_data[0].get("patient_id")
patient.patient_sex = patient_data[0].get("sex")
# TODO patient.patient_dob
# Currently, E2E's patient_dob is incorrect, see
# the E2E reader for more context.

return patient

Expand Down
25 changes: 22 additions & 3 deletions oct_converter/readers/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, filepath: str | Path) -> None:
self.acquisition_date = None
self.birthdate = None
self.pixel_spacing = None
self.patient_id = None

# get initial directory structure
with open(self.filepath, "rb") as f:
Expand Down Expand Up @@ -129,7 +130,13 @@ def _make_lut():
for start, pos in chunk_stack:
f.seek(start + self.byte_skip)
raw = f.read(60)
chunk = e2e_binary.chunk_structure.parse(raw)
try:
# Heidelberg's updated anonymization seems to cause problems with
# some chunks. Observed problems include an empty raw and problems
# with undecodable bytes. For now, these chunks are skipped...
chunk = e2e_binary.chunk_structure.parse(raw)
except Exception:
continue

if chunk.type == 9: # patient data
raw = f.read(127)
Expand Down Expand Up @@ -358,7 +365,13 @@ def read_fundus_image(
for start, pos in chunk_stack:
f.seek(start + self.byte_skip)
raw = f.read(60)
chunk = e2e_binary.chunk_structure.parse(raw)
try:
# Heidelberg's updated anonymization seems to cause problems with
# some chunks. Observed problems include an empty raw and problems
# with undecodable bytes. For now, these chunks are skipped...
chunk = e2e_binary.chunk_structure.parse(raw)
except Exception:
continue

if chunk.type == 9: # patient data
raw = f.read(127)
Expand Down Expand Up @@ -489,7 +502,13 @@ def _convert_to_dict(container):
for start, pos in chunk_stack:
f.seek(start + self.byte_skip)
raw = f.read(60)
chunk = e2e_binary.chunk_structure.parse(raw)
try:
# Heidelberg's updated anonymization seems to cause problems with
# some chunks. Observed problems include an empty raw and problems
# with undecodable bytes. For now, these chunks are skipped...
chunk = e2e_binary.chunk_structure.parse(raw)
except Exception:
continue

image_string = "{}_{}_{}".format(
chunk.patient_db_id, chunk.study_id, chunk.series_id
Expand Down