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