def send_c_find(self, query): """Perform a CFIND with the given query Raises ------ DICOMTrolleyError When finding fails """ if self.debug: debug_logger() ae = AE(ae_title=bytes(self.aet, encoding="utf-8")) ae.add_requested_context(PatientRootQueryRetrieveInformationModelFind) assoc = ae.associate(self.host, self.port, ae_title=bytes(self.aec, encoding="utf-8")) responses = [] if assoc.is_established: # Send the C-FIND request c_find_response = assoc.send_c_find( query.as_dataset(), PatientRootQueryRetrieveInformationModelFind, ) for (status, identifier) in c_find_response: if status: # I don't understand this status.. For now just collect non-None if identifier: responses.append(identifier) else: raise DICOMTrolleyError( "Connection timed out, was aborted or" " received invalid response") assoc.release() else: raise DICOMTrolleyError( "Association rejected, aborted or never connected") return responses
import glob import config import dicom_helpers from pynetdicom import AE, debug_logger from pynetdicom.sop_class import CTImageStorage, RTStructureSetStorage debug_logger() def export_files(dicom_paths, directory=False): if directory: dicom_paths = glob.glob(dicom_paths + "/*.dcm") dicom_files = dicom_helpers.read_dicom_paths(dicom_paths) print("dicom_files", len(dicom_files)) # Initialise the Application Entity ae = AE() # Add a requested presentation context ae.add_requested_context(CTImageStorage) ae.add_requested_context(RTStructureSetStorage) # Associate with peer AE assoc = ae.associate(config.SCU_IP, config.SCU_PORT, ae_title=config.SCU_AE_TITLE) if assoc.is_established: # Use the C-STORE service to send the dataset # returns the response status as a pydicom Dataset