1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2006/07/17 13:27:04 $
7 Version: $Revision: 1.33 $
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][detail=m][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 = gdcm::DicomDir::New();
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();
145 { // on degouline les STUDY de ce patient
146 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
147 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
148 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
149 std::cout << std::endl;
150 st = pa->GetNextStudy();
152 pa = f->GetNextPatient();
157 std::cout << std::endl << std::endl
158 << " = PATIENT/STUDY/SERIE List =================================="
159 << std::endl<< std::endl;
161 pa = f->GetFirstPatient();
162 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
164 // Patient's Name, Patient ID
165 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
166 std::cout << " Pat.ID:[";
167 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
169 st = pa->GetFirstStudy();
171 { // on degouline les STUDY de ce patient
172 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
173 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
174 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
175 std::cout << std::endl;
177 se = st->GetFirstSerie();
179 { // on degouline les SERIES de cette study
180 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description
181 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number
182 std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
183 std::cout << " Serie Inst.UID.:[" << se->GetEntryString(0x0020, 0x000e) << "]"; // Series Instance UID
184 std::cout << std::endl;
185 se = st->GetNextSerie();
188 vs = st->GetFirstVisit();
190 { // on degouline les VISIT de cette study
191 std::cout << "--- --- VISIT: ";
192 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
193 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
194 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
195 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
196 std::cout << std::endl;
197 vs = st->GetNextVisit();
200 st = pa->GetNextStudy();
202 pa = f->GetNextPatient();
207 std::cout << std::endl << std::endl
208 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
209 << std::endl<< std::endl;
211 pa = f->GetFirstPatient();
213 { // les PATIENT de ce DICOMDIR
214 // Patient's Name, Patient ID
215 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
216 std::cout << " Pat.ID:[";
217 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
219 st = pa->GetFirstStudy();
221 { // on degouline les STUDY de ce patient
222 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
223 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
224 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
225 std::cout << std::endl;
227 vs = st->GetFirstVisit();
229 { // on degouline les VISIT de cette study
230 std::cout << "--- --- VISIT: ";
231 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
232 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
233 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
234 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
235 std::cout << std::endl;
236 vs = st->GetNextVisit();
239 se = st->GetFirstSerie();
241 { // on degouline les SERIES de cette study
242 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e) << "]"; // Series Description
243 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011) << "]"; // Series number
244 std::cout << " Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
245 std::cout << " Serie Inst.UID.:[" << se->GetEntryString(0x0020, 0x000e) << "]"; // Series Instance UID
246 std::cout << std::endl;
248 im = se->GetFirstImage();
250 { // on degouline les Images de cette serie
251 std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryString(0x0004, 0x1500)
252 << "]" << std::endl; // File name (Referenced File ID)
253 im = se->GetNextImage();
255 se = st->GetNextSerie();
257 st = pa->GetNextStudy();
259 pa = f->GetNextPatient();
264 std::cout << std::endl << std::endl
265 << " = DICOMDIR full content =========================================="
266 << std::endl<< std::endl;
275 // Kept as an example. Please don't remove
277 gdcm::ListDicomDirPatient::const_iterator itPatient;
278 gdcm::ListDicomDirStudy::const_iterator itStudy;
279 gdcm::ListDicomDirSerie::const_iterator itSerie;
280 gdcm::ListDicomDirImage::const_iterator itImage;
281 cout << std::endl << std::endl
282 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
283 << std::endl<< std::endl;
285 itPatient = f->GetDicomDirPatients().begin();
286 while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
287 std::cout << (*itPatient)->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name
288 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
289 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
290 std::cout << "--- "<< (*itStudy)->GetEntryString(0x0008, 0x1030) << std::endl; // Study Description
291 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
292 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
293 std::cout << "--- --- "<< (*itSerie)->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description
294 itImage = ((*itSerie)->GetDicomDirImages()).begin();
295 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
296 std::cout << "--- --- --- "<< (*itImage)->GetEntryString(0x0004, 0x1500) << std::endl; // File name
309 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
311 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
312 std::cout<<std::flush;