1 /*=========================================================================
4 Module: $RCSfile: AnonymizeMultiPatient.cxx,v $
6 Date: $Date: 2006/05/31 16:16:04 $
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 "gdcmDicomDirVisit.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
25 #include "gdcmDirList.h"
26 #include "gdcmDebug.h"
29 #include "gdcmFileHelper.h"
31 #include "gdcmArgMgr.h"
36 * \brief Explores recursively the given directory
37 * orders the gdcm-readable found Files
38 * according their Patient/Study/Serie/Image characteristics
39 * and anomymizes (NoLoad) them, creates a different name for each Patient.
42 int main(int argc, char *argv[])
45 " \n AnonymizeMultiPatient :\n ",
46 " AnonymizeMultiPatient a full gdcm-readable Dicom image ",
47 " Warning : the image is OVERWRITTEN ",
48 " to preserve image integrity, use a copy. ",
49 " usage: AnonymizeMultiPatient dirin=inputDirectoryName ",
50 " listOfElementsToRubOut : group-elem,g2-e2,... (in hexa, no space) ",
51 " of extra Elements to rub out ",
52 " noshadowseq: user doesn't want to load Private Sequences ",
53 " noshadow : user doesn't want to load Private groups (odd number) ",
54 " noseq : user doesn't want to load Sequences ",
55 " verbose : user wants to run the program in 'verbose mode' ",
56 " debug : user wants to run the program in 'debug mode' ",
61 // ----- Initialize Arguments Manager ------
62 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
64 if (argc == 1 || am->ArgMgrDefined("usage"))
66 am->ArgMgrUsage(usage); // Display 'usage'
70 const char * name = am->ArgMgrGetString("dirin");
77 std::string dirName = name;
79 bool verbose = am->ArgMgrDefined("verbose");
81 if (am->ArgMgrDefined("debug"))
82 gdcm::Debug::DebugOn();
84 int loadMode = gdcm::LD_ALL;
86 if ( am->ArgMgrDefined("noshadowseq") )
87 loadMode |= gdcm::LD_NOSHADOWSEQ;
90 if ( am->ArgMgrDefined("noshadow") )
91 loadMode |= gdcm::LD_NOSHADOW;
92 if ( am->ArgMgrDefined("noseq") )
93 loadMode |= gdcm::LD_NOSEQ;
98 uint16_t *elemsToRubOut = am->ArgMgrGetXInt16Enum("rubout", &rubOutNb);
100 // ----------- if unused Param we give up
101 if ( am->ArgMgrPrintUnusedLabels() )
103 am->ArgMgrUsage(usage);
108 delete am; // we don't need Argument Manager any longer
111 // ----------------------------------------------------------
114 // ----- Begin Processing -----
116 gdcm::DicomDir *dcmdir;
118 // we ask for Directory parsing
120 dcmdir = gdcm::DicomDir::New( );
121 dcmdir->SetLoadMode(loadMode);
122 dcmdir->SetDirectoryName(dirName);
126 std::cout << "======================= End Parsing Directory" << std::endl;
128 // ----- Check the result
130 if ( !dcmdir->GetFirstPatient() )
132 std::cout << "No patient found (?!?). Exiting."
138 gdcm::DicomDirPatient *pa;
139 gdcm::DicomDirStudy *st;
140 gdcm::DicomDirSerie *se;
141 gdcm::DicomDirVisit *vs;
142 gdcm::DicomDirImage *im;
144 std::string codedName;
145 std::string fullFileName;
150 pa = dcmdir->GetFirstPatient();
152 { // on degouline les PATIENT du DICOMDIR
153 patName = pa->GetEntryString(0x0010, 0x0010);
154 codedName = "g^" + gdcm::Util::ConvertToMD5(patName);
156 std::cout << patName << " --> " << codedName << std::endl;
157 st = pa->GetFirstStudy();
159 { // on degouline les STUDY de ce patient
160 se = st->GetFirstSerie();
162 { // on degouline les SERIES de cette study
163 im = se->GetFirstImage();
165 { // on degouline les Images de cette serie
166 fullFileName = dirName;
167 fullFileName += gdcm::GDCM_FILESEPARATOR;
168 fullFileName += im->GetEntryString(0x0004, 0x1500);
170 std::cout << "FileName " << fullFileName << std::endl;
172 f = gdcm::File::New( );
173 f->SetLoadMode(loadMode);
174 f->SetFileName( fullFileName );
176 std::cout << "Load failed for [" << fullFileName << "]" << std::endl;
179 std::cout << "Load successed for [" << fullFileName << "]" << std::endl;
182 // Choose the fields to anonymize.
186 f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" );
189 f->AddAnonymizeElement( 0x0010, 0x0010, codedName );
192 f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
193 // Patient's Birthdate
194 f->AddAnonymizeElement( 0x0010, 0x0030,"11111111" );
196 f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
197 // Patient's Mother's Birth Name
198 f->AddAnonymizeElement( 0x0010, 0x1060,"g^Vampirella" );
200 // Study Instance UID
201 // we may not brutaly overwrite it
202 //f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
205 f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
207 // deal with user defined Elements set
209 for (int ri=0; ri<rubOutNb; ri++)
211 f->AddAnonymizeElement((uint32_t)elemsToRubOut[2*ri],
212 (uint32_t)elemsToRubOut[2*ri+1],"*" );
216 // Overwrite the file
218 // The gdcm::File remains untouched in memory
220 f->AnonymizeNoLoad();
222 f->ClearAnonymizeList();
225 im = se->GetNextImage();
227 se = st->GetNextSerie();
229 st = pa->GetNextStudy();
231 pa = dcmdir->GetNextPatient();