]> Creatis software - gdcm.git/blob - Example/PrintDicomDir.cxx
2005-01-13 Jean-Pierre Roux <jpr@creatis.univ-lyon1.fr>
[gdcm.git] / Example / PrintDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/13 14:56:39 $
7   Version:   $Revision: 1.13 $
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    
35    gdcm::ListDicomDirPatient::const_iterator  itPatient;
36    gdcm::ListDicomDirStudy::const_iterator    itStudy;
37    gdcm::ListDicomDirSerie::const_iterator    itSerie;
38    gdcm::ListDicomDirImage::const_iterator    itImage;
39    gdcm::TSKey v;
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    if( !e1->IsReadable() )
63    {
64       std::cout<<"          DicomDir '"<<fileName
65                <<"' is not readable"<<std::endl
66                <<"          ...Failed"<<std::endl;
67
68       delete e1;
69       return 1;
70    }
71
72    if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() )
73    {
74       std::cout<<"          DicomDir '"<<fileName
75                <<" has no patients"<<std::endl
76                <<"          ...Failed"<<std::endl;
77
78       delete e1;
79       return 1;
80    }
81
82 // Structure use Examples 
83
84    switch (detailLevel)
85   { 
86   case 1:
87      std::cout << std::endl << std::endl  
88        << " =  PATIENT List ==========================================" 
89        << std::endl<< std::endl;
90
91       itPatient = e1->GetDicomDirPatients().begin();
92       while ( itPatient != e1->GetDicomDirPatients().end() ) // on degouline la liste de PATIENT
93       {
94          std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name   
95          itPatient ++;    
96       }
97       break;
98
99    case 2:    
100       std::cout << std::endl << std::endl  
101         << " = PATIENT/STUDY List =======================================" 
102         << std::endl<< std::endl;
103
104       itPatient = e1->GetDicomDirPatients().begin();
105       while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
106          std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name 
107          itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
108          while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
109             std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
110             ++itStudy;
111          }
112          itPatient ++;    
113       }   
114       break;
115
116    case 3: 
117       std::cout << std::endl << std::endl  
118         << " =  PATIENT/STUDY/SERIE List ==================================" 
119         << std::endl<< std::endl;
120  
121       itPatient = e1->GetDicomDirPatients().begin();
122       while ( itPatient != e1->GetDicomDirPatients().end() )   // on degouline la liste de PATIENT
123       {
124        // Patient's Name, Patient ID 
125          std::cout << "Pat.Name:[" << (*itPatient)->GetEntry(0x0010, 0x0010) <<"]"; // Patient's Name
126          std::cout << " Pat.ID:[";
127          std::cout << (*itPatient)->GetEntry(0x0010, 0x0020) << "]" << std::endl; // Patient ID
128          itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
129          while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
130             std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntry(0x0008, 0x1030) << "]";// Study Description 
131             std::cout << " Stud.ID:["          << (*itStudy)->GetEntry(0x0020, 0x0010);       // Study ID
132             std::cout << "]" << std::endl;
133             itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
134             while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
135                std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntry(0x0008, 0x103e)<< "]";  // Series Description
136                std::cout << " Ser.nb:["         <<  (*itSerie)->GetEntry(0x0020, 0x0011);        // Series number
137                std::cout << "] Mod.:["          <<  (*itSerie)->GetEntry(0x0008, 0x0060) << "]"; // Modality
138               std::cout << std::endl;    
139                ++itSerie;   
140             }
141             ++itStudy;
142          }
143          itPatient ++;    
144       } 
145       break;
146
147    case 4:  
148       std::cout << std::endl << std::endl  
149            << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
150            << std::endl<< std::endl;
151  
152       itPatient = e1->GetDicomDirPatients().begin();
153       while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
154          std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
155          itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
156          while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
157             std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
158             itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
159             while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
160                std::cout << "--- --- "<< (*itSerie)->GetEntry(0x0008, 0x103e) << std::endl; // Serie Description
161                itImage = ((*itSerie)->GetDicomDirImages()).begin();
162                while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study
163                   std::cout << "--- --- --- "<< (*itImage)->GetEntry(0x0004, 0x1500) << std::endl; // File name
164                   ++itImage;   
165                }
166                ++itSerie;   
167            }
168            ++itStudy;
169         }  
170         itPatient ++;    
171       }
172       break;
173
174    case 5:
175       std::cout << std::endl << std::endl  
176            << " = DICOMDIR full content ==========================================" 
177            << std::endl<< std::endl;
178       e1->Print();
179       break;
180
181    }  // end switch
182
183
184
185    if(e1->IsReadable())
186       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
187    else
188       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
189    std::cout<<std::flush;
190    delete e1;
191
192    return(0);
193 }