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