def check_send_dicom(self): ts = [ ExplicitVRLittleEndian, ImplicitVRLittleEndian, ExplicitVRBigEndian ] # create application entity with Find and Move SOP classes as SCU and # Storage SOP class as SCP MyAE = AE("DCMTK", 9999, [ PatientRootFindSOPClass, PatientRootMoveSOPClass, VerificationSOPClass ], [StorageSOPClass], ts) MyAE.OnAssociateResponse = OnAssociateResponse MyAE.OnAssociateRequest = OnAssociateRequest MyAE.OnReceiveStore = OnReceiveStore MyAE.start() # remote application entity PrismaAE = dict(Address="134.157.205.1", Port=104, AET="AN_MRC35181") # create association with remote AE self.log.info("Request association on PRISMA") assoc = MyAE.RequestAssociation(PrismaAE) # perform a DICOM ECHO st = assoc.VerificationSOPClass.SCU(1) self.log.info('DICOM Echo done with status "%s"', st) try: self.check_send_dicom_from_remoteAE(assoc) except Exception as e: self.log.warning('CODE ERROR because of %s', e) assoc.Release(0) # AGAIN with VERIO VerioAE = dict(Address="134.157.205.51", Port=104, AET="MRC40527") # create association with remote AE self.log.info("Request association on VERIO") assoc = MyAE.RequestAssociation(VerioAE) # perform a DICOM ECHO st = assoc.VerificationSOPClass.SCU(1) self.log.info('DICOM Echo done with status "%s"', st) #try : self.check_send_dicom_from_remoteAE(assoc) #except Exception as e: # self.log.warning('CODE ERROR because of %s',e) assoc.Release(0) MyAE.Quit()
def check_send_dicom(self): ts = [ ExplicitVRLittleEndian, ImplicitVRLittleEndian, ExplicitVRBigEndian ] # create application entity with Find and Move SOP classes as SCU and # Storage SOP class as SCP MyAE = AE("DCMTK",9999, [PatientRootFindSOPClass, PatientRootMoveSOPClass, VerificationSOPClass], [StorageSOPClass], ts) MyAE.OnAssociateResponse = OnAssociateResponse MyAE.OnAssociateRequest = OnAssociateRequest MyAE.OnReceiveStore = OnReceiveStore MyAE.start() # remote application entity PrismaAE = dict(Address="134.157.205.1", Port=104, AET="AN_MRC35181") # create association with remote AE self.log.info("Request association on PRISMA") assoc = MyAE.RequestAssociation(PrismaAE) # perform a DICOM ECHO st = assoc.VerificationSOPClass.SCU(1) self.log.info('DICOM Echo done with status "%s"', st) try : self.check_send_dicom_from_remoteAE(assoc) except Exception as e: self.log.warning('CODE ERROR because of %s',e) assoc.Release(0) # AGAIN with VERIO VerioAE = dict(Address="134.157.205.51", Port=104, AET="MRC40527") # create association with remote AE self.log.info("Request association on VERIO") assoc = MyAE.RequestAssociation(VerioAE) # perform a DICOM ECHO st = assoc.VerificationSOPClass.SCU(1) self.log.info('DICOM Echo done with status "%s"', st) #try : self.check_send_dicom_from_remoteAE(assoc) #except Exception as e: # self.log.warning('CODE ERROR because of %s',e) assoc.Release(0) MyAE.Quit()
def OnAssociateResponse(association): print "Association response received" print association def OnReceiveStore(SOPclass, DS): assoc = MyAE.RequestAssociation(REMOTEAE) if assoc: assoc.CRImageStorageSOPClass.StoreSCU(DS, 1) assoc.Release(0) return 0 else: return 1 def OnReceiveEcho(self): print "Echo received" if __name__ == '__main__': start_dcmqrscp() MyAE = AE('NETDICOM', 7654, [CRImageStorageSOPClass], [CRImageStorageSOPClass, VerificationSOPClass]) MyAE.OnAssociateRequest = OnAssociateRequest MyAE.OnAssociateResponse = OnAssociateResponse MyAE.OnReceiveStore = OnReceiveStore MyAE.OnReceiveEcho = OnReceiveEcho MyAE.start()
def _pynetdicom_img_get_worker(aet, node, port, laet, patid, studyuid, seriesuid, imageuid, savedir, queue, returns): ''' Use pynetdicom to perform a series level c-get fetch. This is to be run in a separate worker thread. The c-store callbacks save the images and push a CStoreResponse object onto a queue for the main thread. The function returns normally, which will lead to the threading terminating. This is detected by the parent thread. ''' global msg_id msg_id += 1 # a slight kludge as python 2.7 doesn't have 'nonlocal' qualifier image_counter = [0] # The callback function for C-STORE sub-operations def on_receive_store(cget_obj, ds): try: # print 'C-STORE callback(cget=%s,instno=%d)' % (cget_obj, ds.InstanceNumber) # This is a bit of a hack but we need to add some file-meta file_meta = Dataset() file_meta.add_new((2, 0x01), 'OB', b'\0\1') # FileMetaInformationVersion file_meta.add_new((2, 0x02), 'UI', ds.SOPClassUID) # MediaStorageSOPClassUID file_meta.add_new((2, 0x03), 'UI', ds.SOPInstanceUID) # MediaStorageSOPInstanceUID file_meta.add_new((2, 0x10), 'UI', ExplicitVRLittleEndian) # TransferSyntaxUID file_meta.add_new((2, 0x12), 'UI', '1.2.40.0.13.1.1') # ImplementationClassUID file_meta.add_new((2, 0x13), 'SH', 'pynetdicom') # ImplementationVersionName ds.file_meta = file_meta # and specify the encoding ds.is_implicit_VR = False ds.is_little_endian = True save_path = os.path.join(savedir, '%05d.dcm' % (image_counter[0] + 1)) # the WriteLikeOriginal=False flag is need to get preamble etc right ds.save_as(filename=save_path, WriteLikeOriginal=False) image_counter[0] += 1 pcid = image_counter[0] # for the sake of argument # actually what we want here is the message object so we can extract the no of operations, status etc status = 0 queue.put(CStoreResponse(pcid, status)) except Exception as e: # print 'Error saving: C-STORE callback(cget=%s, instno=%d), saving to %s [%s]' % (cget_obj, ds.InstanceNumber, save_path, e) print('Error Saving: %s' % e) return 1 # ?? RHD # zero corresponds to DICOM Success return 0 # Create application entity and association with remote AE (port number of 0 to stop it putting up a listen) ae = AE(laet, port=0, SOPSCU=[PatientRootGetSOPClass], SOPSCP=[ RTPlanStorageSOPClass, CTImageStorageSOPClass, MRImageStorageSOPClass, RTImageStorageSOPClass ]) ae.OnReceiveStore = on_receive_store ae.start() assoc = ae.RequestAssociation({'Address': node, 'Port': port, 'AET': aet}) # Query object d = Dataset() d.PatientID = str(patid) d.StudyInstanceUID = str(studyuid) d.SeriesInstanceUID = str(seriesuid) d.SOPInstanceUID = str(imageuid) d.QueryRetrieveLevel = 'IMAGE' st_ds = assoc.PatientRootGetSOPClass.SCU(d, msg_id) if st_ds is not None: for status, ds in st_ds: pass # print 'status = %s, dataset = %s' % (status, ds) # print 'Done' returns.append(status) return