Skip to content

Commit 0821456

Browse files
committed
try to fix code failure when dicom time fields are empty
This scenario happens when anonymization empties the field (not removed).
1 parent 7caff37 commit 0821456

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

heudiconv/dicoms.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,18 +526,18 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti
526526
3. SeriesDate & SeriesTime (0008,0021); (0008,0031)
527527
528528
"""
529-
acq_date = dcm_data.get("AcquisitionDate")
530-
acq_time = dcm_data.get("AcquisitionTime")
531-
if not (acq_date is None or acq_time is None):
529+
acq_date = dcm_data.get("AcquisitionDate", "").strip()
530+
acq_time = dcm_data.get("AcquisitionTime", "").strip()
531+
if len(acq_date) > 0 and len(acq_time) > 0:
532532
return strptime_micr(acq_date + acq_time, "%Y%m%d%H%M%S[.%f]")
533533

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

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

0 commit comments

Comments
 (0)