1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/10/18 08:35:43 $
7 Version: $Revision: 1.29 $
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 "gdcmDicomDirPatient.h"
21 #include "gdcmDicomDirStudy.h"
22 #include "gdcmDicomDirVisit.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);
48 if (argc == 1 || am->ArgMgrDefined("usage") )
50 am->ArgMgrUsage(usage); // Display 'usage'
58 gdcm::DicomDirPatient *pa;
59 gdcm::DicomDirStudy *st;
60 gdcm::DicomDirSerie *se;
61 gdcm::DicomDirVisit *vs;
62 gdcm::DicomDirImage *im;
65 fileName = am->ArgMgrWantString("filein",usage);
67 int level = am->ArgMgrGetInt("level", 2);
69 int detailLevel = am->ArgMgrGetInt("detail", 2);
71 if (am->ArgMgrDefined("debug"))
72 gdcm::Debug::DebugOn();
74 /* if unused Param we give up */
75 if ( am->ArgMgrPrintUnusedLabels() )
77 am->ArgMgrUsage(usage);
84 f = new gdcm::DicomDir();
85 f->SetFileName ( fileName );
88 // Test if the DicomDir is readable
89 if( !f->IsReadable() )
91 std::cout<<" DicomDir '"<<fileName
92 <<"' is not readable"<<std::endl
93 <<" ...Failed"<<std::endl;
99 f->SetPrintLevel(level);
101 // Test if the DicomDir contains any Patient
102 pa = f->GetFirstPatient();
105 std::cout<<" DicomDir '"<<fileName
106 <<" has no patient"<<std::endl
107 <<" ...Failed"<<std::endl;
113 // Structure use Examples
118 std::cout << std::endl << std::endl
119 << " = PATIENT List =========================================="
120 << std::endl<< std::endl;
122 pa = f->GetFirstPatient();
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();
133 std::cout << std::endl << std::endl
134 << " = PATIENT/STUDY List ======================================="
135 << std::endl<< std::endl;
137 pa = f->GetFirstPatient();
138 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
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 ) { // on degouline les STUDY de ce patient
145 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
146 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
147 std::cout << std::endl;
148 st = pa->GetNextStudy();
150 pa = f->GetNextPatient();
155 std::cout << std::endl << std::endl
156 << " = PATIENT/STUDY/SERIE List =================================="
157 << std::endl<< std::endl;
159 pa = f->GetFirstPatient();
160 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
162 // Patient's Name, Patient ID
163 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
164 std::cout << " Pat.ID:[";
165 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
167 st = pa->GetFirstStudy();
168 while ( st ) { // on degouline les STUDY de ce patient
169 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
170 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
171 std::cout << std::endl;
173 se = st->GetFirstSerie();
174 while ( se ) { // on degouline les SERIES de cette study
175 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description
176 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number
177 std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
178 std::cout << std::endl;
179 se = st->GetNextSerie();
182 vs = st->GetFirstVisit();
183 while ( vs ) { // on degouline les VISIT de cette study
184 std::cout << "--- --- VISIT: ";
185 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
186 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
187 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
188 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
189 std::cout << std::endl;
190 vs = st->GetNextVisit();
193 st = pa->GetNextStudy();
195 pa = f->GetNextPatient();
200 std::cout << std::endl << std::endl
201 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
202 << std::endl<< std::endl;
204 pa = f->GetFirstPatient();
205 while ( pa ) { // les PATIENT de ce DICOMDIR
206 // Patient's Name, Patient ID
207 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
208 std::cout << " Pat.ID:[";
209 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
211 st = pa->GetFirstStudy();
212 while ( st ) { // on degouline les STUDY de ce patient
213 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
214 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
215 std::cout << std::endl;
217 vs = st->GetFirstVisit();
218 while ( vs ) { // on degouline les VISIT de cette study
219 std::cout << "--- --- VISIT: ";
220 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
221 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
222 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
223 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
224 std::cout << std::endl;
225 vs = st->GetNextVisit();
228 se = st->GetFirstSerie();
229 while ( se ) { // on degouline les SERIES de cette study
230 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description
231 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number
232 std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
233 std::cout << std::endl;
235 im = se->GetFirstImage();
236 while ( im ) { // on degouline les Images de cette serie
237 std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryString(0x0004, 0x1500)
238 << "]" << std::endl; // File name (Referenced File ID)
239 im = se->GetNextImage();
241 se = st->GetNextSerie();
243 st = pa->GetNextStudy();
245 pa = f->GetNextPatient();
250 std::cout << std::endl << std::endl
251 << " = DICOMDIR full content =========================================="
252 << std::endl<< std::endl;
261 // Kept as an example. Please don't remove
263 gdcm::ListDicomDirPatient::const_iterator itPatient;
264 gdcm::ListDicomDirStudy::const_iterator itStudy;
265 gdcm::ListDicomDirSerie::const_iterator itSerie;
266 gdcm::ListDicomDirImage::const_iterator itImage;
267 cout << std::endl << std::endl
268 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
269 << std::endl<< std::endl;
271 itPatient = f->GetDicomDirPatients().begin();
272 while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
273 std::cout << (*itPatient)->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name
274 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
275 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
276 std::cout << "--- "<< (*itStudy)->GetEntryString(0x0008, 0x1030) << std::endl; // Study Description
277 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
278 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
279 std::cout << "--- --- "<< (*itSerie)->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description
280 itImage = ((*itSerie)->GetDicomDirImages()).begin();
281 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
282 std::cout << "--- --- --- "<< (*itImage)->GetEntryString(0x0004, 0x1500) << std::endl; // File name
295 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
297 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
298 std::cout<<std::flush;