]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
* ENH add self defined param 'new' to PrintHeader to 'show' the SeQuence
[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 += GDCM_DATA_ROOT;
36       file += "/DICOMDIR";
37     }
38
39    e1 = new gdcmDicomDir(file.c_str());
40    if (argc > 2) {
41       int level = atoi(argv[2]);   
42       e1->SetPrintLevel(level);
43    }
44
45    if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() )
46    {
47       std::cout<<"Empty list"<<std::endl;
48       return(1);
49    }
50
51 // Simple examples of structure exploitation 
52 // DON'T REMOVE neither the folowing code, nor the commented out lines
53
54 /*
55   cout << std::endl << std::endl  
56              << " = Liste des PATIENT ==========================================" 
57              << std::endl<< std::endl;  
58
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       itPatient ++;    
64    }
65 */
66
67 /*        
68    cout << std::endl << std::endl  
69         << " = Liste des PATIENT/STUDY ==========================================" 
70         << std::endl<< std::endl;       
71
72    itPatient = e1->GetDicomDirPatients().begin();       
73    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
74       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
75       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
76       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
77          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
78          ++itStudy;             
79       }
80       itPatient ++;    
81    }   
82  */
83  
84    std::cout << std::endl << std::endl  
85              << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
86              << std::endl<< std::endl;  
87  
88    itPatient = e1->GetDicomDirPatients().begin();       
89    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
90        // Patient's Name, Patient ID 
91       std::cout << "Pat.Name:[" << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) <<"]";
92       std::cout << " Pat.ID:[";
93       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0020) << "]" << std::endl;
94       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
95       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
96          std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << "]";// Study Description 
97          std::cout << " Stud.ID:["<< (*itStudy)->GetEntryByNumber(0x0020, 0x0010);                 // Study ID
98          std::cout << "]" << std::endl;
99          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
100          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study     
101             std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e)<< "]";// Serie Description
102             std::cout << " Ser.nb:[" <<   (*itSerie)->GetEntryByNumber(0x0020, 0x0011);            // Serie number
103             std::cout << "] Mod.:["    <<   (*itSerie)->GetEntryByNumber(0x0008, 0x0060) << "]";   // Modality
104             std::cout << std::endl;         
105             ++itSerie;   
106          }
107          ++itStudy;             
108       }
109       itPatient ++;    
110    } 
111    
112     
113  /*
114    cout << std::endl << std::endl  
115              << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
116              << std::endl<< std::endl;
117  
118    itPatient = e1->GetDicomDirPatients().begin();       
119    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
120       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name
121       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();   
122       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient    
123          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
124          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
125          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study     
126             std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description
127             itImage = ((*itSerie)->GetDicomDirImages()).begin();
128             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study          
129                std::cout << "--- --- --- "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // File name
130                ++itImage;   
131             }
132             ++itSerie;   
133          }
134          ++itStudy;             
135       }  
136       itPatient ++;    
137    }   
138  */  
139
140    std::cout << std::endl << std::endl  
141         << " = Contenu Complet du DICOMDIR ==========================================" 
142         << std::endl<< std::endl;       
143    e1->Print();
144    
145    std::cout<<std::flush;
146    delete e1;
147
148    return(0);
149 }