]> Creatis software - gdcm.git/blob - Example/PrintDicomDir.cxx
0fd1386623117d9ff91b35f626c8bd0a4d1b0e61
[gdcm.git] / Example / PrintDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/13 14:20:18 $
7   Version:   $Revision: 1.12 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDocument.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmValEntry.h"
21 #include "gdcmDicomDirPatient.h"
22 #include "gdcmDicomDirStudy.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
25 #include "gdcmTS.h"
26 #include "gdcmDebug.h"
27
28 #include <fstream>
29 #include <iostream>
30
31 int main(int argc, char* argv[])
32 {  
33    gdcm::DicomDir *e1;
34    
35    gdcm::ListDicomDirPatient::const_iterator  itPatient;
36    gdcm::ListDicomDirStudy::const_iterator    itStudy;
37    gdcm::ListDicomDirSerie::const_iterator    itSerie;
38    gdcm::ListDicomDirImage::const_iterator    itImage;
39    gdcm::TSKey v;
40     
41    std::string fileName; 
42    if (argc > 1) 
43       fileName = argv[1];    
44    else 
45    {
46       fileName = GDCM_DATA_ROOT;
47       fileName += "/DICOMDIR";
48    }
49
50    if (argc > 3)
51       gdcm::Debug::SetDebugOn();
52
53    e1 = new gdcm::DicomDir( fileName );
54
55    e1->SetPrintLevel(2);
56    int detailLevel;
57    if (argc > 2)
58       detailLevel = atoi(argv[2]);   
59    else
60       detailLevel = 3;
61
62
63    if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() )
64    {
65       std::cout<<"Empty list"<<std::endl;
66       return(1);
67    }
68
69 // Structure use Examples 
70
71    switch (detailLevel)
72   { 
73   case 1:
74      std::cout << std::endl << std::endl  
75        << " =  PATIENT List ==========================================" 
76        << std::endl<< std::endl;
77
78       itPatient = e1->GetDicomDirPatients().begin();
79       while ( itPatient != e1->GetDicomDirPatients().end() ) // on degouline la liste de PATIENT
80       {
81          std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name   
82          itPatient ++;    
83       }
84       break;
85
86    case 2:    
87       std::cout << std::endl << std::endl  
88         << " = PATIENT/STUDY List =======================================" 
89         << std::endl<< std::endl;
90
91       itPatient = e1->GetDicomDirPatients().begin();
92       while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
93          std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name 
94          itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
95          while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
96             std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
97             ++itStudy;
98          }
99          itPatient ++;    
100       }   
101       break;
102
103    case 3: 
104       std::cout << std::endl << std::endl  
105         << " =  PATIENT/STUDY/SERIE List ==================================" 
106         << std::endl<< std::endl;
107  
108       itPatient = e1->GetDicomDirPatients().begin();
109       while ( itPatient != e1->GetDicomDirPatients().end() )   // on degouline la liste de PATIENT
110       {
111        // Patient's Name, Patient ID 
112          std::cout << "Pat.Name:[" << (*itPatient)->GetEntry(0x0010, 0x0010) <<"]"; // Patient's Name
113          std::cout << " Pat.ID:[";
114          std::cout << (*itPatient)->GetEntry(0x0010, 0x0020) << "]" << std::endl; // Patient ID
115          itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
116          while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
117             std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntry(0x0008, 0x1030) << "]";// Study Description 
118             std::cout << " Stud.ID:["          << (*itStudy)->GetEntry(0x0020, 0x0010);       // Study ID
119             std::cout << "]" << std::endl;
120             itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
121             while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
122                std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntry(0x0008, 0x103e)<< "]";  // Series Description
123                std::cout << " Ser.nb:["         <<  (*itSerie)->GetEntry(0x0020, 0x0011);        // Series number
124                std::cout << "] Mod.:["          <<  (*itSerie)->GetEntry(0x0008, 0x0060) << "]"; // Modality
125               std::cout << std::endl;    
126                ++itSerie;   
127             }
128             ++itStudy;
129          }
130          itPatient ++;    
131       } 
132       break;
133
134    case 4:  
135       std::cout << std::endl << std::endl  
136            << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
137            << std::endl<< std::endl;
138  
139       itPatient = e1->GetDicomDirPatients().begin();
140       while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
141          std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
142          itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
143          while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
144             std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
145             itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
146             while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
147                std::cout << "--- --- "<< (*itSerie)->GetEntry(0x0008, 0x103e) << std::endl; // Serie Description
148                itImage = ((*itSerie)->GetDicomDirImages()).begin();
149                while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study
150                   std::cout << "--- --- --- "<< (*itImage)->GetEntry(0x0004, 0x1500) << std::endl; // File name
151                   ++itImage;   
152                }
153                ++itSerie;   
154            }
155            ++itStudy;
156         }  
157         itPatient ++;    
158       }
159       break;
160
161    case 5:
162       std::cout << std::endl << std::endl  
163            << " = DICOMDIR full content ==========================================" 
164            << std::endl<< std::endl;
165       e1->Print();
166       break;
167
168    }  // end switch
169
170
171
172    if(e1->IsReadable())
173       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
174    else
175       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
176    std::cout<<std::flush;
177    delete e1;
178
179    return(0);
180 }