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