in pathology/transformation_pipeline/ingestion_lib/dicom_gen/wsi_to_dicom/dicom_util.py [0:0]
def _init_acquision_date_time_if_undefined(dcm_file: pydicom.Dataset) -> None:
"""Inits acquision date time if undefined (Required for WSI DICOM).
If tag is undefined attempts to build tag value from date/time components.
date = AcquisitionDate, ContentDate, and then current date.
time = AcquisitionTime, ContentTime, and then current time.
if date metadata does not fully describe metadata in 8 chars (YYYYMMDD)
then uses current date.
Args:
dcm_file: Pydicom dataset.
Returns:
None:
"""
if ingest_const.DICOMTagKeywords.ACQUISITION_DATE_TIME in dcm_file:
return
datetime_now = _get_datetime_now()
acquision_date = ''
acquision_time = '000000'
try:
if len(dcm_file.AcquisitionDate) >= 4:
acquision_date = dcm_file.AcquisitionDate
acquision_time = dcm_file.AcquisitionTime
except AttributeError:
pass
if not acquision_date:
try:
if len(dcm_file.ContentDate) >= 4:
acquision_date = dcm_file.ContentDate
acquision_time = dcm_file.ContentTime
except AttributeError:
pass
if not acquision_date:
acquision_date = _dicom_formatted_date(datetime_now)
acquision_time = _dicom_formatted_time(datetime_now)
cloud_logging_client.info(
'Metadata missing required acquision datetime metadata setting datetime'
' current date/time.'
)
if ingest_const.DICOMTagKeywords.ACQUISITION_DATE not in dcm_file:
dcm_file.AcquisitionDate = acquision_date
if ingest_const.DICOMTagKeywords.ACQUISITION_TIME not in dcm_file:
dcm_file.AcquisitionTime = acquision_time
acquision_date = _pad_date(acquision_date)
acquision_time = _pad_time(acquision_time)
dcm_file.AcquisitionDateTime = f'{acquision_date}{acquision_time}'