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 UID and birthdate error handling #147

Merged
merged 3 commits into from
Sep 10, 2024
Merged
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
40 changes: 28 additions & 12 deletions oct_converter/readers/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

import numpy as np
from construct.core import StreamError

from oct_converter.image_types import FundusImageWithMetaData, OCTVolumeWithMetaData
from oct_converter.readers.binary_structs import e2e_binary
Expand Down Expand Up @@ -137,14 +138,26 @@ def _make_lut():
self.sex = patient_data.sex
self.first_name = patient_data.first_name
self.surname = patient_data.surname
julian_birthdate = (patient_data.birthdate / 64) - 14558805
self.birthdate = self.julian_to_ymd(julian_birthdate)
# TODO: There are conflicting ideas of how to parse E2E's birthdate
# https://bitbucket.org/uocte/uocte/wiki/Heidelberg%20File%20Format suggests the above,
# whereas https://github.com/neurodial/LibE2E/blob/master/E2E/dataelements/patientdataelement.cpp
# suggests that DOB is given as a Windows date. Neither option seems accurate to
# test files with known-correct birthdates. More investigation is needed.
self.patient_id = patient_data.patient_id
if len(str(patient_data.birthdate)) == 8:
# Encountered a file where birthdate had been stored as YYYYMMDD,
# this is an attempt to catch that.
self.birthdate = str(patient_data.birthdate)
else:
try:
julian_birthdate = (
patient_data.birthdate / 64
) - 14558805
self.birthdate = self.julian_to_ymd(julian_birthdate)
# TODO: There are conflicting ideas of how to parse E2E's birthdate
# https://bitbucket.org/uocte/uocte/wiki/Heidelberg%20File%20Format suggests the above,
# whereas https://github.com/neurodial/LibE2E/blob/master/E2E/dataelements/patientdataelement.cpp
# suggests that DOB is given as a Windows date. Neither option seems accurate to
# test files with known-correct birthdates. More investigation is needed.
except ValueError:
# If the julian_to_ymd function cannot parse it into a date obj,
# it throws a ValueError
self.birthdate = None
except Exception:
pass

Expand Down Expand Up @@ -564,11 +577,14 @@ def _convert_to_dict(container):
metadata["time_data"].append(_convert_to_dict(time_data))

elif chunk.type in [52, 54, 1000, 1001]: # various UIDs
raw = f.read(chunk.size)
uid_data = e2e_binary.uid_data.parse(raw)
metadata["uid_data"].append(
{chunk.type: _convert_to_dict(uid_data)}
)
try:
raw = f.read(chunk.size)
uid_data = e2e_binary.uid_data.parse(raw)
metadata["uid_data"].append(
{chunk.type: _convert_to_dict(uid_data)}
)
except StreamError:
pass

# Chunks 1005, 1006, and 1007 seem to contain strings of device data,
# including some servicers and distributors and other entities,
Expand Down
Loading