add process per study_iuid

This commit is contained in:
mario
2025-05-30 12:54:51 +07:00
parent dfe0c18be2
commit c945ead72f
2 changed files with 189 additions and 2 deletions

View File

@@ -269,4 +269,82 @@ class DicomFinder:
logger.error(error_msg)
raise DicomQueryError(error_msg)
return first_instance
return first_instance
@dicom_retry(exception_types=(DicomQueryError, ConnectionError))
def find_study_by_uid(self, study_instance_uid):
"""
Find a specific study by its StudyInstanceUID.
Args:
study_instance_uid (str): StudyInstanceUID to find
Returns:
Dataset: Study dataset or None if not found
"""
logger.info(f"Finding study with UID: {study_instance_uid}")
# Create query dataset
ds = Dataset()
ds.QueryRetrieveLevel = 'STUDY'
# Set the StudyInstanceUID filter
ds.StudyInstanceUID = study_instance_uid
# Required fields (minimal set)
ds.StudyDate = ''
# Additional fields we want to retrieve
ds.AccessionNumber = ''
ds.PatientID = '' # MedrecID
ds.StudyDescription = ''
ds.StudyTime = ''
ds.NumberOfStudyRelatedSeries = ''
# Create association
assoc = self.ae.associate(
self.pacs_config['host'],
self.pacs_config['port'],
ae_title=self.pacs_config['aet']
)
study = None
if assoc.is_established:
try:
logger.debug("Association established, sending C-FIND request")
# Send C-FIND request
responses = assoc.send_c_find(
ds,
StudyRootQueryRetrieveInformationModelFind
)
# Process responses - just get the first one
for (status, dataset) in responses:
if status and status.Status == 0xFF00: # Pending
if dataset:
study = dataset
logger.debug(f"Found study: {dataset.StudyInstanceUID}")
break
elif status and status.Status != 0x0000: # Not success
logger.error(f"C-FIND error: {status}")
if study:
logger.info(f"Found study {study_instance_uid}")
else:
logger.warning(f"No study found with UID {study_instance_uid}")
except Exception as e:
logger.error(f"Error during C-FIND: {str(e)}")
raise DicomQueryError(f"C-FIND operation failed: {str(e)}")
finally:
# Release the association
assoc.release()
logger.debug("Association released")
else:
error_msg = f"Association rejected, aborted or never connected to {self.pacs_config['aet']}"
logger.error(error_msg)
raise DicomQueryError(error_msg)
return study