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"
19 print "Progress",dicomdir.GetProgress()
23 ### Get filename from command line or default it
25 fileName = sys.argv[1]
27 fileName = os.path.join(GDCM_DATA_ROOT, "DICOMDIR")
28 if( not os.path.isfile(fileName) ):
29 fileName=os.path.join(os.path.split(sys.argv[0])[0],"DICOMDIR")
32 printLevel = int(sys.argv[2])
36 ### Build the DicomDir element list
37 dicomdir = gdcm.DicomDir.New()
39 dicomdir.SetStartMethod(startMethod)
40 dicomdir.SetProgressMethod(progressMethod)
41 dicomdir.SetEndMethod(endMethod)
43 dicomdir.SetFileName(fileName)
45 if not dicomdir.IsReadable():
47 raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
49 print "DICOMDIR -->",fileName
50 print "##############################################################"
51 print "## Display all the elements and their respective values"
52 print "## found in the ", fileName, " file."
53 print "##############################################################"
54 dicomdir.SetPrintLevel(-1)
58 patient=dicomdir.GetFirstPatient()
61 study=patient.GetFirstStudy()
64 serie=study.GetFirstSerie()
67 image=serie.GetFirstImage()
70 print " ---",image.GetDataEntry(0x0004,0x1500).GetString()
71 image=serie.GetNextImage()
72 serie=study.GetNextSerie()
73 study=patient.GetNextStudy()
74 patient=dicomdir.GetNextPatient()
76 dicomdir.SetDirectoryName(os.path.dirname(fileName))
78 if not dicomdir.IsReadable():
80 raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
82 print "DICOMDIR -->",fileName
83 print "##############################################################"
84 print "## Display all the elements and their respective values"
85 print "## found in the ", fileName, " file."
86 print "##############################################################"
87 dicomdir.SetPrintLevel(-1)