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