]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
To check DICOMDIR related methods
[gdcm.git] / Testing / TestDicomDir.cxx
1 #include <iostream>
2 #include "gdcm.h"
3 #include "gdcmHeaderEntry.h"
4 #include "gdcmDICOMDIR.h"
5
6 #include <fstream>
7 #ifdef GDCM_NO_ANSI_STRING_STREAM
8 #  include <strstream>
9 #  define  ostringstream ostrstream
10 # else
11 #  include <sstream>
12 #endif
13
14 #define  ostringstream ostrstream
15 //extern "C"
16
17
18 void aff (ListTag::iterator deb, ListTag::iterator fin);
19
20 // ===============================================================================
21
22 void aff (ListTag::iterator deb, ListTag::iterator fin, int nbFFFE) {
23    int count =0;
24    for (ListTag::iterator i= deb; i!= fin; i++) {  
25          if( (*i)->GetGroup() == 0xfffe) {
26             count ++;
27             if (count == nbFFFE) break;
28          }
29         (*i)->SetPrintLevel(0);
30         (*i)->Print();
31    } 
32 }
33
34
35 int main(int argc, char* argv[])
36 {  
37    gdcmDICOMDIR* e1;
38    unsigned short int g, e;
39    int o;
40    TSKey v;
41     
42    string a; 
43    if (argc > 1) 
44       a = argv[1];    
45    else 
46       a = "DICOMDIR";
47       
48  e1 = new gdcmDICOMDIR(a);
49
50   if(e1->GetPatients().begin() == e1->GetPatients().end() )
51         std::cout << "Liste Vide" << std::endl;
52
53 // Exemples exploitation de la structure
54
55 ListTag::iterator deb , fin;
56 lPatient::iterator  itPatient;
57
58    cout << std::endl << std::endl  
59         << " = Liste des PATIENT ==========================================" 
60         << std::endl<< std::endl;       
61
62
63     itPatient = e1->GetPatients().begin();      
64     while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
65         //cout << " = PATIENT ==========================================" << std::endl; 
66         //deb = (*itPatient)->beginObj; 
67         //fin =  (*((*itPatient)->GetStudies()).begin())->beginObj;
68         //e1->SetPrintLevel(2);
69         //aff(deb,fin,1); 
70         std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name   
71         itPatient ++;    
72     }    
73
74    cout << std::endl << std::endl  
75         << " = Liste des PATIENT/STUDY ==========================================" 
76         << std::endl<< std::endl;       
77  
78     itPatient = e1->GetPatients().begin();      
79     while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
80         std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
81         lStudy::iterator itStudy = ((*itPatient)->GetStudies()).begin();        
82         while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient  
83            std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Stdy Description 
84                 
85            
86            ++itStudy;           
87         }  
88         itPatient ++;    
89     }    
90
91    cout << std::endl << std::endl  
92         << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
93         << std::endl<< std::endl;       
94  
95     itPatient = e1->GetPatients().begin();      
96     while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
97         std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
98         lStudy::iterator itStudy = ((*itPatient)->GetStudies()).begin();        
99         while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient  
100            std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description 
101            lSerie::iterator itSerie = ((*itStudy)->GetSeries()).begin();
102            while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study           
103            std::cout << "--- ---  "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description           
104            ++itSerie;   
105            }                       
106            ++itStudy;           
107         }  
108         itPatient ++;    
109     }    
110  
111    cout << std::endl << std::endl  
112         << " = Contenu Complet du DICOMDIR ==========================================" 
113         << std::endl<< std::endl;       
114    
115         
116     itPatient = e1->GetPatients().begin();      
117     while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
118         cout << " = PATIENT ==========================================" << std::endl;   
119         deb = (*itPatient)->beginObj;   
120         fin =  (*((*itPatient)->GetStudies()).begin())->beginObj;
121         e1->SetPrintLevel(2);
122         aff(deb,fin,1);
123         
124         lStudy::iterator itStudy = ((*itPatient)->GetStudies()).begin();        
125         while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient  
126            std::cout << " ==== STUDY ==========================================" <<std::endl;              
127            deb = (*itStudy)->beginObj;  
128            fin = (*((*itStudy)->GetSeries()).begin())->beginObj;
129            //e1->SetPrintLevel(2);
130            aff(deb,fin,1);                                      
131         
132            lSerie::iterator itSerie = ((*itStudy)->GetSeries()).begin();
133            while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study           
134               cout << " ======= SERIES ==========================================" << std::endl;              
135               deb = (*itSerie)->beginObj;       
136               fin = (*((*itSerie)->GetImages()).begin())->beginObj;
137               //e1->SetPrintLevel(2);
138               aff(deb,fin,1);         
139                               
140               lImage::iterator itImage = ((*itSerie)->GetImages()).begin();
141               while (itImage != (*itSerie)->GetImages().end() ) {  // on degouline les IMAGE de cette serie 
142               
143                  cout << " ========== IMAGE ==========================================" << std::endl;   
144                  std::cout << "--- --- --- File Name: "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // Referenced File 
145                           
146               ++itImage;
147               }                       
148               ++itSerie;   
149            }    
150            ++itStudy;   
151          }                         
152         itPatient ++;    
153     }
154     
155     delete e1;
156 }