1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/06/07 11:12:10 $
7 Version: $Revision: 1.22 $
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.
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.
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"
26 #include "gdcmDebug.h"
28 #include "gdcmArgMgr.h"
33 int main(int argc, char* argv[])
36 " \n PrintDicomDir :\n",
37 " Display the tree-like structure of a DICOMDIR File",
38 " usage: PrintDicomDir filein=fileName [level=n] [debug] ",
39 " detail = 1 : Patients, 2 : Studies, 3 : Series, 4 : Images ",
41 " level = 0,1,2 : depending on user (what he wants to see)",
42 " debug : user wants to run the program in 'debug mode' ",
45 // Initialize Arguments Manager
46 gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
50 am->ArgMgrUsage(usage); // Display 'usage'
58 gdcm::DicomDirPatient *pa;
59 gdcm::DicomDirStudy *st;
60 gdcm::DicomDirSerie *se;
61 gdcm::DicomDirImage *im;
64 fileName = am->ArgMgrWantString("filein",usage);
66 int level = am->ArgMgrGetInt("level", 2);
68 int detailLevel = am->ArgMgrGetInt("detail", 2);
70 if (am->ArgMgrDefined("debug"))
71 gdcm::Debug::DebugOn();
73 /* if unused Param we give up */
74 if ( am->ArgMgrPrintUnusedLabels() )
76 am->ArgMgrUsage(usage);
82 // new style is useless, since it has no effect for *reading* a DICOMDIR
83 // (only meaningfull when *creating* a DICOMDIR)
85 e1 = new gdcm::DicomDir( fileName );
87 //e1 = new gdcm::DicomDir();
88 //e1->SetParseDir(false);
89 //e1->Load( fileName );
91 // Test if the DicomDir is readable
92 if( !e1->IsReadable() )
94 std::cout<<" DicomDir '"<<fileName
95 <<"' is not readable"<<std::endl
96 <<" ...Failed"<<std::endl;
102 e1->SetPrintLevel(level);
104 // Test if the DicomDir contains any Patient
105 pa = e1->GetFirstPatient();
108 std::cout<<" DicomDir '"<<fileName
109 <<" has no patient"<<std::endl
110 <<" ...Failed"<<std::endl;
116 // Structure use Examples
121 std::cout << std::endl << std::endl
122 << " = PATIENT List =========================================="
123 << std::endl<< std::endl;
125 pa = e1->GetFirstPatient();
128 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
129 pa = e1->GetNextPatient();
134 std::cout << std::endl << std::endl
135 << " = PATIENT/STUDY List ======================================="
136 << std::endl<< std::endl;
138 pa = e1->GetFirstPatient();
139 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
141 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
143 st = pa->GetFirstStudy();
144 while ( st ) { // on degouline les STUDY de ce patient
145 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
146 st = pa->GetNextStudy();
148 pa = e1->GetNextPatient();
153 std::cout << std::endl << std::endl
154 << " = PATIENT/STUDY/SERIE List =================================="
155 << std::endl<< std::endl;
157 pa = e1->GetFirstPatient();
158 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
160 // Patient's Name, Patient ID
161 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
162 std::cout << " Pat.ID:[";
163 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
165 st = pa->GetFirstStudy();
166 while ( st ) { // on degouline les STUDY de ce patient
167 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
168 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
169 std::cout << "]" << std::endl;
171 se = st->GetFirstSerie();
172 while ( se ) { // on degouline les SERIES de cette study
173 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
174 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
175 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
176 std::cout << std::endl;
177 se = st->GetNextSerie();
179 st = pa->GetNextStudy();
181 pa = e1->GetNextPatient();
186 std::cout << std::endl << std::endl
187 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
188 << std::endl<< std::endl;
190 pa = e1->GetFirstPatient();
191 while ( pa ) { // les PATIENT de ce DICOMDIR
192 // Patient's Name, Patient ID
193 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
194 std::cout << " Pat.ID:[";
195 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
197 st = pa->GetFirstStudy();
198 while ( st ) { // on degouline les STUDY de ce patient
199 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
200 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
201 std::cout << "]" << std::endl;
203 se = st->GetFirstSerie();
204 while ( se ) { // on degouline les SERIES de cette study
205 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
206 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
207 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
208 std::cout << std::endl;
210 im = se->GetFirstImage();
211 while ( im ) { // on degouline les Images de cette serie
212 std::cout << "--- --- --- "<< im->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
213 im = se->GetNextImage();
215 se = st->GetNextSerie();
217 st = pa->GetNextStudy();
219 pa = e1->GetNextPatient();
224 std::cout << std::endl << std::endl
225 << " = DICOMDIR full content =========================================="
226 << std::endl<< std::endl;
235 // Kept as an example. Please don't remove
237 gdcm::ListDicomDirPatient::const_iterator itPatient;
238 gdcm::ListDicomDirStudy::const_iterator itStudy;
239 gdcm::ListDicomDirSerie::const_iterator itSerie;
240 gdcm::ListDicomDirImage::const_iterator itImage;
241 cout << std::endl << std::endl
242 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
243 << std::endl<< std::endl;
245 itPatient = e1->GetDicomDirPatients().begin();
246 while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
247 std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
248 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
249 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
250 std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
251 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
252 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
253 std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
254 itImage = ((*itSerie)->GetDicomDirImages()).begin();
255 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
256 std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
269 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
271 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
272 std::cout<<std::flush;