1 /*=========================================================================
4 Module: $RCSfile: TestBuildUpDicomDir.cxx,v $
6 Date: $Date: 2005/04/19 10:03:22 $
7 Version: $Revision: 1.2 $
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.
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.
17 =========================================================================*/
18 #include "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDicomDirStudy.h"
22 #include "gdcmDicomDirSerie.h"
23 #include "gdcmDicomDirImage.h"
24 #include "gdcmDirList.h"
25 #include "gdcmDebug.h"
28 // ===============================================================
31 * \brief Builds up ex-nihilo a DICOMDIR file
32 * adding Patient, Study, Serie, Image descriptions
33 * to an empty gdcmDicomDir occurence
34 * and writes a file named NewDICOMDIR.
36 int TestBuildUpDicomDir(int argc, char *argv[])
40 std::cerr << "Usage: " << argv[0] << " dummy ";
43 gdcm::DicomDir *dcmdir;
46 dcmdir = new gdcm::DicomDir();
48 gdcm::DicomDirPatient *p1;
49 // --- Forget these 4 lines :
50 // just to improve test coverage.
51 p1=dcmdir->GetFirstPatient();
53 std::cout << "BEFORE any Patient creation, a DicomDir has no Patient. Pffff"
59 p1 = dcmdir->NewPatient();
60 p1->SetValEntry("patientONE",0x0010, 0x0010);
61 // fill here other patient characteristics
63 gdcm::DicomDirStudy *s11;
64 // --- Forget these 4 lines :
65 // just to improve test coverage.
66 s11=p1->GetFirstStudy();
68 std::cout << "BEFORE any Study creation, a Patient has no Study. Pffff"
72 // Let's create and add a Study for this Patient
74 s11->SetValEntry("StudyDescrOne.One_",0x0008, 0x1030);
75 // we know entry (0008,1060) is not yet created
76 s11->InsertValEntry("Dr Mabuse", 0x0008, 0x1060);
77 // fill here other Study characteristics
79 gdcm::DicomDirStudy *s12 = p1->NewStudy();
80 s12->SetValEntry("StudyDescrOne.Two",0x0008, 0x1030);
81 s12->InsertValEntry("Dr Zorglub", 0x0008, 0x1060);
82 // fill here other Study characteristics
84 gdcm::DicomDirStudy *s13 = p1->NewStudy();
85 s13->SetValEntry("StudyDescrOne.Tree",0x0008, 0x1030);
86 s13->InsertValEntry("Dr Follamour", 0x0008, 0x1060);
87 // fill here other Study characteristics
89 gdcm::DicomDirSerie *s111;
90 // --- Forget these 4 lines :
91 // just to improve test coverage.
92 s111=s11->GetFirstSerie();
94 std::cout << "BEFORE any Serie creation, a Study has no Serie. Pffff"
98 // Let's create and add a Serie for this Study
99 s111 = s11->NewSerie();
100 s111->SetValEntry("01-01-111", 0x0008, 0x0021);
101 // fill here other Serie characteristics
103 gdcm::DicomDirImage *s1111;
105 // --- Forget these 4 lines :
106 // just to improve test coverage.
107 s1111=s111->GetFirstImage();
109 std::cout << "BEFORE any Image creation, a Serie has no Image. Pffff"
113 // Let's create and add a Image for this Serie
114 s1111 = s111->NewImage();
115 s1111->SetValEntry("imageFileName1111",0x0004,0x1500);
117 gdcm::DicomDirImage *s1112 = s111->NewImage();
118 s1112->SetValEntry("imageFileName1112",0x0004,0x1500);
120 // Create patient TWO
121 // ------------------
122 gdcm::DicomDirPatient *p2 = dcmdir->NewPatient();
123 p2->SetValEntry("patientTWO",0x0010, 0x0010);
124 // fill here other patient characteristics
126 gdcm::DicomDirStudy *s21 = p2->NewStudy();
127 s21->SetValEntry("StudyDescrTwo.One",0x0008, 0x1030);
128 // fill here other Study characteristics
130 gdcm::DicomDirSerie *s211 = s21->NewSerie();
131 s111->SetValEntry("01-01-211", 0x0008, 0x0021);
132 // fill here other Serie characteristics
134 gdcm::DicomDirImage *s2111 = s211->NewImage();
135 s2111->SetValEntry("imageFileName2111",0x0004,0x1500);
136 // fill here other Image characteristics
138 gdcm::DicomDirImage *s2112 = s211->NewImage();
139 s2112->SetValEntry("imageFileName1122",0x0004,0x1500);
140 // fill here other Image characteristics
142 // Create patient TREE
143 // -------------------
144 gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
145 p3->SetValEntry("patientTHREE",0x0010, 0x0010);
146 // fill here other Patient characteristics
148 // Add a new Serie/Image for a Patient's Study created a long time ago
149 // -------------------------------------------------------------------
150 gdcm::DicomDirSerie *s131 = s13->NewSerie();
151 s111->SetValEntry("01-01-131", 0x0008, 0x0021);
152 // fill here other Serie characteristics
154 gdcm::DicomDirImage *s1311 = s131->NewImage();
155 s1311->SetValEntry("imageFileName1311",0x0004,0x1500);
156 // fill here other Image characteristics
159 std::cout << "Test/BuildUpDicomDir: Test Print of patients\n";
161 std::cout << "Test/BuildUpDicomDir: -------------------\n";
163 std::cout << "Test/BuildUpDicomDir: -------------------\n";
165 std::cout << "Test/BuildUpDicomDir: Test Print of patients ended\n";
167 if( !dcmdir->IsReadable() )
169 std::cout<<" Created DicomDir "
170 <<" is not readable"<<std::endl
171 <<" ...Failed"<<std::endl;
178 // Print the 'in memory' built up DicomDir
179 std::cout << "Test/BuildUpDicomDir: Print all of the DicomDir" << std::endl;
180 dcmdir->SetPrintLevel(-1);
184 dcmdir->WriteDicomDir("NewDICOMDIR");
187 // Read the newly written DicomDir
188 gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
189 if( !newDicomDir->IsReadable() )
191 std::cout<<" Written DicomDir 'NewDICOMDIR'"
192 <<" is not readable"<<std::endl
193 <<" ...Failed"<<std::endl;
198 // Check some value we are sure
199 p1 = newDicomDir->GetFirstPatient();
200 p2 = newDicomDir->GetNextPatient();
201 p3 = newDicomDir->GetNextPatient();
203 if (!p1 || !p2 || !p3)
205 std::cout << "A patient is missing in written DicomDir"
211 std::cout <<std::endl
212 << "----------Final Check ---------------------"
215 bool errorFound = false;
216 std::string valueStuff;
217 for (;;) // exit on 'break'
219 if ( p1->GetEntryValue(0x0010, 0x0010) != "patientONE" )
221 std::cout << "0x0010,0x0010 ["
222 << p1->GetEntryValue(0x0010, 0x0010)
227 std::cout << "Patient : ["
228 << p1->GetEntryValue(0x0010, 0x0010)
231 if ( !(s11 = p1->GetFirstStudy()) )
233 std::cout << "missing first Study Patient One" << std::endl;
237 valueStuff = s11->GetEntryValue(0x0008, 0x1030);
238 if ( valueStuff.find("StudyDescrOne.One_") >= valueStuff.length() )
240 std::cout << "1 : 0x0008,0x1030 ["
246 std::cout << "Study : ["
250 valueStuff = s11->GetEntryValue(0x0008, 0x1060);
251 if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Mabuse") )
253 std::cout << "2 : 0x0008,0x1060 ["
254 << s11->GetEntryValue(0x0008,0x1060)
259 std::cout << "Pysician : ["
262 if ( (s12 = p1->GetNextStudy()) == 0 )
267 if ( gdcm::Util::DicomStringEqual(s12->GetEntryValue(0x0008,
268 0x1030),"StudyDescrOne.Two " ))
270 std::cout << "3 0x0008,0x1030 ["
271 << s12->GetEntryValue(0x0008,0x1030)
276 std::cout << "Study Descr : ["
277 << s12->GetEntryValue(0x0008,0x1030)
280 if ( gdcm::Util::DicomStringEqual(s12->GetEntryValue(0x0008,
281 0x1060),"Dr Zorglub " ))
283 std::cout << "4 0x0008,0x1060 ["
284 << s12->GetEntryValue(0x0008,0x1060)
289 std::cout << "Pysician : ["
290 << s12->GetEntryValue(0x0008,0x1060)
293 if ( (s13 = p1->GetNextStudy()) == 0 )
295 std::cout << "Study StudyDescrOne.Tree missing" << std::endl;
298 if ( s13->GetEntryValue(0x0008, 0x1030) != "StudyDescrOne.Tree" )
303 std::cout << "Study : ["
307 valueStuff = s13->GetEntryValue(0x0008, 0x1060);
308 if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Follamour") )
310 std::cout << "5 0x0008,0x1060 ["
316 std::cout << "Pysician : ["
320 if ((s111 = s11->GetFirstSerie()) == 0 )
322 std::cout << "Serie 01-01-111 missing" << std::endl;
327 valueStuff = s111->GetEntryValue(0x0008, 0x0021);
328 if (!gdcm::Util::DicomStringEqual(valueStuff, "01-01-131") )
330 std::cout << "6 0x0008,0x0021 ["
336 std::cout << "Serie : ["
340 if ( (s1111 = s111->GetFirstImage()) == 0 )
342 std::cout << "missing image S1111" << std::endl;
347 if ( s1111->GetEntryValue(0x0004,0x1500) != "imageFileName1111 " )
353 if ( (s1112 = s111->GetNextImage()) == 0 )
355 std::cout << "missing image S1112" << std::endl;
360 if ( s1112->GetEntryValue(0x0004,0x1500) != "imageFileName1112 " )
366 break; // No error found. Stop looping
372 std::cout << "MissWritting / MissReading " << std::endl;
373 std::cout<<std::flush;
377 std::cout<<std::flush;