]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
Remove redundant (with TestDicomDir) PrintDicomDir.cxx file
[gdcm.git] / Testing / TestDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/13 14:39:02 $
7   Version:   $Revision: 1.26 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDicomDirStudy.h"
22 #include "gdcmDicomDirSerie.h"
23 #include "gdcmDicomDirImage.h"
24 #include "gdcmTS.h"
25
26 #include <iostream>
27 #include <fstream>
28
29 int TestDicomDir(int argc, char* argv[])
30 {  
31    gdcm::DicomDir *e1;
32    
33    gdcm::ListDicomDirPatient::const_iterator  itPatient;
34    gdcm::ListDicomDirStudy::const_iterator    itStudy;
35    gdcm::ListDicomDirSerie::const_iterator    itSerie;
36    //gdcm::ListDicomDirImage::const_iterator    itImage;
37    gdcm::TSKey v;
38     
39    std::string file; 
40    if (argc > 1) 
41       file = argv[1];    
42    else 
43    {
44       file += GDCM_DATA_ROOT;
45       file += "/DICOMDIR";
46    }
47
48    e1 = new gdcm::DicomDir(file);
49    if (argc > 2) 
50    {
51       int level = atoi(argv[2]);   
52       e1->SetPrintLevel(level);
53    }
54
55    // Test if the dicomDir is readable
56    if( !e1->IsReadable() )
57    {
58       std::cout<<"          DicomDir '"<<file
59                <<"' is not readable"<<std::endl
60                <<"          ...Failed"<<std::endl;
61
62       delete e1;
63       return 1;
64    }
65
66    if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() )
67    {
68       std::cout<<"          DicomDir '"<<file
69                <<" has no patient"<<std::endl
70                <<"          ...Failed"<<std::endl;
71
72       delete e1;
73       return 1;
74    }
75
76 // Simple examples of structure exploitation 
77 // DON'T REMOVE neither the following code, nor the commented out lines
78
79 /*
80   cout << std::endl << std::endl  
81         << " = Liste des PATIENT ==========================================" 
82         << std::endl<< std::endl;
83
84
85    itPatient = e1->GetDicomDirPatients().begin();
86    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
87       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name   
88       itPatient ++;    
89    }
90 */
91
92 /*        
93    cout << std::endl << std::endl  
94         << " = Liste des PATIENT/STUDY ==========================================" 
95         << std::endl<< std::endl;
96
97    itPatient = e1->GetDicomDirPatients().begin();
98    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
99       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name 
100       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
101       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
102          std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
103          ++itStudy;
104       }
105       itPatient ++;    
106    }   
107  */
108  
109    std::cout << std::endl << std::endl  
110              << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
111              << std::endl<< std::endl;
112  
113    itPatient = e1->GetDicomDirPatients().begin();
114    while ( itPatient != e1->GetDicomDirPatients().end() ) // on degouline la liste de PATIENT
115    {  
116        // Patient's Name, Patient ID 
117       std::cout << "Pat.Name:[" << (*itPatient)->GetEntry(0x0010, 0x0010) <<"]";
118       std::cout << " Pat.ID:[";
119       std::cout << (*itPatient)->GetEntry(0x0010, 0x0020) << "]" << std::endl;
120       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
121       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
122          std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntry(0x0008, 0x1030) << "]";// Study Description 
123          std::cout << " Stud.ID:["<< (*itStudy)->GetEntry(0x0020, 0x0010);                 // Study ID
124          std::cout << "]" << std::endl;
125          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
126          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) // on degouline les SERIES de cette study
127          {
128             std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntry(0x0008, 0x103e)<< "]";// Serie Description
129             std::cout << " Ser.nb:[" <<   (*itSerie)->GetEntry(0x0020, 0x0011);            // Serie number
130             std::cout << "] Mod.:["    <<   (*itSerie)->GetEntry(0x0008, 0x0060) << "]";   // Modality
131             std::cout << std::endl;
132             ++itSerie;   
133          }
134          ++itStudy;
135       }
136       itPatient ++;    
137    } 
138    
139     
140  /*
141    cout << std::endl << std::endl  
142         << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
143         << std::endl<< std::endl;
144  
145    itPatient = e1->GetDicomDirPatients().begin();
146    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
147       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
148       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
149       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
150          std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
151          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
152          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
153             std::cout << "--- --- "<< (*itSerie)->GetEntry(0x0008, 0x103e) << std::endl; // Serie Description
154             itImage = ((*itSerie)->GetDicomDirImages()).begin();
155             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study
156                std::cout << "--- --- --- "<< (*itImage)->GetEntry(0x0004, 0x1500) << std::endl; // File name
157                ++itImage;   
158             }
159             ++itSerie;   
160          }
161          ++itStudy;
162       }  
163       itPatient ++;    
164    }   
165  */  
166
167    std::cout << std::endl << std::endl  
168              << " = Contenu Complet du DICOMDIR ==========================================" 
169              << std::endl<< std::endl;
170    e1->Print();
171    
172    std::cout<<std::flush;
173    delete e1;
174
175    return 0;
176 }