Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix code failure when dicom time fields are empty #755

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 acq_date and acq_time:
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 acq_dt:
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 series_date and series_time:
return strptime_micr(series_date + series_time, "%Y%m%d%H%M%S[.%f]")
return None

Expand Down