1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/04/26 16:21:54 $
7 Version: $Revision: 1.21 $
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::DebugOn();
53 // new style is useless, since it has no effect fore *reading* a DICOMDIR
54 // (only meaningfull when *creating* a DICOMDIR)
56 e1 = new gdcm::DicomDir( fileName );
58 //e1 = new gdcm::DicomDir();
59 //e1->SetParseDir(false);
60 //e1->Load( fileName );
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;
76 detailLevel = atoi(argv[2]);
80 // Test if the DicomDir contains any Patient
81 pa = e1->GetFirstPatient();
84 std::cout<<" DicomDir '"<<fileName
85 <<" has no patient"<<std::endl
86 <<" ...Failed"<<std::endl;
92 // Structure use Examples
97 std::cout << std::endl << std::endl
98 << " = PATIENT List =========================================="
99 << std::endl<< std::endl;
101 pa = e1->GetFirstPatient();
104 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
105 pa = e1->GetNextPatient();
110 std::cout << std::endl << std::endl
111 << " = PATIENT/STUDY List ======================================="
112 << std::endl<< std::endl;
114 pa = e1->GetFirstPatient();
115 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
117 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
119 st = pa->GetFirstStudy();
120 while ( st ) { // on degouline les STUDY de ce patient
121 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
122 st = pa->GetNextStudy();
124 pa = e1->GetNextPatient();
129 std::cout << std::endl << std::endl
130 << " = PATIENT/STUDY/SERIE List =================================="
131 << std::endl<< std::endl;
133 pa = e1->GetFirstPatient();
134 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
136 // Patient's Name, Patient ID
137 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
138 std::cout << " Pat.ID:[";
139 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
141 st = pa->GetFirstStudy();
142 while ( st ) { // on degouline les STUDY de ce patient
143 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
144 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
145 std::cout << "]" << std::endl;
147 se = st->GetFirstSerie();
148 while ( se ) { // on degouline les SERIES de cette study
149 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
150 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
151 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
152 std::cout << std::endl;
153 se = st->GetNextSerie();
155 st = pa->GetNextStudy();
157 pa = e1->GetNextPatient();
162 std::cout << std::endl << std::endl
163 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
164 << std::endl<< std::endl;
166 pa = e1->GetFirstPatient();
167 while ( pa ) { // les PATIENT de ce DICOMDIR
168 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
170 st = pa->GetFirstStudy();
171 while ( st ) { // on degouline les STUDY de ce patient
172 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
173 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
175 se = st->GetFirstSerie();
176 while ( se ) { // on degouline les SERIES de cette study
177 std::cout << "--- --- "<< se->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
178 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
179 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
181 im = se->GetFirstImage();
182 while ( im ) { // on degouline les Images de cette serie
183 std::cout << "--- --- --- "<< im->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
184 im = se->GetNextImage();
186 se = st->GetNextSerie();
188 st = pa->GetNextStudy();
190 pa = e1->GetNextPatient();
195 std::cout << std::endl << std::endl
196 << " = DICOMDIR full content =========================================="
197 << std::endl<< std::endl;
206 // Kept as an example. Please don't remove
208 gdcm::ListDicomDirPatient::const_iterator itPatient;
209 gdcm::ListDicomDirStudy::const_iterator itStudy;
210 gdcm::ListDicomDirSerie::const_iterator itSerie;
211 gdcm::ListDicomDirImage::const_iterator itImage;
212 cout << std::endl << std::endl
213 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
214 << std::endl<< std::endl;
216 itPatient = e1->GetDicomDirPatients().begin();
217 while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
218 std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
219 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
220 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
221 std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
222 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
223 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
224 std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
225 itImage = ((*itSerie)->GetDicomDirImages()).begin();
226 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
227 std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
240 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
242 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
243 std::cout<<std::flush;