]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
ENH: Adding automatic testing
[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
20 int testDicomDir(int argc, char* argv[])
21 {  
22    gdcmDicomDir *e1;
23    ListTag::iterator deb , fin;
24    
25    ListDicomDirPatient::iterator  itPatient;
26    ListDicomDirStudy::iterator    itStudy;
27    ListDicomDirSerie::iterator    itSerie;
28    ListDicomDirImage::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->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().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->GetDicomDirPatients().begin();       
59    while ( itPatient != e1->GetDicomDirPatients().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->GetDicomDirPatients().begin();       
71    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
72       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
73       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
74       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
75          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
76          ++itStudy;             
77       }
78       itPatient ++;    
79    }   
80  */
81  
82    std::cout << std::endl << std::endl  
83              << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
84              << std::endl<< std::endl;  
85  
86    itPatient = e1->GetDicomDirPatients().begin();       
87    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
88        // Patient's Name, Patient ID 
89       std::cout << "Pat.Name:[" << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) <<"]";
90       std::cout << " Pat.ID:[";
91       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0020) << "]" << std::endl;
92       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
93       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
94          std::cout << "--- Stud.descr:["    << (*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)->GetDicomDirSeries()).begin();
98          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study     
99             std::cout << "--- --- Ser.Descr:["<< (*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) << "]";   // Modality
102             std::cout << std::endl;         
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->GetDicomDirPatients().begin();       
117    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
118       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name
119       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
120       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
121          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
122          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
123          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study     
124             std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description
125             itImage = ((*itSerie)->GetDicomDirImages()).begin();
126             while (itImage != (*itSerie)->GetDicomDirImages().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    std::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 }