1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2007/05/23 14:18:04 $
7 Version: $Revision: 1.36 $
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"
25 #include "gdcmDicomDirPrivate.h"
27 #include "gdcmDebug.h"
29 #include "gdcmArgMgr.h"
34 int main(int argc, char* argv[])
37 " \n PrintDicomDir :\n ",
38 " Display the tree-like structure of a DICOMDIR File ",
39 " usage: PrintDicomDir filein=fileName [level=n][detail=m][debug] ",
40 " detail = 1 : Patients, 2 : Studies, 3 : Series, 4 : Images ",
42 " level = 0,1,2 : depending on user (what he wants to see) ",
43 " warning : user wants to run the program in 'warning mode' ",
44 " debug : developper wants to run the program in 'debug mode' ",
47 // Initialize Arguments Manager
48 GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
50 if (argc == 1 || am->ArgMgrDefined("usage") )
52 am->ArgMgrUsage(usage); // Display 'usage'
57 GDCM_NAME_SPACE::DicomDir *f;
58 GDCM_NAME_SPACE::TSKey v;
60 GDCM_NAME_SPACE::DicomDirPatient *pa;
61 GDCM_NAME_SPACE::DicomDirStudy *st;
62 GDCM_NAME_SPACE::DicomDirSerie *se;
63 GDCM_NAME_SPACE::DicomDirVisit *vs;
64 GDCM_NAME_SPACE::DicomDirImage *im;
65 GDCM_NAME_SPACE::DicomDirPrivate *pr;
67 fileName = am->ArgMgrWantString("filein",usage);
69 int level = am->ArgMgrGetInt("level", 2);
71 int detailLevel = am->ArgMgrGetInt("detail", 2);
73 if (am->ArgMgrDefined("debug"))
74 GDCM_NAME_SPACE::Debug::DebugOn();
76 if (am->ArgMgrDefined("warning"))
77 GDCM_NAME_SPACE::Debug::WarningOn();
79 /* if unused Param we give up */
80 if ( am->ArgMgrPrintUnusedLabels() )
82 am->ArgMgrUsage(usage);
89 f = GDCM_NAME_SPACE::DicomDir::New();
90 f->SetFileName ( fileName );
93 // Test if the DicomDir is readable
94 if( !f->IsReadable() )
96 std::cout<<" DicomDir '"<<fileName
97 <<"' is not readable"<<std::endl
98 <<" ...Failed"<<std::endl;
104 f->SetPrintLevel(level);
106 // Test if the DicomDir contains any Patient
107 pa = f->GetFirstPatient();
110 std::cout<<" DicomDir '"<<fileName
111 <<" has no patient"<<std::endl
112 <<" ...Failed"<<std::endl;
118 // Structure use Examples
123 std::cout << std::endl << std::endl
124 << " = PATIENT List =========================================="
125 << std::endl<< std::endl;
127 pa = f->GetFirstPatient();
130 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
131 std::cout << " Pat.ID:[";
132 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
133 pa = f->GetNextPatient();
138 std::cout << std::endl << std::endl
139 << " = PATIENT/STUDY List ======================================="
140 << std::endl<< std::endl;
142 pa = f->GetFirstPatient();
143 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
145 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
146 std::cout << " Pat.ID:[";
147 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
148 st = pa->GetFirstStudy();
150 { // on degouline les STUDY de ce patient
151 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
152 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
153 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
154 std::cout << std::endl;
155 st = pa->GetNextStudy();
157 pa = f->GetNextPatient();
162 std::cout << std::endl << std::endl
163 << " = PATIENT/STUDY/SERIE List =================================="
164 << std::endl<< std::endl;
166 pa = f->GetFirstPatient();
167 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
169 // Patient's Name, Patient ID
170 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
171 std::cout << " Pat.ID:[";
172 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
174 st = pa->GetFirstStudy();
176 { // on degouline les STUDY de ce patient
177 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
178 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
179 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
180 std::cout << std::endl;
182 se = st->GetFirstSerie();
184 { // on degouline les SERIES de cette study
185 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description
186 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number
187 std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
188 std::cout << " Serie Inst.UID.:[" << se->GetEntryString(0x0020, 0x000e) << "]"; // Series Instance UID
189 std::cout << std::endl;
190 se = st->GetNextSerie();
193 vs = st->GetFirstVisit();
195 { // on degouline les VISIT de cette study
196 std::cout << "--- --- VISIT: ";
197 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
198 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
199 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
200 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
201 std::cout << std::endl;
202 vs = st->GetNextVisit();
205 st = pa->GetNextStudy();
207 pa = f->GetNextPatient();
212 std::cout << std::endl << std::endl
213 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
214 << std::endl<< std::endl;
216 pa = f->GetFirstPatient();
218 { // les PATIENT de ce DICOMDIR
219 // Patient's Name, Patient ID
220 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
221 std::cout << " Pat.ID:[";
222 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
224 st = pa->GetFirstStudy();
226 { // on degouline les STUDY de ce patient
227 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
228 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
229 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
230 std::cout << std::endl;
232 vs = st->GetFirstVisit();
234 { // on degouline les VISIT de cette study
235 std::cout << "--- --- VISIT: ";
236 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
237 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
238 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
239 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
240 std::cout << std::endl;
241 vs = st->GetNextVisit();
244 se = st->GetFirstSerie();
246 { // on degouline les SERIES de cette study
247 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e) << "]"; // Series Description
248 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011) << "]"; // Series number
249 std::cout << " Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
250 std::cout << " Serie Inst.UID.:[" << se->GetEntryString(0x0020, 0x000e) << "]"; // Series Instance UID
251 std::cout << std::endl;
253 im = se->GetFirstImage();
255 { // on degouline les Images de cette serie
256 std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryString(0x0004, 0x1500)
257 << "]" << std::endl; // File name (Referenced File ID)
258 im = se->GetNextImage();
261 pr = se->GetFirstPrivate();
263 { // on degouline les 'Privates' de cette serie
264 std::cout << "--- --- --- "<< " PRIVATE Ref. File ID :[" << pr->GetEntryString(0x0004, 0x1500)
265 << "]" << std::endl; // File name (Referenced File ID)
266 pr = se->GetNextPrivate();
269 se = st->GetNextSerie();
271 st = pa->GetNextStudy();
273 pa = f->GetNextPatient();
278 std::cout << std::endl << std::endl
279 << " = DICOMDIR full content =========================================="
280 << std::endl<< std::endl;
289 // Kept as an example. Please don't remove
291 GDCM_NAME_SPACE::ListDicomDirPatient::const_iterator itPatient;
292 GDCM_NAME_SPACE::ListDicomDirStudy::const_iterator itStudy;
293 GDCM_NAME_SPACE::ListDicomDirSerie::const_iterator itSerie;
294 GDCM_NAME_SPACE::ListDicomDirImage::const_iterator itImage;
295 cout << std::endl << std::endl
296 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
297 << std::endl<< std::endl;
299 itPatient = f->GetDicomDirPatients().begin();
300 while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
301 std::cout << (*itPatient)->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name
302 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
303 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
304 std::cout << "--- "<< (*itStudy)->GetEntryString(0x0008, 0x1030) << std::endl; // Study Description
305 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
306 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
307 std::cout << "--- --- "<< (*itSerie)->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description
308 itImage = ((*itSerie)->GetDicomDirImages()).begin();
309 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
310 std::cout << "--- --- --- "<< (*itImage)->GetEntryString(0x0004, 0x1500) << std::endl; // File name
323 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
325 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
326 std::cout<<std::flush;