]> Creatis software - gdcm.git/blob - Example/PrintDicomDir.cxx
Fix mistypings
[gdcm.git] / Example / PrintDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/05/23 14:18:04 $
7   Version:   $Revision: 1.36 $
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 "gdcmDicomDirPatient.h"
21 #include "gdcmDicomDirStudy.h"
22 #include "gdcmDicomDirVisit.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
25 #include "gdcmDicomDirPrivate.h"
26 #include "gdcmTS.h"
27 #include "gdcmDebug.h"
28
29 #include "gdcmArgMgr.h"
30
31 #include <fstream>
32 #include <iostream>
33
34 int main(int argc, char* argv[])
35 {
36    START_USAGE(usage)
37    " \n PrintDicomDir :\n                                                  ",
38    " Display the tree-like structure of a DICOMDIR File                    ",
39    " usage: PrintDicomDir filein=fileName [level=n][detail=m][debug]       ",
40    "        detail = 1 : Patients, 2 : Studies, 3 : Series, 4 : Images     ",
41    "                 5 : Full Content                                      ",
42    "        level = 0,1,2 : depending on user (what he wants to see)       ",
43    "        warning  : user wants to run the program in 'warning mode'     ",   
44    "        debug    : developper wants to run the program in 'debug mode' ",
45    FINISH_USAGE
46
47    // Initialize Arguments Manager   
48    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
49   
50    if (argc == 1 || am->ArgMgrDefined("usage") )
51    {
52       am->ArgMgrUsage(usage); // Display 'usage'
53       delete am;
54       return 0;
55    }
56   
57    GDCM_NAME_SPACE::DicomDir *f;
58    GDCM_NAME_SPACE::TSKey v;
59
60    GDCM_NAME_SPACE::DicomDirPatient *pa;
61    GDCM_NAME_SPACE::DicomDirStudy *st;
62    GDCM_NAME_SPACE::DicomDirSerie *se;
63    GDCM_NAME_SPACE::DicomDirVisit *vs;
64    GDCM_NAME_SPACE::DicomDirImage *im;
65    GDCM_NAME_SPACE::DicomDirPrivate *pr;  
66    char *fileName;
67    fileName  = am->ArgMgrWantString("filein",usage); 
68
69    int level  = am->ArgMgrGetInt("level", 2);
70
71    int detailLevel = am->ArgMgrGetInt("detail", 2);
72
73    if (am->ArgMgrDefined("debug"))
74       GDCM_NAME_SPACE::Debug::DebugOn();
75
76    if (am->ArgMgrDefined("warning"))
77       GDCM_NAME_SPACE::Debug::WarningOn();
78       
79    /* if unused Param we give up */
80    if ( am->ArgMgrPrintUnusedLabels() )
81    { 
82       am->ArgMgrUsage(usage);
83       delete am;
84       return 0;
85    } 
86
87    // new gdcm2 style 
88
89    f = GDCM_NAME_SPACE::DicomDir::New();
90    f->SetFileName ( fileName );
91    f->Load( );
92
93    // Test if the DicomDir is readable
94    if( !f->IsReadable() )
95    {
96       std::cout<<"          DicomDir '"<<fileName
97                <<"' is not readable"<<std::endl
98                <<"          ...Failed"<<std::endl;
99
100       f->Delete();
101       return 1;
102    }
103
104    f->SetPrintLevel(level);
105
106    // Test if the DicomDir contains any Patient
107    pa = f->GetFirstPatient();
108    if ( pa == 0)
109    {
110       std::cout<<"          DicomDir '"<<fileName
111                <<" has no patient"<<std::endl
112                <<"          ...Failed"<<std::endl;
113
114       f->Delete();
115       return 1;
116    }
117
118 // Structure use Examples 
119
120    switch (detailLevel)
121    { 
122       case 1:
123          std::cout << std::endl << std::endl  
124          << " =  PATIENT List ==========================================" 
125          << std::endl<< std::endl;
126
127          pa = f->GetFirstPatient();
128          while (pa) 
129          {
130             std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
131             std::cout << " Pat.ID:[";
132             std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
133             pa = f->GetNextPatient();    
134          }
135          break;
136
137       case 2:    
138          std::cout << std::endl << std::endl  
139          << " = PATIENT/STUDY List =======================================" 
140          << std::endl<< std::endl;
141
142          pa = f->GetFirstPatient();
143          while ( pa ) // on degouline les PATIENT de ce DICOMDIR
144          {  
145             std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
146             std::cout << " Pat.ID:[";
147             std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
148             st = pa->GetFirstStudy();
149             while ( st ) 
150             { // on degouline les STUDY de ce patient
151                std::cout << "--- Stud.descr:["    << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description 
152                std::cout << " Stud.ID:["          << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
153                std::cout << " Stud.Inst.UID:["    << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
154                std::cout << std::endl; 
155                st = pa->GetNextStudy();
156             }
157             pa = f->GetNextPatient();    
158          }   
159          break;
160
161       case 3: 
162          std::cout << std::endl << std::endl  
163          << " =  PATIENT/STUDY/SERIE List ==================================" 
164          << std::endl<< std::endl;
165
166          pa = f->GetFirstPatient(); 
167          while ( pa )   // on degouline les PATIENT de ce DICOMDIR
168          {
169             // Patient's Name, Patient ID 
170             std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
171             std::cout << " Pat.ID:[";
172             std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
173
174             st = pa->GetFirstStudy();
175             while ( st ) 
176             { // on degouline les STUDY de ce patient
177                std::cout << "--- Stud.descr:["    << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description 
178                std::cout << " Stud.ID:["          << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
179                std::cout << " Stud.Inst.UID:["    << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID       
180                std::cout << std::endl;
181
182                se = st->GetFirstSerie();
183                while ( se ) 
184                { // on degouline les SERIES de cette study
185                   std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]";  // Series Description
186                   std::cout << " Ser.nb:["          << se->GetEntryString(0x0020, 0x0011);        // Series number
187                   std::cout << "] Mod.:["           << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
188                   std::cout << " Serie Inst.UID.:[" <<  se->GetEntryString(0x0020, 0x000e) << "]";  // Series Instance UID
189                   std::cout << std::endl;    
190                   se = st->GetNextSerie();   
191                }
192
193                vs = st->GetFirstVisit();
194                while ( vs ) 
195                { // on degouline les VISIT de cette study
196                   std::cout << "--- --- VISIT: ";
197                   std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
198                   std::cout << " Inst.Name:["    << vs->GetEntryString(0x0008,0x0080)   << "]"; // Institution Name
199                   std::cout << " Adm.ID:["      << vs->GetEntryString(0x0038, 0x0010)   << "]"; // Admission ID
200                   std::cout << " Adm. date:["   << vs->GetEntryString(0x0038, 0x0020)   << "]"; // Admitting Date
201                   std::cout << std::endl;    
202                   vs = st->GetNextVisit();    
203                }
204
205                st = pa->GetNextStudy();
206             }
207             pa = f->GetNextPatient();    
208          } 
209          break;
210
211       case 4:  
212          std::cout << std::endl << std::endl  
213          << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
214          << std::endl<< std::endl;
215
216          pa = f->GetFirstPatient(); 
217          while ( pa )
218          {  // les PATIENT de ce DICOMDIR
219             // Patient's Name, Patient ID 
220             std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
221             std::cout << " Pat.ID:[";
222             std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
223
224             st = pa->GetFirstStudy();
225             while ( st ) 
226             { // on degouline les STUDY de ce patient
227                std::cout << "--- Stud.descr:["    << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description 
228                std::cout << " Stud.ID:["          << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
229                std::cout << " Stud.Inst.UID:["    << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
230                std::cout << std::endl;
231
232                vs = st->GetFirstVisit();
233                while ( vs ) 
234                { // on degouline les VISIT de cette study
235                   std::cout << "--- --- VISIT: ";
236                   std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
237                   std::cout << " Inst.Name:["     << vs->GetEntryString(0x0008,0x0080)  << "]"; // Institution Name
238                   std::cout << " Adm.ID:["        << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
239                   std::cout << " Adm. date:["     << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
240                   std::cout << std::endl;    
241                   vs = st->GetNextVisit();    
242                }
243
244                se = st->GetFirstSerie();
245                while ( se ) 
246                { // on degouline les SERIES de cette study
247                   std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e) << "]";  // Series Description
248                   std::cout << " Ser.nb:["          <<  se->GetEntryString(0x0020, 0x0011) << "]";  // Series number
249                   std::cout << " Mod.:["            <<  se->GetEntryString(0x0008, 0x0060) << "]";  // Modality
250                   std::cout << " Serie Inst.UID.:[" <<  se->GetEntryString(0x0020, 0x000e) << "]";  // Series Instance UID
251                   std::cout << std::endl;    
252
253                   im = se->GetFirstImage();
254                   while ( im ) 
255                   { // on degouline les Images de cette serie
256                      std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryString(0x0004, 0x1500) 
257                                << "]" << std::endl; // File name (Referenced File ID)
258                      im = se->GetNextImage();   
259                   }
260  
261                   pr = se->GetFirstPrivate();
262                   while ( pr ) 
263                   { // on degouline les 'Privates' de cette serie
264                      std::cout << "--- --- --- "<< " PRIVATE Ref. File ID :[" << pr->GetEntryString(0x0004, 0x1500) 
265                                << "]" << std::endl; // File name (Referenced File ID)
266                      pr = se->GetNextPrivate();   
267                   }
268  
269                   se = st->GetNextSerie();   
270                }
271                st = pa->GetNextStudy();
272             }     
273             pa = f->GetNextPatient();    
274          }
275          break;
276
277       case 5:
278          std::cout << std::endl << std::endl  
279          << " = DICOMDIR full content ==========================================" 
280          << std::endl<< std::endl;
281          f->Print();
282          break;
283
284    }  // end switch
285
286
287  /*
288    // Previous code.
289    // Kept as an example. Please don't remove
290  
291    GDCM_NAME_SPACE::ListDicomDirPatient::const_iterator  itPatient;
292    GDCM_NAME_SPACE::ListDicomDirStudy::const_iterator    itStudy;
293    GDCM_NAME_SPACE::ListDicomDirSerie::const_iterator    itSerie;
294    GDCM_NAME_SPACE::ListDicomDirImage::const_iterator    itImage;
295    cout << std::endl << std::endl
296         << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
297         << std::endl<< std::endl;
298  
299    itPatient = f->GetDicomDirPatients().begin();
300    while ( itPatient != f->GetDicomDirPatients().end() ) {  // on degouline les PATIENT de ce DICOMDIR
301       std::cout << (*itPatient)->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name
302       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
303       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
304          std::cout << "--- "<< (*itStudy)->GetEntryString(0x0008, 0x1030) << std::endl; // Study Description
305          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
306          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
307             std::cout << "--- --- "<< (*itSerie)->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description
308             itImage = ((*itSerie)->GetDicomDirImages()).begin();
309             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
310                std::cout << "--- --- --- "<< (*itImage)->GetEntryString(0x0004, 0x1500) << std::endl; // File name
311                ++itImage;   
312             }
313             ++itSerie;   
314          }
315          ++itStudy;
316       }  
317       itPatient ++;    
318    }   
319  */  
320
321
322    if(f->IsReadable())
323       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
324    else
325       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
326    std::cout<<std::flush;
327    f->Delete();
328
329    return(0);
330 }