3 from gdcmConfigDemo import *
4 from gdcmPython.core import *
10 print "%s <dicomDir>" % sys.argv[0]
11 print " dicomDir : path to the DICOMDIR to parse"
15 ### Get filename from command line or default it
17 fileName = sys.argv[1]
19 fileName = os.path.join(GDCM_DATA_ROOT, "DICOMDIR")
20 if( not os.path.isfile(fileName) ):
21 fileName=os.path.join(os.path.split(sys.argv[0])[0],"DICOMDIR")
24 printLevel = int(sys.argv[2])
28 ### Build the DicomDir element list
29 dicomdir = gdcm.DicomDir.New()
31 dicomdir.SetFileName(fileName)
33 if not dicomdir.IsReadable():
35 raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
37 print "DICOMDIR -->",fileName
38 print "##############################################################"
39 print "## Display all the elements and their respective values"
40 print "## found in the ", fileName, " file."
41 print "##############################################################"
42 dicomdir.SetPrintLevel(-1)
46 patient=dicomdir.GetFirstPatient()
49 study=patient.GetFirstStudy()
52 serie=study.GetFirstSerie()
55 image=serie.GetFirstImage()
58 print " ---",image.GetDataEntry(0x0004,0x1500).GetString()
59 image=serie.GetNextImage()
60 serie=study.GetNextSerie()
61 study=patient.GetNextStudy()
62 patient=dicomdir.GetNextPatient()
64 dicomdir.SetDirectoryName(os.path.dirname(fileName))
66 if not dicomdir.IsReadable():
68 raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
70 print "DICOMDIR -->",fileName
71 print "##############################################################"
72 print "## Display all the elements and their respective values"
73 print "## found in the ", fileName, " file."
74 print "##############################################################"
75 dicomdir.SetPrintLevel(-1)