]> Creatis software - gdcm.git/blob - Example/AnonymizeNoLoad.cxx
Begin of kosherization of Example
[gdcm.git] / Example / AnonymizeNoLoad.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: AnonymizeNoLoad.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/07 17:31:53 $
7   Version:   $Revision: 1.3 $
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 "gdcmFile.h"
19 #include "gdcmFileHelper.h"
20 #include "gdcmCommon.h"
21 #include "gdcmDebug.h"
22
23 #include "gdcmArgMgr.h"
24
25 #include <iostream>
26
27 int main(int argc, char *argv[])
28 {
29    START_USAGE(usage)
30    " \n AnonymizeNoLoad :\n",
31    " Anonymize a gdcm-readable Dicom image even if pixels aren't gdcm readable",
32    "          Warning : Warning : the image is overwritten",
33    "                    to preserve image integrity, use a copy.",
34    " usage: AnonymizeNoLoad filein=inputFileName fileout=[debug] ",
35    "        debug    : user wants to run the program in 'debug mode' ",
36    FINISH_USAGE
37
38    // ----- Initialize Arguments Manager ------   
39    gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
40   
41    if (am->ArgMgrDefined("usage")) 
42    {
43       am->ArgMgrUsage(usage); // Display 'usage'
44       delete am;
45       return 0;
46    }
47
48    if (am->ArgMgrDefined("debug"))
49       gdcm::Debug::DebugOn();
50
51    char *fileName = am->ArgMgrWantString("filein",usage);
52
53    int loadMode;
54    if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
55        loadMode = NO_SEQ | NO_SHADOW;  
56    else if ( am->ArgMgrDefined("noshadow") )
57       loadMode = NO_SHADOW;
58    else if ( am->ArgMgrDefined("noseq") )
59       loadMode = NO_SEQ;
60    else
61       loadMode = 0;
62
63    delete am;  // we don't need Argument Manager any longer
64
65    // ============================================================
66    //   Parse the input file.
67    // ============================================================
68
69    gdcm::File *f;
70    f = new gdcm::File( );
71    f->SetLoadMode(loadMode);
72    f->SetFileName( fileName );
73    bool res = f->Load();
74
75    // gdcm::File::IsReadable() is no usable here, because we deal with
76    // any kind of gdcm::Readable *document*
77    // not only gdcm::File (as opposed to gdcm::DicomDir)
78    if ( !res ) 
79    {
80        std::cout <<std::endl
81            << "Sorry, " << fileName <<"  not a gdcm-readable "
82            << "DICOM / ACR Document"
83            << std::endl;
84         delete f;
85         return 1;
86    }
87    std::cout << fileName << " is readable " << std::endl;
88
89    // ============================================================
90    //   No need to load the pixels in memory.
91    //   File will be overwritten
92    // ============================================================
93
94
95    // ============================================================
96    //  Choose the fields to anonymize.
97    // ============================================================
98    // Institution name 
99    f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); 
100    // Patient's name 
101    f->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" );   
102    // Patient's ID
103    f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
104    // Patient's Birthdate
105    f->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" );
106    // Patient's Adress
107    f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" );
108    // Patient's Mother's Birth Name
109    f->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" );   
110    // Study Instance UID
111    f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" );
112    // Telephone
113    f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
114
115   // Aware use will add new fields here
116
117    // ============================================================
118    //   Overwrite the file
119    // ============================================================
120
121    std::cout <<"Let's AnonymizeNoLoad " << std::endl;;
122
123    // The gdcm::File remains untouched in memory
124
125    f->AnonymizeNoLoad();
126
127    // No need to write the File : modif were done on disc !
128    // File was overwritten ...
129
130    std::cout <<"End AnonymizeNoLoad" << std::endl;
131
132    // ============================================================
133    //   Remove the Anonymize list
134    // ============================================================  
135    f->ClearAnonymizeList();
136     
137    delete f;
138    return 0;
139 }
140