1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/01/24 16:10:49 $
7 Version: $Revision: 1.18 $
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 "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
26 #include "gdcmDebug.h"
31 int main(int argc, char* argv[])
36 gdcm::DicomDirPatient *pa;
37 gdcm::DicomDirStudy *st;
38 gdcm::DicomDirSerie *se;
39 gdcm::DicomDirImage *im;
46 fileName = GDCM_DATA_ROOT;
47 fileName += "/DICOMDIR";
51 gdcm::Debug::SetDebugOn();
53 e1 = new gdcm::DicomDir( fileName );
58 detailLevel = atoi(argv[2]);
62 // Test if the DicomDir is readable
63 if( !e1->IsReadable() )
65 std::cout<<" DicomDir '"<<fileName
66 <<"' is not readable"<<std::endl
67 <<" ...Failed"<<std::endl;
73 // Test if the DicomDir contains any Patient
74 pa = e1->GetFirstPatient();
77 std::cout<<" DicomDir '"<<fileName
78 <<" has no patient"<<std::endl
79 <<" ...Failed"<<std::endl;
85 // Structure use Examples
90 std::cout << std::endl << std::endl
91 << " = PATIENT List =========================================="
92 << std::endl<< std::endl;
94 pa = e1->GetFirstPatient();
97 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
98 pa = e1->GetNextPatient();
103 std::cout << std::endl << std::endl
104 << " = PATIENT/STUDY List ======================================="
105 << std::endl<< std::endl;
107 pa = e1->GetFirstPatient();
108 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
110 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
112 st = pa->GetFirstStudy();
113 while ( st ) { // on degouline les STUDY de ce patient
114 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
115 st = pa->GetNextStudy();
117 pa = e1->GetNextPatient();
122 std::cout << std::endl << std::endl
123 << " = PATIENT/STUDY/SERIE List =================================="
124 << std::endl<< std::endl;
126 pa = e1->GetFirstPatient();
127 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
129 // Patient's Name, Patient ID
130 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
131 std::cout << " Pat.ID:[";
132 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
134 st = pa->GetFirstStudy();
135 while ( st ) { // on degouline les STUDY de ce patient
136 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
137 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
138 std::cout << "]" << std::endl;
140 se = st->GetFirstSerie();
141 while ( se ) { // on degouline les SERIES de cette study
142 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
143 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
144 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
145 std::cout << std::endl;
146 se = st->GetNextSerie();
148 st = pa->GetNextStudy();
150 pa = e1->GetNextPatient();
155 std::cout << std::endl << std::endl
156 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
157 << std::endl<< std::endl;
159 pa = e1->GetFirstPatient();
160 while ( pa ) { // les PATIENT de ce DICOMDIR
161 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
163 st = pa->GetFirstStudy();
164 while ( st ) { // on degouline les STUDY de ce patient
165 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
166 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
168 se = st->GetFirstSerie();
169 while ( se ) { // on degouline les SERIES de cette study
170 std::cout << "--- --- "<< se->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
171 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
172 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
174 im = se->GetFirstImage();
175 while ( im ) { // on degouline les Images de cette serie
176 std::cout << "--- --- --- "<< im->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
177 im = se->GetNextImage();
179 se = st->GetNextSerie();
181 st = pa->GetNextStudy();
183 pa = e1->GetNextPatient();
188 std::cout << std::endl << std::endl
189 << " = DICOMDIR full content =========================================="
190 << std::endl<< std::endl;
199 // Kept as an example. Please don't remove
201 gdcm::ListDicomDirPatient::const_iterator itPatient;
202 gdcm::ListDicomDirStudy::const_iterator itStudy;
203 gdcm::ListDicomDirSerie::const_iterator itSerie;
204 gdcm::ListDicomDirImage::const_iterator itImage;
205 cout << std::endl << std::endl
206 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
207 << std::endl<< std::endl;
209 itPatient = e1->GetDicomDirPatients().begin();
210 while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
211 std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
212 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
213 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
214 std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
215 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
216 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
217 std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
218 itImage = ((*itSerie)->GetDicomDirImages()).begin();
219 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
220 std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
233 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
235 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
236 std::cout<<std::flush;