Skip to content

Commit

Permalink
Merge pull request #147 from sustrev/main
Browse files Browse the repository at this point in the history
E2E UID and birthdate error handling
  • Loading branch information
marksgraham authored Sep 10, 2024
2 parents 116b9e2 + d6ca342 commit 1bc6422
Showing 1 changed file with 28 additions and 12 deletions.
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

0 comments on commit 1bc6422

Please sign in to comment.