From 82dd085c39fdddc32fa12419bc475911d22c497a Mon Sep 17 00:00:00 2001 From: Susannah Trevino Date: Tue, 27 Aug 2024 09:02:34 -0500 Subject: [PATCH 1/3] Add try except wrapper for E2E UID chunk --- oct_converter/readers/e2e.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/oct_converter/readers/e2e.py b/oct_converter/readers/e2e.py index 0c77cd7..bae3631 100644 --- a/oct_converter/readers/e2e.py +++ b/oct_converter/readers/e2e.py @@ -6,6 +6,7 @@ from datetime import date, datetime from itertools import chain from pathlib import Path +from construct.core import StreamError import numpy as np @@ -564,11 +565,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, From 93ebcd39b2c3fb479db357c0690cdaa904f35caa Mon Sep 17 00:00:00 2001 From: Susannah Trevino Date: Mon, 9 Sep 2024 15:26:08 -0500 Subject: [PATCH 2/3] Update E2E birthdate setting --- oct_converter/readers/e2e.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/oct_converter/readers/e2e.py b/oct_converter/readers/e2e.py index bae3631..a12a2f7 100644 --- a/oct_converter/readers/e2e.py +++ b/oct_converter/readers/e2e.py @@ -138,14 +138,24 @@ 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 From d6ca342223092866ef3c99fd297469de5a7b776a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:11:52 +0000 Subject: [PATCH 3/3] [pre-commit.ci lite] apply automatic fixes --- oct_converter/readers/e2e.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oct_converter/readers/e2e.py b/oct_converter/readers/e2e.py index a12a2f7..d0ccee1 100644 --- a/oct_converter/readers/e2e.py +++ b/oct_converter/readers/e2e.py @@ -6,9 +6,9 @@ from datetime import date, datetime from itertools import chain from pathlib import Path -from construct.core import StreamError 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 @@ -145,7 +145,9 @@ def _make_lut(): self.birthdate = str(patient_data.birthdate) else: try: - julian_birthdate = (patient_data.birthdate / 64) - 14558805 + 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,