add: safe_get_attr untuk force None / null ke ' '
This commit is contained in:
18
main.py
18
main.py
@@ -397,6 +397,7 @@ def process_single_study(study_uid, accession_number=None, log_dir=None):
|
|||||||
|
|
||||||
# STEP 1: Retrieve the study
|
# STEP 1: Retrieve the study
|
||||||
retrieve_result = retriever.retrieve_study(study_uid, accession_number=accession_number)
|
retrieve_result = retriever.retrieve_study(study_uid, accession_number=accession_number)
|
||||||
|
|
||||||
if not retrieve_result['success']:
|
if not retrieve_result['success']:
|
||||||
logger.error(f"Failed to retrieve study {study_uid}: {retrieve_result['status']}")
|
logger.error(f"Failed to retrieve study {study_uid}: {retrieve_result['status']}")
|
||||||
return {'success': False, 'error': f"Failed to retrieve study: {retrieve_result['status']}"}
|
return {'success': False, 'error': f"Failed to retrieve study: {retrieve_result['status']}"}
|
||||||
@@ -405,6 +406,7 @@ def process_single_study(study_uid, accession_number=None, log_dir=None):
|
|||||||
|
|
||||||
# STEP 2: Send the study to destination PACS
|
# STEP 2: Send the study to destination PACS
|
||||||
send_result = sender.send_study(os.path.join(settings.DICOM_STORE_DIR, study_uid))
|
send_result = sender.send_study(os.path.join(settings.DICOM_STORE_DIR, study_uid))
|
||||||
|
|
||||||
if not send_result['success']:
|
if not send_result['success']:
|
||||||
logger.error(f"Failed to send study {study_uid}: {send_result.get('error', 'Unknown error')}")
|
logger.error(f"Failed to send study {study_uid}: {send_result.get('error', 'Unknown error')}")
|
||||||
|
|
||||||
@@ -445,12 +447,18 @@ def process_single_study(study_uid, accession_number=None, log_dir=None):
|
|||||||
# Get first instance for the series
|
# Get first instance for the series
|
||||||
instance = finder.find_first_instance_for_series(study_uid, series_uid)
|
instance = finder.find_first_instance_for_series(study_uid, series_uid)
|
||||||
|
|
||||||
|
# Kalau null atau None, forced ke ''
|
||||||
|
def safe_get_attr(obj, attr_name, default=''):
|
||||||
|
"""Get attribute value, ensuring None is converted to default."""
|
||||||
|
value = getattr(obj, attr_name, default)
|
||||||
|
return default if value is None else str(value)
|
||||||
|
|
||||||
series_info = {
|
series_info = {
|
||||||
'Series_IUID': getattr(series, 'SeriesInstanceUID', ''),
|
'Series_IUID': safe_get_attr(series, 'SeriesInstanceUID'),
|
||||||
'SeriesNumber': getattr(series, 'SeriesNumber', ''),
|
'SeriesNumber': safe_get_attr(series, 'SeriesNumber'),
|
||||||
'SeriesDescription': getattr(series, 'SeriesDescription', ''),
|
'SeriesDescription': safe_get_attr(series, 'SeriesDescription'),
|
||||||
'NumberOfInstances': getattr(series, 'NumberOfSeriesRelatedInstances', ''),
|
'NumberOfInstances': safe_get_attr(series, 'NumberOfSeriesRelatedInstances'),
|
||||||
'SOP_IUID': getattr(instance, 'SOPInstanceUID', '') if instance else ''
|
'SOP_IUID': safe_get_attr(instance, 'SOPInstanceUID') if instance else ''
|
||||||
}
|
}
|
||||||
|
|
||||||
study_log['Series'].append(series_info)
|
study_log['Series'].append(series_info)
|
||||||
|
|||||||
Reference in New Issue
Block a user