Saguenay (Jonquière), Québec, Canada. Tél: (581) 683-9887 Téléc: (581) 221-0874
RetourDICOM images downloader and cd burner
2005-04-08 21:04:48 (ID: 70, Parent: 0, Type: post)
#!/usr/bin/python2.2 # Title: CDs.py # Descr: Retrieve images from IMAGEM PACS (Oracle/FTP) # build up a dicomdir file # Author: Jean-Luc Cyr # License: (C)2005 Jean-Luc Cyr / Les systèmes médicaux IMAGEM # Created: 2005-04-08 # # Require: DCMTK utilities (dcmdjpeg, dcmconv, dcmgpdir) # Oracle connection settings db_user = "ris_pacs" db_pass = "password" db_host = "rpdev" # FTP retrieve connection settings ftp_user = "robin" ftp_pass = "blitzkrieg" ftp_host = "192.168.2.70" # Imports and defs ftp = "ftp://%s:%s@%s" % (ftp_user, ftp_pass, ftp_host) import cx_Oracle as db from urllib import urlretrieve import commands from os import stat #program start HERE #Ask for a patient id to fetch study list for patid = raw_input("Enter Pat ID:") #Connect to db con = db.connect(db_user, db_pass, db_host) cur = con.cursor() #Fetch study list for this patient cur.execute("select STU_DATE, STU_DESC, STU_INSTANCE_UID from study where stu_pat_id='%s' order by stu_date desc" % patid) study = cur.fetchall() for row in range(0,study.__len__()): (date,desc,stuuid) = study[row] print "%s - %s - %s" % (row+1,date,desc) #Ask for studies to burn (index from returned list) studylist = raw_input("Enter Study (comma separated):") stunolist = studylist.split(",") stulist="" for stuno in stunolist: #stulist.insert(1,study[int(stuno)][2]) if stulist.__len__()>0: stulist = "%s,'%s'" % (stulist,study[int(stuno)-1][2]) else: stulist = "'%s'" % study[int(stuno)-1][2]; #Fetch image list (for all studies) select = "select MFS_MOUNT_POINT,COI_STUDY_INSTANCE_UID,COI_SERIES_INSTANCE_UID,COI_SOP_INSTANCE_UID from composite_object_instance,media_file_set where coi_study_instance_uid in (%s) and coi_sto_media_fset_uid = mfs_uid" % (stulist) cur.execute(select) coi = cur.fetchall() #clean up last dicomdir and files op = commands.getoutput("rm *dcm") op = commands.getoutput("rm DICOMDIR") op = commands.getoutput("rm image.iso") #Fetch images, convert them to the good uncompressed format #and build up the DICOMDIR file imlist=[] for row in range(0, coi.__len__()): print "=== %s de %s ===" % (int(row)+1,coi.__len__()) (mfsuid,stuuid,seruid,coiuid) = coi[row] url = "%s/%s/%s/%s/%s.dcm" % (ftp,mfsuid,stuuid,seruid,coiuid) fileName = "%sdcm" % (row) imlist.insert(1,"%s.dcm" % (coiuid)) print "*Retrieving %s" % coiuid try: urlretrieve(url,fileName); except IOError: print "Can't retrieve file" else: path = "/home/jlcyr/old_home/Devel/CDs"; print '*Uncompressing' op = commands.getoutput("dcmdjpeg +te %s %s" % (fileName,fileName)) if op!="": print op print '*Converting to LittleEndianExplicit' op = commands.getoutput("dcmconv +te %s %s" % (fileName,fileName)) if op!="": print op try: stat("DICOMDIR") except OSError:#file doesn't exist print '*Creating DICOMDIR' op = commands.getoutput("dcmgpdir +m +D DICOMDIR %s" % (fileName)) if op!="": print op op = commands.getoutput("rm %s" % (fileName)) else: print '*Adding to DICOMDIR' op = commands.getoutput("dcmgpdir +A +m +D DICOMDIR %s" % (fileName)) if op!="": print op op = commands.getoutput("rm %s" % (fileName)) #Now burn the CD! print "==== Making ISO image ====" op = commands.getoutput("mkisofs *dcm DICOMDIR >image.iso") print op
Document Informatif
ADN Informatique
2015
Rev. 1
Jean-Luc Cyr