1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/07/11 13:54:51 $
7 Version: $Revision: 1.27 $
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 "gdcmDicomDirVisit.h"
24 #include "gdcmDicomDirSerie.h"
25 #include "gdcmDicomDirImage.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] [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 " debug : user wants to run the program in 'debug mode' ",
46 // Initialize Arguments Manager
47 gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
51 am->ArgMgrUsage(usage); // Display 'usage'
59 gdcm::DicomDirPatient *pa;
60 gdcm::DicomDirStudy *st;
61 gdcm::DicomDirSerie *se;
62 gdcm::DicomDirVisit *vs;
63 gdcm::DicomDirImage *im;
66 fileName = am->ArgMgrWantString("filein",usage);
68 int level = am->ArgMgrGetInt("level", 2);
70 int detailLevel = am->ArgMgrGetInt("detail", 2);
72 if (am->ArgMgrDefined("debug"))
73 gdcm::Debug::DebugOn();
75 /* if unused Param we give up */
76 if ( am->ArgMgrPrintUnusedLabels() )
78 am->ArgMgrUsage(usage);
85 f = new gdcm::DicomDir();
86 f->SetFileName ( fileName );
89 // Test if the DicomDir is readable
90 if( !f->IsReadable() )
92 std::cout<<" DicomDir '"<<fileName
93 <<"' is not readable"<<std::endl
94 <<" ...Failed"<<std::endl;
100 f->SetPrintLevel(level);
102 // Test if the DicomDir contains any Patient
103 pa = f->GetFirstPatient();
106 std::cout<<" DicomDir '"<<fileName
107 <<" has no patient"<<std::endl
108 <<" ...Failed"<<std::endl;
114 // Structure use Examples
119 std::cout << std::endl << std::endl
120 << " = PATIENT List =========================================="
121 << std::endl<< std::endl;
123 pa = f->GetFirstPatient();
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();
134 std::cout << std::endl << std::endl
135 << " = PATIENT/STUDY List ======================================="
136 << std::endl<< std::endl;
138 pa = f->GetFirstPatient();
139 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
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();
151 pa = f->GetNextPatient();
156 std::cout << std::endl << std::endl
157 << " = PATIENT/STUDY/SERIE List =================================="
158 << std::endl<< std::endl;
160 pa = f->GetFirstPatient();
161 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
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
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;
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();
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();
194 st = pa->GetNextStudy();
196 pa = f->GetNextPatient();
201 std::cout << std::endl << std::endl
202 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
203 << std::endl<< std::endl;
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
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;
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();
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;
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();
242 se = st->GetNextSerie();
244 st = pa->GetNextStudy();
246 pa = f->GetNextPatient();
251 std::cout << std::endl << std::endl
252 << " = DICOMDIR full content =========================================="
253 << std::endl<< std::endl;
262 // Kept as an example. Please don't remove
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;
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
296 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
298 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
299 std::cout<<std::flush;