]> Creatis software - gdcm.git/blob - Example/PrintDicomDir.cxx
5e589900e755b4e46a25e1e34cc2c555cb85ac34
[gdcm.git] / Example / PrintDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/18 07:55:16 $
7   Version:   $Revision: 1.16 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDocument.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmValEntry.h"
21 #include "gdcmDicomDirPatient.h"
22 #include "gdcmDicomDirStudy.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
25 #include "gdcmTS.h"
26 #include "gdcmDebug.h"
27
28 #include <fstream>
29 #include <iostream>
30
31 int main(int argc, char* argv[])
32 {  
33    gdcm::DicomDir *e1;
34    gdcm::TSKey v;
35
36    gdcm::DicomDirPatient *pa;
37    gdcm::DicomDirStudy *st;
38    gdcm::DicomDirSerie *se;
39    gdcm::DicomDirImage *im;
40   
41    std::string fileName; 
42    if (argc > 1) 
43       fileName = argv[1];    
44    else 
45    {
46       fileName = GDCM_DATA_ROOT;
47       fileName += "/DICOMDIR";
48    }
49
50    if (argc > 3)
51       gdcm::Debug::SetDebugOn();
52
53    e1 = new gdcm::DicomDir( fileName );
54
55    e1->SetPrintLevel(2);
56    int detailLevel;
57    if (argc > 2)
58       detailLevel = atoi(argv[2]);   
59    else
60       detailLevel = 3;
61
62    // Test if the DicomDir is readable
63    if( !e1->IsReadable() )
64    {
65       std::cout<<"          DicomDir '"<<fileName
66                <<"' is not readable"<<std::endl
67                <<"          ...Failed"<<std::endl;
68
69       delete e1;
70       return 1;
71    }
72
73    // Test if the DicomDir contains any Patient
74    pa = e1->GetFirstEntry();
75    if ( pa  == 0)
76    {
77       std::cout<<"          DicomDir '"<<fileName
78                <<" has no patient"<<std::endl
79                <<"          ...Failed"<<std::endl;
80
81       delete e1;
82       return 1;
83    }
84
85 // Structure use Examples 
86
87    switch (detailLevel)
88   { 
89   case 1:
90      std::cout << std::endl << std::endl  
91        << " =  PATIENT List ==========================================" 
92        << std::endl<< std::endl;
93
94       pa = e1->GetFirstEntry();
95       while (pa) 
96       {
97          std::cout << pa->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name   
98          pa = e1->GetNextEntry();    
99       }
100       break;
101
102    case 2:    
103       std::cout << std::endl << std::endl  
104         << " = PATIENT/STUDY List =======================================" 
105         << std::endl<< std::endl;
106
107       pa = e1->GetFirstEntry();
108       while ( pa ) // on degouline les PATIENT de ce DICOMDIR
109       {  
110          std::cout << pa->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name 
111          st = pa->GetFirstEntry();
112          while ( st ) { // on degouline les STUDY de ce patient
113             std::cout << "--- "<< st->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
114             st = pa->GetNextEntry();
115          }
116          pa = e1->GetNextEntry();    
117       }   
118       break;
119
120    case 3: 
121       std::cout << std::endl << std::endl  
122         << " =  PATIENT/STUDY/SERIE List ==================================" 
123         << std::endl<< std::endl;
124
125       pa = e1->GetFirstEntry(); 
126       while ( pa )   // on degouline les PATIENT de ce DICOMDIR
127       {
128        // Patient's Name, Patient ID 
129          std::cout << "Pat.Name:[" << pa->GetEntry(0x0010, 0x0010) <<"]"; // Patient's Name
130          std::cout << " Pat.ID:[";
131          std::cout << pa->GetEntry(0x0010, 0x0020) << "]" << std::endl; // Patient ID
132          st = pa->GetFirstEntry();
133          while ( st ) { // on degouline les STUDY de ce patient
134             std::cout << "--- Stud.descr:["    << st->GetEntry(0x0008, 0x1030) << "]";// Study Description 
135             std::cout << " Stud.ID:["          << st->GetEntry(0x0020, 0x0010);       // Study ID
136             std::cout << "]" << std::endl;
137             se = st->GetFirstEntry();
138             while ( se ) { // on degouline les SERIES de cette study
139                std::cout << "--- --- Ser.Descr:["<< se->GetEntry(0x0008, 0x103e)<< "]";  // Series Description
140                std::cout << " Ser.nb:["         <<  se->GetEntry(0x0020, 0x0011);        // Series number
141                std::cout << "] Mod.:["          <<  se->GetEntry(0x0008, 0x0060) << "]"; // Modality
142                std::cout << std::endl;    
143                se = st->GetNextEntry();   
144             }
145             st = pa->GetNextEntry();
146          }
147          pa = e1->GetNextEntry();    
148       } 
149       break;
150
151    case 4:  
152       std::cout << std::endl << std::endl  
153            << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
154            << std::endl<< std::endl;
155  
156       pa = e1->GetFirstEntry(); 
157       while ( pa ) {  // les PATIENT de ce DICOMDIR
158          std::cout << pa->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
159          st = pa->GetFirstEntry();
160          while ( st ) { // on degouline les STUDY de ce patient
161             std::cout << "--- "<< st->GetEntry(0x0008, 0x1030) << std::endl;    // Study Description
162             std::cout << " Stud.ID:["          << st->GetEntry(0x0020, 0x0010); // Study ID
163             se = st->GetFirstEntry();
164             while ( se ) { // on degouline les SERIES de cette study
165                std::cout << "--- --- "<< se->GetEntry(0x0008, 0x103e) << std::endl;      // Serie Description
166                std::cout << " Ser.nb:["         <<  se->GetEntry(0x0020, 0x0011);        // Series number
167                std::cout << "] Mod.:["          <<  se->GetEntry(0x0008, 0x0060) << "]"; // Modality
168                im = se->GetFirstEntry();
169                while ( im ) { // on degouline les Images de cette serie
170                   std::cout << "--- --- --- "<< im->GetEntry(0x0004, 0x1500) << std::endl; // File name
171                   im = se->GetNextEntry();   
172                }
173                se = st->GetNextEntry();   
174            }
175             st = pa->GetNextEntry();
176         }     
177         pa = e1->GetNextEntry();    
178       }
179       break;
180
181    case 5:
182       std::cout << std::endl << std::endl  
183            << " = DICOMDIR full content ==========================================" 
184            << std::endl<< std::endl;
185       e1->Print();
186       break;
187
188    }  // end switch
189
190
191  /*
192    // Previous code.
193    // Kept as an example. Please don't remove
194  
195    gdcm::ListDicomDirPatient::const_iterator  itPatient;
196    gdcm::ListDicomDirStudy::const_iterator    itStudy;
197    gdcm::ListDicomDirSerie::const_iterator    itSerie;
198    gdcm::ListDicomDirImage::const_iterator    itImage;
199    cout << std::endl << std::endl
200         << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
201         << std::endl<< std::endl;
202  
203    itPatient = e1->GetDicomDirPatients().begin();
204    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline les PATIENT de ce DICOMDIR
205       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
206       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
207       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
208          std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
209          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
210          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
211             std::cout << "--- --- "<< (*itSerie)->GetEntry(0x0008, 0x103e) << std::endl; // Serie Description
212             itImage = ((*itSerie)->GetDicomDirImages()).begin();
213             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
214                std::cout << "--- --- --- "<< (*itImage)->GetEntry(0x0004, 0x1500) << std::endl; // File name
215                ++itImage;   
216             }
217             ++itSerie;   
218          }
219          ++itStudy;
220       }  
221       itPatient ++;    
222    }   
223  */  
224
225
226    if(e1->IsReadable())
227       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
228    else
229       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
230    std::cout<<std::flush;
231    delete e1;
232
233    return(0);
234 }