Skip to content

Commit

Permalink
Handle missing PatientBirthDate
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Sep 28, 2023
1 parent b9669de commit a35f935
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions adit/core/utils/dicom_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import logging
from datetime import date, time
from typing import Any, Iterable, Literal

Expand All @@ -14,6 +15,8 @@
convert_to_python_time,
)

logger = logging.getLogger(__name__)


class BaseDataset:
def __init__(self, ds: Dataset) -> None:
Expand All @@ -28,9 +31,15 @@ def PatientName(self) -> str:
return str(self._ds.PatientName)

@property
def PatientBirthDate(self) -> date:
birth_date = self._ds.PatientBirthDate
return convert_to_python_date(birth_date)
def PatientBirthDate(self) -> date | None:
try:
birth_date = self._ds.PatientBirthDate
return convert_to_python_date(birth_date)
except Exception:
# Birth date can be absent on some external images even if it
# is mandatory by the DICOM standard
logger.exception(f"Invalid patient birth date in dataset:\n{self._ds}")
return None

@property
def PatientSex(self) -> Literal["M", "F", "O"]:
Expand Down

0 comments on commit a35f935

Please sign in to comment.