]> Creatis software - gdcm.git/blob - gdcmPython/demo/PrintDicomDir.py.in
Use new style for DicomDir constructor
[gdcm.git] / gdcmPython / demo / PrintDicomDir.py.in
1 import sys
2 import os.path
3 from gdcmConfigDemo import *
4 from gdcmPython.core import *
5
6 def PrintUse():
7    print ""
8    print "Use :"
9    print "-----"
10    print "%s <dicomDir>" % sys.argv[0]
11    print "   dicomDir : path to the DICOMDIR to parse"
12    print ""
13    print ""
14
15 ### Get filename from command line or default it
16 try:
17    fileName = sys.argv[1]
18 except IndexError:
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")
22
23 try:
24    printLevel = int(sys.argv[2])
25 except IndexError:
26    printLevel = 1
27
28 ### Build the DicomDir element list
29 dicomdir = gdcm.DicomDir()
30 dicomdir.SetFileName(fileName)
31 dicomdir.Load()
32 if not dicomdir.IsReadable():
33    PrintUse()
34    raise RuntimeError,"The '%s' DicomDir is not readable with gdcm." % fileName
35
36 print "DICOMDIR -->",fileName
37 print "##############################################################"
38 print "## Display all the elements and their respective values"
39 print "## found in the ", fileName, " file."
40 print "##############################################################"
41 dicomdir.SetPrintLevel(-1)
42 dicomdir.Print()
43
44 print ""
45 patient=dicomdir.GetFirstPatient()
46 while(patient):
47    print "Patient"
48    study=patient.GetFirstStudy()
49    while(study):
50       print "   Study"
51       serie=study.GetFirstSerie()
52       while(serie):
53          print "      Serie"
54          image=serie.GetFirstImage()
55          while(image):
56             print "         Image"
57             print "         ---",image.GetValEntry(0x0004,0x1500).GetValue()
58             image=serie.GetNextImage()
59          serie=study.GetNextSerie()
60       study=patient.GetNextStudy()
61    patient=dicomdir.GetNextPatient()
62