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