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