def release_assoc(self): '''release assoc will release any associations that are open, in preparation for a new one. ''' if self.assoc is not None: if self.assoc.is_established: bot.debug("Found established association, releasing.") self.assoc.release()
def update_peer(self, address=None, port=None, name=None): '''update_peer will update the address, port, and name of the peer AE''' if name is not None: self.to_name = name if port is not None: self.to_port = port if address is None and self.to_address is None: bot.error("You must supply a peer address to make an association.") sys.exit(1) self.to_address = address bot.debug("Peer[%s] %s:%s" % (self.to_name, self.to_address, self.to_port))
def send_echo(self,to_address=None,to_port=None,to_name=None): '''send an echo repeat times, and close the association when finished''' # Make the association self.make_assoc(address=to_address, name=to_name, port=to_port) # If we successfully Associated then send N DIMSE C-ECHOs if self.assoc.is_established: for ii in range(self.repeat): status = self.assoc.send_c_echo() if status is not None: # Abort or release association bot.debug("%s received status %s" %(self.ae.ae_title, status)) if self.abort: bot.debug("%s aborting association." %self.self.ae.ae_title) self.assoc.abort() else: bot.debug("%s releasing association." %self.ae.ae_title) self.assoc.release()
def validate_dicoms(dcm_files): '''validate dicoms will test opening one or more dicom files, and return a list of valid files. :param dcm_files: one or more dicom files to test''' if not isinstance(dcm_files, list): dcm_files = [dcm_files] valids = [] bot.debug("Checking %s dicom files for validation." % (len(dcm_files))) for dcm_file in dcm_files: try: with open(dcm_file, 'rb') as filey: dataset = read_file(filey, force=True) valids.append(dcm_file) except IOError: bot.error('Cannot read input file {0!s}'.format(dcm_file)) sys.exit(1) bot.info("Found %s valid dicom files" % (len(valids))) return valids
def on_c_find(self, dataset): '''on_c_find for a provider expects the user to send a dataset as a query ''' bot.debug("Responding to request for find") # Should we update the dicom base for each find request (default False) if self.update_on_find is True: bot.debug("[%s] updating dicom list to search" % (self.ae.ae_title)) self.dicoms = get_dicom_files(self.base) # Variables that the user has specified in the query dataset fields = self.get_dataset_query(dataset) bot.debug("Requested fields include %s" % (",".join(fields))) for dcm in self.dicoms: # Here we assume that the user wants to return # datasets that match all of the query ds = read_file(dcm, force=True) is_match = self.match_dataset(query=dataset, contender=ds, fields=fields) # I'm not sure if we only want to sent back a subset of information? ds.RetrieveAETitle = self.ae.ae_title if is_match: bot.debug("Found matching dataset %s" % dcm) yield 0xff00, ds else: yield self.status, None if self.cancel: yield self.matching_terminated_cancel, None return yield self.status, None