1 /*=========================================================================
4 Module: $RCSfile: TestBuildUpDicomDir.cxx,v $
6 Date: $Date: 2005/10/25 14:52:30 $
7 Version: $Revision: 1.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.
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 " << std::endl;
43 bool errorFound = false;
44 gdcm::DicomDir *dcmdir;
47 dcmdir = gdcm::DicomDir::New();
49 gdcm::DicomDirPatient *p1;
50 // --- Forget these 4 lines :
51 // just to improve test coverage.
52 p1=dcmdir->GetFirstPatient();
54 std::cout << "BEFORE any Patient creation, a DicomDir has no Patient. Pffff"
60 p1 = dcmdir->NewPatient();
61 p1->SetEntryString("patientONE",0x0010, 0x0010);
62 // fill here other patient characteristics
64 gdcm::DicomDirStudy *s11;
65 // --- Forget these 4 lines :
66 // just to improve test coverage.
67 s11=p1->GetFirstStudy();
69 std::cout << "BEFORE any Study creation, a Patient has no Study. Pffff"
73 // Let's create and add a Study for this Patient
75 s11->SetEntryString("StudyDescrOne.One_",0x0008, 0x1030);
76 // we know entry (0008,1060) is not yet created
77 s11->InsertEntryString("Dr Mabuse", 0x0008, 0x1060);
78 // fill here other Study characteristics
80 gdcm::DicomDirStudy *s12 = p1->NewStudy();
81 s12->SetEntryString("StudyDescrOne.Two",0x0008, 0x1030);
82 s12->InsertEntryString("Dr Zorglub", 0x0008, 0x1060);
83 // fill here other Study characteristics
85 gdcm::DicomDirStudy *s13 = p1->NewStudy();
86 s13->SetEntryString("StudyDescrOne.Tree",0x0008, 0x1030);
87 s13->InsertEntryString("Dr Follamour", 0x0008, 0x1060);
88 // fill here other Study characteristics
90 gdcm::DicomDirSerie *s111;
91 // --- Forget these 4 lines :
92 // just to improve test coverage.
93 s111=s11->GetFirstSerie();
95 std::cout << "BEFORE any Serie creation, a Study has no Serie. Pffff"
99 // Let's create and add a Serie for this Study
100 s111 = s11->NewSerie();
101 s111->SetEntryString("01-01-111", 0x0008, 0x0021);
102 // fill here other Serie characteristics
104 gdcm::DicomDirImage *s1111;
106 // --- Forget these 4 lines :
107 // just to improve test coverage.
108 s1111=s111->GetFirstImage();
110 std::cout << "BEFORE any Image creation, a Serie has no Image. Pffff"
114 // Let's create and add a Image for this Serie
115 s1111 = s111->NewImage();
116 s1111->SetEntryString("imageFileName1111",0x0004,0x1500);
118 gdcm::DicomDirImage *s1112 = s111->NewImage();
119 s1112->SetEntryString("imageFileName1112",0x0004,0x1500);
121 // Create patient TWO
122 // ------------------
123 gdcm::DicomDirPatient *p2 = dcmdir->NewPatient();
124 p2->SetEntryString("patientTWO",0x0010, 0x0010);
125 // fill here other patient characteristics
127 gdcm::DicomDirStudy *s21 = p2->NewStudy();
128 s21->SetEntryString("StudyDescrTwo.One",0x0008, 0x1030);
129 // fill here other Study characteristics
131 gdcm::DicomDirSerie *s211 = s21->NewSerie();
132 s111->SetEntryString("01-01-211", 0x0008, 0x0021);
133 // fill here other Serie characteristics
135 gdcm::DicomDirImage *s2111 = s211->NewImage();
136 s2111->SetEntryString("imageFileName2111",0x0004,0x1500);
137 // fill here other Image characteristics
139 gdcm::DicomDirImage *s2112 = s211->NewImage();
140 s2112->SetEntryString("imageFileName1122",0x0004,0x1500);
141 // fill here other Image characteristics
143 // Create patient TREE
144 // -------------------
145 gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
146 p3->SetEntryString("patientTHREE",0x0010, 0x0010);
147 // fill here other Patient characteristics
149 // Add a new Serie/Image for a Patient's Study created a long time ago
150 // -------------------------------------------------------------------
151 gdcm::DicomDirSerie *s131 = s13->NewSerie();
152 s111->SetEntryString("01-01-131", 0x0008, 0x0021);
153 // fill here other Serie characteristics
155 gdcm::DicomDirImage *s1311 = s131->NewImage();
156 s1311->SetEntryString("imageFileName1311",0x0004,0x1500);
157 // fill here other Image characteristics
160 std::cout << "Test/BuildUpDicomDir: Test Print of patients\n";
162 std::cout << "Test/BuildUpDicomDir: -------------------\n";
164 std::cout << "Test/BuildUpDicomDir: -------------------\n";
166 std::cout << "Test/BuildUpDicomDir: Test Print of patients ended\n";
168 if( !dcmdir->IsReadable() )
170 std::cout<<" Created DicomDir "
171 <<" is not readable"<<std::endl
172 <<" ...Failed"<<std::endl;
179 // Print the 'in memory' built up DicomDir
180 std::cout << "Test/BuildUpDicomDir: Print all of the DicomDir" << std::endl;
181 dcmdir->SetPrintLevel(-1);
185 dcmdir->Write("NewDICOMDIR");
189 // Read the newly written DicomDir
190 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
191 newDicomDir->SetFileName("NewDICOMDIR");
192 newDicomDir->Load( );
193 if( !newDicomDir->IsReadable() )
195 std::cout<<" Written DicomDir 'NewDICOMDIR'"
196 <<" is not readable"<<std::endl
197 <<" ...Failed"<<std::endl;
199 newDicomDir->Delete();
202 // Check some value we are sure
203 p1 = newDicomDir->GetFirstPatient();
204 p2 = newDicomDir->GetNextPatient();
205 p3 = newDicomDir->GetNextPatient();
207 if (!p1 || !p2 || !p3)
209 std::cout << "A patient is missing in written DicomDir"
211 newDicomDir->Delete();
215 std::cout <<std::endl
216 << "----------Final Check ---------------------"
219 std::string valueStuff;
220 for (;;) // exit on 'break'
222 if ( p1->GetEntryString(0x0010, 0x0010) != "patientONE" )
224 std::cout << "0x0010,0x0010 ["
225 << p1->GetEntryString(0x0010, 0x0010)
230 std::cout << "Patient : ["
231 << p1->GetEntryString(0x0010, 0x0010)
234 if ( !(s11 = p1->GetFirstStudy()) )
236 std::cout << "missing first Study Patient One" << std::endl;
240 valueStuff = s11->GetEntryString(0x0008, 0x1030);
241 if ( valueStuff.find("StudyDescrOne.One_") >= valueStuff.length() )
243 std::cout << "1 : 0x0008,0x1030 ["
249 std::cout << "Study : ["
253 valueStuff = s11->GetEntryString(0x0008, 0x1060);
254 if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Mabuse") )
256 std::cout << "2 : 0x0008,0x1060 ["
257 << s11->GetEntryString(0x0008,0x1060)
262 std::cout << "Pysician : ["
265 if ( (s12 = p1->GetNextStudy()) == 0 )
270 if ( gdcm::Util::DicomStringEqual(s12->GetEntryString(0x0008,
271 0x1030),"StudyDescrOne.Two " ))
273 std::cout << "3 0x0008,0x1030 ["
274 << s12->GetEntryString(0x0008,0x1030)
279 std::cout << "Study Descr : ["
280 << s12->GetEntryString(0x0008,0x1030)
283 if ( gdcm::Util::DicomStringEqual(s12->GetEntryString(0x0008,
284 0x1060),"Dr Zorglub " ))
286 std::cout << "4 0x0008,0x1060 ["
287 << s12->GetEntryString(0x0008,0x1060)
292 std::cout << "Pysician : ["
293 << s12->GetEntryString(0x0008,0x1060)
296 if ( (s13 = p1->GetNextStudy()) == 0 )
298 std::cout << "Study StudyDescrOne.Tree missing" << std::endl;
301 if ( s13->GetEntryString(0x0008, 0x1030) != "StudyDescrOne.Tree" )
306 std::cout << "Study : ["
310 valueStuff = s13->GetEntryString(0x0008, 0x1060);
311 if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Follamour") )
313 std::cout << "5 0x0008,0x1060 ["
319 std::cout << "Pysician : ["
323 if ((s111 = s11->GetFirstSerie()) == 0 )
325 std::cout << "Serie 01-01-111 missing" << std::endl;
330 valueStuff = s111->GetEntryString(0x0008, 0x0021);
331 if (!gdcm::Util::DicomStringEqual(valueStuff, "01-01-131") )
333 std::cout << "6 0x0008,0x0021 ["
339 std::cout << "Serie : ["
343 if ( (s1111 = s111->GetFirstImage()) == 0 )
345 std::cout << "missing image S1111" << std::endl;
350 if ( (s1112 = s111->GetNextImage()) == 0 )
352 std::cout << "missing image S1112" << std::endl;
357 break; // No error found. Stop looping
362 std::cout << "MissWritting / MissReading " << std::endl;
365 std::cout<<std::flush;
366 newDicomDir->Delete();