1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2006/01/18 15:45:21 $
7 Version: $Revision: 1.32 $
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 << 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->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
165 std::cout << " Pat.ID:[";
166 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
168 st = pa->GetFirstStudy();
170 { // on degouline les STUDY de ce patient
171 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
172 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
173 std::cout << std::endl;
175 se = st->GetFirstSerie();
177 { // on degouline les SERIES de cette study
178 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description
179 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number
180 std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
181 std::cout << std::endl;
182 se = st->GetNextSerie();
185 vs = st->GetFirstVisit();
187 { // on degouline les VISIT de cette study
188 std::cout << "--- --- VISIT: ";
189 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
190 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
191 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
192 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
193 std::cout << std::endl;
194 vs = st->GetNextVisit();
197 st = pa->GetNextStudy();
199 pa = f->GetNextPatient();
204 std::cout << std::endl << std::endl
205 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
206 << std::endl<< std::endl;
208 pa = f->GetFirstPatient();
210 { // les PATIENT de ce DICOMDIR
211 // Patient's Name, Patient ID
212 std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name
213 std::cout << " Pat.ID:[";
214 std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID
216 st = pa->GetFirstStudy();
218 { // on degouline les STUDY de ce patient
219 std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description
220 std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID
221 std::cout << " Stud.Inst.UID:[" << st->GetEntryString(0x0020, 0x000d) << "]"; // Study Instance UID
222 std::cout << std::endl;
224 vs = st->GetFirstVisit();
226 { // on degouline les VISIT de cette study
227 std::cout << "--- --- VISIT: ";
228 std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID
229 std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name
230 std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID
231 std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date
232 std::cout << std::endl;
233 vs = st->GetNextVisit();
236 se = st->GetFirstSerie();
238 { // on degouline les SERIES de cette study
239 std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e) << "]"; // Series Description
240 std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011) << "]"; // Series number
241 std::cout << " Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality
242 std::cout << " Serie Inst.UID.:[" << se->GetEntryString(0x0020, 0x000e) << "]"; // Series Instance UID
243 std::cout << std::endl;
245 im = se->GetFirstImage();
247 { // on degouline les Images de cette serie
248 std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryString(0x0004, 0x1500)
249 << "]" << std::endl; // File name (Referenced File ID)
250 im = se->GetNextImage();
252 se = st->GetNextSerie();
254 st = pa->GetNextStudy();
256 pa = f->GetNextPatient();
261 std::cout << std::endl << std::endl
262 << " = DICOMDIR full content =========================================="
263 << std::endl<< std::endl;
272 // Kept as an example. Please don't remove
274 gdcm::ListDicomDirPatient::const_iterator itPatient;
275 gdcm::ListDicomDirStudy::const_iterator itStudy;
276 gdcm::ListDicomDirSerie::const_iterator itSerie;
277 gdcm::ListDicomDirImage::const_iterator itImage;
278 cout << std::endl << std::endl
279 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
280 << std::endl<< std::endl;
282 itPatient = f->GetDicomDirPatients().begin();
283 while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
284 std::cout << (*itPatient)->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name
285 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
286 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
287 std::cout << "--- "<< (*itStudy)->GetEntryString(0x0008, 0x1030) << std::endl; // Study Description
288 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
289 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
290 std::cout << "--- --- "<< (*itSerie)->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description
291 itImage = ((*itSerie)->GetDicomDirImages()).begin();
292 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
293 std::cout << "--- --- --- "<< (*itImage)->GetEntryString(0x0004, 0x1500) << std::endl; // File name
306 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
308 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
309 std::cout<<std::flush;