]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
executables now compile with the new version
[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 #include <string>
14 #include <iostream>
15
16 #define  ostringstream ostrstream
17 //extern "C"
18
19 using namespace std;
20
21 int main(int argc, char* argv[])
22 {  
23    gdcmDicomDir *e1;
24    ListTag::iterator deb , fin;
25    
26    ListDicomDirPatient::iterator  itPatient;
27    ListDicomDirStudy::iterator    itStudy;
28    ListDicomDirSerie::iterator    itSerie;
29    ListDicomDirImage::iterator    itImage;
30    TSKey v;
31     
32    std::string file; 
33    if (argc > 1) 
34       file = argv[1];    
35    else 
36       file = "../gdcmData/DICOMDIR";
37       
38    e1 = new gdcmDicomDir(file.c_str());
39         if (argc > 2) {
40            int level = atoi(argv[2]);   
41            e1->SetPrintLevel(level);
42         }
43
44    if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() )
45    {
46       std::cout<<"Empty list"<<std::endl;
47       return(1);
48    }
49
50 // Exemples exploitation de la structure
51 // DON'T REMOVE neither the folowing code, nor the commented out lines
52
53 /*
54   cout << std::endl << std::endl  
55              << " = Liste des PATIENT ==========================================" 
56              << std::endl<< std::endl;  
57
58
59    itPatient = e1->GetDicomDirPatients().begin();       
60    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
61       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name   
62       itPatient ++;    
63    }
64 */
65
66 /*        
67    cout << std::endl << std::endl  
68         << " = Liste des PATIENT/STUDY ==========================================" 
69         << std::endl<< std::endl;       
70
71    itPatient = e1->GetDicomDirPatients().begin();       
72    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
73       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
74       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
75       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
76          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
77          ++itStudy;             
78       }
79       itPatient ++;    
80    }   
81  */
82  
83    cout << std::endl << std::endl  
84              << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
85              << std::endl<< std::endl;  
86  
87    itPatient = e1->GetDicomDirPatients().begin();       
88    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
89        // Patient's Name, Patient ID 
90       std::cout << "Pat.Name:[" << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) <<"]";
91       std::cout << " Pat.ID:[";
92       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0020) << "]" << std::endl;
93       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
94       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
95          std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << "]";// Study Description 
96          std::cout << " Stud.ID:["<< (*itStudy)->GetEntryByNumber(0x0020, 0x0010);                 // Study ID
97          std::cout << "]" << std::endl;
98          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
99          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study     
100             std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e)<< "]";// Serie Description
101             std::cout << " Ser.nb:[" <<   (*itSerie)->GetEntryByNumber(0x0020, 0x0011);            // Serie number
102             std::cout << "] Mod.:["    <<   (*itSerie)->GetEntryByNumber(0x0008, 0x0060) << "]";   // Modality
103             std::cout << std::endl;         
104             ++itSerie;   
105          }
106          ++itStudy;             
107       }
108       itPatient ++;    
109    } 
110    
111     
112  /*
113    cout << std::endl << std::endl  
114              << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
115              << std::endl<< std::endl;
116  
117    itPatient = e1->GetDicomDirPatients().begin();       
118    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
119       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name
120       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
121       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
122          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
123          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
124          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study     
125             std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description
126             itImage = ((*itSerie)->GetDicomDirImages()).begin();
127             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study          
128                std::cout << "--- --- --- "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // File name
129                ++itImage;   
130             }
131             ++itSerie;   
132          }
133          ++itStudy;             
134       }  
135       itPatient ++;    
136    }   
137  */  
138
139    cout << std::endl << std::endl  
140         << " = Contenu Complet du DICOMDIR ==========================================" 
141         << std::endl<< std::endl;       
142    e1->Print();
143    
144    std::cout<<std::flush;
145    delete e1;
146
147    return(0);
148 }