X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FAnonymizeMultiPatient.cxx;h=3008aecaaa0b3a84344e78db327c5e544e28abd3;hb=8d0468bd872660b30ce957dd00004ea205a2b135;hp=82aae27d1e0df98b56f0f6100fe68ee0df749951;hpb=61131cfa4902c3558c30ccc07b007fe43ed0a47f;p=gdcm.git diff --git a/Example/AnonymizeMultiPatient.cxx b/Example/AnonymizeMultiPatient.cxx index 82aae27d..3008aeca 100755 --- a/Example/AnonymizeMultiPatient.cxx +++ b/Example/AnonymizeMultiPatient.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: AnonymizeMultiPatient.cxx,v $ Language: C++ - Date: $Date: 2006/05/31 16:16:04 $ - Version: $Revision: 1.2 $ + Date: $Date: 2007/11/13 11:49:09 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -44,11 +44,13 @@ int main(int argc, char *argv[]) START_USAGE(usage) " \n AnonymizeMultiPatient :\n ", " AnonymizeMultiPatient a full gdcm-readable Dicom image ", + " optionnaly, creates the DICOMDIR ", " Warning : the image is OVERWRITTEN ", " to preserve image integrity, use a copy. ", - " usage: AnonymizeMultiPatient dirin=inputDirectoryName ", + " usage: AnonymizeMultiPatient dirin=inputDirectoryName dicomdir ", " listOfElementsToRubOut : group-elem,g2-e2,... (in hexa, no space) ", " of extra Elements to rub out ", + " dicomdir : user wants to generate a DICOMDIR ", " noshadowseq: user doesn't want to load Private Sequences ", " noshadow : user doesn't want to load Private groups (odd number) ", " noseq : user doesn't want to load Sequences ", @@ -59,7 +61,7 @@ int main(int argc, char *argv[]) // ----- Initialize Arguments Manager ------ - gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); if (argc == 1 || am->ArgMgrDefined("usage")) { @@ -75,22 +77,23 @@ int main(int argc, char *argv[]) } std::string dirName = name; - - bool verbose = am->ArgMgrDefined("verbose"); + + bool verbose = ( 0 != am->ArgMgrDefined("verbose") ); + bool dicomdir = ( 0 != am->ArgMgrDefined("dicomdir") ); if (am->ArgMgrDefined("debug")) - gdcm::Debug::DebugOn(); + GDCM_NAME_SPACE::Debug::DebugOn(); - int loadMode = gdcm::LD_ALL; + int loadMode = GDCM_NAME_SPACE::LD_ALL; if ( am->ArgMgrDefined("noshadowseq") ) - loadMode |= gdcm::LD_NOSHADOWSEQ; + loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ; else { if ( am->ArgMgrDefined("noshadow") ) - loadMode |= gdcm::LD_NOSHADOW; + loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW; if ( am->ArgMgrDefined("noseq") ) - loadMode |= gdcm::LD_NOSEQ; + loadMode |= GDCM_NAME_SPACE::LD_NOSEQ; } @@ -113,11 +116,11 @@ int main(int argc, char *argv[]) // ----- Begin Processing ----- - gdcm::DicomDir *dcmdir; + GDCM_NAME_SPACE::DicomDir *dcmdir; // we ask for Directory parsing - dcmdir = gdcm::DicomDir::New( ); + dcmdir = GDCM_NAME_SPACE::DicomDir::New( ); dcmdir->SetLoadMode(loadMode); dcmdir->SetDirectoryName(dirName); dcmdir->Load(); @@ -135,25 +138,31 @@ int main(int argc, char *argv[]) return 1; } - gdcm::DicomDirPatient *pa; - gdcm::DicomDirStudy *st; - gdcm::DicomDirSerie *se; - gdcm::DicomDirVisit *vs; - gdcm::DicomDirImage *im; + GDCM_NAME_SPACE::DicomDirPatient *pa; + GDCM_NAME_SPACE::DicomDirStudy *st; + GDCM_NAME_SPACE::DicomDirSerie *se; + GDCM_NAME_SPACE::DicomDirImage *im; - std::string codedName; + std::string codedName; + std::string codedID; std::string fullFileName; std::string patName; - - gdcm::File *f; + std::string patID; + + GDCM_NAME_SPACE::File *f; pa = dcmdir->GetFirstPatient(); while ( pa ) { // on degouline les PATIENT du DICOMDIR patName = pa->GetEntryString(0x0010, 0x0010); - codedName = "g^" + gdcm::Util::ConvertToMD5(patName); - if (verbose) - std::cout << patName << " --> " << codedName << std::endl; + codedName = "g^" + GDCM_NAME_SPACE::Util::ConvertToMD5(patName); + patID = pa->GetEntryString(0x0010, 0x0020); + codedID = GDCM_NAME_SPACE::Util::ConvertToMD5(patID); + + if (verbose) { + std::cout << "[" << patName << "] --> [" << codedName << "]" << std::endl; + std::cout << "[" << patID << "] --> [" << codedID << "]" << std::endl; + } st = pa->GetFirstStudy(); while ( st ) { // on degouline les STUDY de ce patient @@ -164,12 +173,12 @@ int main(int argc, char *argv[]) while ( im ) { // on degouline les Images de cette serie fullFileName = dirName; - fullFileName += gdcm::GDCM_FILESEPARATOR; + fullFileName += GDCM_NAME_SPACE::GDCM_FILESEPARATOR; fullFileName += im->GetEntryString(0x0004, 0x1500); if (verbose) std::cout << "FileName " << fullFileName << std::endl; - f = gdcm::File::New( ); + f = GDCM_NAME_SPACE::File::New( ); f->SetLoadMode(loadMode); f->SetFileName( fullFileName ); if ( !f->Load() ) @@ -189,7 +198,8 @@ int main(int argc, char *argv[]) f->AddAnonymizeElement( 0x0010, 0x0010, codedName ); // Patient's ID - f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + //f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + f->AddAnonymizeElement( 0x0010, 0x0020,codedID ); // Patient's Birthdate f->AddAnonymizeElement( 0x0010, 0x0030,"11111111" ); // Patient's Adress @@ -215,7 +225,7 @@ int main(int argc, char *argv[]) // // Overwrite the file // - // The gdcm::File remains untouched in memory + // The GDCM_NAME_SPACE::File remains untouched in memory f->AnonymizeNoLoad(); @@ -231,7 +241,18 @@ int main(int argc, char *argv[]) pa = dcmdir->GetNextPatient(); } - dcmdir->Delete(); + dcmdir->Delete(); + + if (dicomdir) + { + std::cout << "DICOMDIR creation in progress ..." << std::endl; + dcmdir = GDCM_NAME_SPACE::DicomDir::New( ); + dcmdir->SetLoadMode(loadMode); + dcmdir->SetDirectoryName(dirName); + dcmdir->Load(); + dcmdir->Write("DICOMDIR"); + } + return 0; }