Skip to content

Commit

Permalink
try to fix code failure when dicom time fields are empty
Browse files Browse the repository at this point in the history
This scenario happens when anonymization empties the field (not removed).
  • Loading branch information
jennan committed Mar 5, 2024
1 parent 7caff37 commit 0821456
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions heudiconv/dicoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,18 +526,18 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti
3. SeriesDate & SeriesTime (0008,0021); (0008,0031)
"""
acq_date = dcm_data.get("AcquisitionDate")
acq_time = dcm_data.get("AcquisitionTime")
if not (acq_date is None or acq_time is None):
acq_date = dcm_data.get("AcquisitionDate", "").strip()
acq_time = dcm_data.get("AcquisitionTime", "").strip()
if len(acq_date) > 0 and len(acq_time) > 0:
return strptime_micr(acq_date + acq_time, "%Y%m%d%H%M%S[.%f]")

acq_dt = dcm_data.get("AcquisitionDateTime")
if acq_dt is not None:
acq_dt = dcm_data.get("AcquisitionDateTime", "").strip()
if len(acq_dt) > 0:
return strptime_micr(acq_dt, "%Y%m%d%H%M%S[.%f]")

series_date = dcm_data.get("SeriesDate")
series_time = dcm_data.get("SeriesTime")
if not (series_date is None or series_time is None):
series_date = dcm_data.get("SeriesDate", "").strip()
series_time = dcm_data.get("SeriesTime", "").strip()
if len(series_date) > 0 and len(series_time) > 0:
return strptime_micr(series_date + series_time, "%Y%m%d%H%M%S[.%f]")
return None

Expand Down

0 comments on commit 0821456

Please sign in to comment.