add: fastapi wrapped baru mau di tes di Gajah Mada

This commit is contained in:
mario
2025-07-11 15:01:27 +07:00
parent 1b8eeee04b
commit 853cc70edb
7 changed files with 729 additions and 0 deletions

View File

@@ -347,4 +347,82 @@ class DicomFinder:
logger.error(error_msg)
raise DicomQueryError(error_msg)
return study
@dicom_retry(exception_types=(DicomQueryError, ConnectionError))
def find_study_by_accession(self, accession_number):
"""
Find a specific study by its AccessionNumber.
Args:
accession_number (str): AccessionNumber to find
Returns:
Dataset: Study dataset or None if not found
"""
logger.info(f"Finding study with AccessionNumber: {accession_number}")
# Create query dataset
ds = Dataset()
ds.QueryRetrieveLevel = 'STUDY'
# Set the AccessionNumber filter
ds.AccessionNumber = accession_number
# Required fields (minimal set)
ds.StudyInstanceUID = ''
ds.StudyDate = ''
# Additional fields we want to retrieve
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} for AccessionNumber: {accession_number}")
break
elif status and status.Status != 0x0000: # Not success
logger.error(f"C-FIND error: {status}")
if study:
logger.info(f"Found study with AccessionNumber {accession_number}, StudyUID: {study.StudyInstanceUID}")
else:
logger.warning(f"No study found with AccessionNumber {accession_number}")
except Exception as e:
logger.error(f"Error during C-FIND by AccessionNumber: {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