Saguenay (Jonquière), Québec, Canada. Tél: (581) 683-9887 Téléc: (581) 221-0874
RetourDicom Worklist
2005-04-01 21:06:46 (ID: 71, Parent: 0, Type: post)#!/usr/bin/python2.3 # # Script to download a worklist file # and fetch each enumerated file # # author: Jean-Luc Cyr # created on : 2005-06-16 # for: Les systemes medicaux IMAGEM inc # from urllib import urlopen, urlretrieve from os import makedirs, stat #Variables globales method = "http://" listserver = "192.168.2.21" path = "/worklist/" inst = "CHUL" fileserver = "ftp://robin:blitzkrieg@192.168.2.70/" rootdir = "/home/jlcyr/dl/" #Fonction pour downloader la liste de travail a partir du web def fetchlistweb(): print 'Retrieving worklist' url = method + listserver + path + "worklist.php?INST_ID=" + inst #print url try: page = urlopen(url).read() except IOError: print "Can't connect to server" page = "Can't connect to server" return page; #Fonction pour downloader la liste de travail a partir de la db def fetchlistdb(): import cx_Oracle list = "<PRE>#Liste de travail pour: CHUL\n" destination='CHUL' conn2 = cx_Oracle.connect('ris_pacs','password','rpdev') cur2 = conn2.cursor() select = "SELECT /*+ INDEX(c IDX_COI_STUDY_UID) */ DISTINCT a.AR_START_DOWNLOAD, c.COI_PAT_ID, c.COI_DATE, m.MFS_MOUNT_POINT,a.AR_STU_INSTANCE_UID, c.COI_SERIES_INSTANCE_UID, c.COI_SOP_INSTANCE_UID || '.dcm', s.STU_DESC FROM AUTO_ROUTING a, COMPOSITE_OBJECT_INSTANCE c, MEDIA_FILE_SET m, STUDY s WHERE COI_STUDY_INSTANCE_UID = AR_STU_INSTANCE_UID AND COI_STO_MEDIA_FSET_UID = MFS_UID AND AR_STATUS = 'CREATED' AND AR_DESTINATION = '%s' AND COI_TYPE = 'IMAGE' AND AR_START_DOWNLOAD <= SYSDATE AND COI_STUDY_INSTANCE_UID = STU_INSTANCE_UID UNION SELECT /*+ INDEX(c1 IDX_COI_STUDY_UID) */ DISTINCT a.AR_START_DOWNLOAD, c2.COI_PAT_ID, c2.COI_DATE, m.MFS_MOUNT_POINT, c2.COI_STUDY_INSTANCE_UID, c2.COI_SERIES_INSTANCE_UID, c2.COI_SOP_INSTANCE_UID || '.dcm', s2.STU_DESC FROM AUTO_ROUTING a, COMPOSITE_OBJECT_INSTANCE c1, STUDY s1, HISTORICAL_IMAGES h, STUDY s2, COMPOSITE_OBJECT_INSTANCE c2, MEDIA_FILE_SET m WHERE a.AR_STATUS = 'CREATED' AND a.AR_DESTINATION = '%s' AND a.AR_START_DOWNLOAD <= SYSDATE AND c1.COI_STUDY_INSTANCE_UID = a.AR_STU_INSTANCE_UID AND c1.COI_TYPE = 'IMAGE' AND a.AR_STU_INSTANCE_UID = s1.STU_INSTANCE_UID AND s1.STU_OTHER_NUMBER = h.HI_REF_EXAMCODE AND h.HI_EXAMCODE = s2.STU_OTHER_NUMBER AND s1.STU_PAT_ID = s2.STU_PAT_ID AND s1.STU_INSTANCE_UID != s2.STU_INSTANCE_UID AND s2.STU_INSTANCE_UID = c2.COI_STUDY_INSTANCE_UID AND c2.COI_TYPE = 'IMAGE' AND c2.COI_STO_MEDIA_FSET_UID = m.MFS_UID ORDER BY 1 asc, 2, 3 desc" % (destination, destination) items = 8 cur2.execute(select) res2 = cur2.fetchall() result={} study = "" for item in range(1,cur2.rowcount): for cnt in range(0,items): result[cur2.description[cnt][0]] = res2[item][cnt] if (study!=result['AR_STU_INSTANCE_UID']): if (study!=""): list += "End of Study: " list += study list += "\n" study=result['AR_STU_INSTANCE_UID'] list += "Start of Study: " list += study list += "\n" list += "%s/%s/%s/%s\n" % (result['MFS_MOUNT_POINT'],result['AR_STU_INSTANCE_UID'],result['COI_SERIES_INSTANCE_UID'],result["C.COI_SOP_INSTANCE_UID||'.DCM'"]) if (study!=""): list += "End of Study: " list += study list += "\n" list += "</PRE>" return list #Fonction mettre des entrees dans la liste de travail def makedb(): print "Generation d'une liste de travail" import cx_Oracle conn2 = cx_Oracle.connect('ris_pacs','password','rpdev') cur2 = conn2.cursor() select = "update AUTO_ROUTING set AR_STATUS='CREATED'" cur2.execute(select) select = "commit" cur2.execute(select) #Fonction pour updater la liste de travail quand une etude est downloade def updatelist(study): print "Updating worklist for study %s " % ( study ) url = method + listserver + path + "update_worklist.php?STU_INSTANCE_UID=" + study #print url try: page = urlopen(url).read() except IOError: print "Can't connect to server" page = "Can't connect to server" print "response:%s" % ( page ) #Fonction pour downloader une image, verifier les directory etc def download(full,stu,ser,file): url = fileserver+full try: stat(rootdir+stu+"/"+ser) except OSError: print "Local directory doesn't exist, creating it (%s)" % (rootdir+stu+"/"+ser) makedirs(rootdir+stu+"/"+ser) print "Retrieving object %s" % (file) fileName= "%s%s/%s/%s" % ( rootdir, stu, ser, file ) try: urlretrieve(url,fileName); except IOError: print "Can't connect to server" print 'Done' #Fonction pour executer une liste de travail (downloader les images et updater a chaque etude) def parse(page): print 'Parsing worklist' lines = page.split("\n") for line in lines: #print line compo = line.split('/') if line[0]=='/': download(line,compo[3],compo[4],compo[5]) else: if (line[0:3]=="End"): compo = line.split(': ') print line updatelist(compo[1]) if (line[0:5]=="Start"): print line #Programme principal makedb() print 'Starting download' #parse(fetchlistweb()) parse(fetchlistdb()) print 'All work done'
Document Informatif
ADN Informatique
2015
Rev. 1
Jean-Luc Cyr