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