using System;
using gdcm;
public class MyWatcher : SimpleSubjectWatcher
{
public MyWatcher(Subject s):base(s,"Override String"){}
protected override void StartFilter() {
System.Console.WriteLine( "This is my start" );
}
protected override void EndFilter(){
System.Console.WriteLine( "This is my end" );
}
protected override void ShowProgress(Subject caller, Event evt){
ProgressEvent pe = ProgressEvent.Cast(evt);
System.Console.WriteLine( "This is my progress: " + pe.GetProgress() );
}
protected override void ShowIteration(){
System.Console.WriteLine( "This is my iteration" );
}
protected override void ShowAnonymization(Subject caller, Event evt){
AnonymizeEvent ae = AnonymizeEvent.Cast(evt);
if( ae != null )
{
Tag t = ae.GetTag();
System.Console.WriteLine( "This is my Anonymization. Processing Tag #" + t.toString() );
}
else
{
System.Console.WriteLine( "This is my Anonymization. Unhandled Event type: " + evt.GetEventName() );
}
}
protected override void ShowAbort(){
System.Console.WriteLine( "This is my abort" );
}
}
public class ClinicalTrialIdentificationWorkflow
{
public static bool ProcessOneFile( gdcm.Anonymizer ano , string filename, string outfilename )
{
Reader reader = new Reader();
reader.SetFileName( filename );
bool ret = reader.Read();
if( !ret )
{
return false;
}
ano.SetFile( reader.GetFile() );
if( !ano.BasicApplicationLevelConfidentialityProfile() )
{
return false;
}
ano.Replace(
new gdcm.Tag(0x0012,0x0010),
"MySponsorName");
ano.Replace(
new gdcm.Tag(0x0012,0x0020),
"MyProtocolID");
ano.Replace(
new gdcm.Tag(0x0012,0x0021),
"MyProtocolName");
ano.Replace(
new gdcm.Tag(0x0012,0x0030),
"MySiteId");
ano.Replace(
new gdcm.Tag(0x0012,0x0031),
"MySiteName");
ano.Replace(
new gdcm.Tag(0x0012,0x0040),
"MySponsorId");
ano.Replace(
new gdcm.Tag(0x0012,0x0050),
"MyTPId");
ano.Replace(
new gdcm.Tag(0x0012,0x0051),
"MyTPDescription");
string subdir = fn.GetPath();
if( !gdcm.PosixEmulation.MakeDirectory( subdir ) )
{
return false;
}
fmi.Remove(
new gdcm.Tag(0x0002,0x0012) );
fmi.Remove(
new gdcm.Tag(0x0002,0x0013) );
fmi.Remove(
new gdcm.Tag(0x0002,0x0016) );
Writer writer = new Writer();
writer.SetFileName( outfilename );
writer.SetFile( ano.GetFile() );
ret = writer.Write();
if( !ret )
{
return false;
}
return true;
}
public static int Main(string[] args)
{
gdcm.FileMetaInformation.SetSourceApplicationEntityTitle( "My ClinicalTrial App" );
string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";
gdcm.UIDGenerator.SetRoot( THERALYS_ORG_ROOT );
System.Console.WriteLine( "Root dir is now: " + gdcm.UIDGenerator.GetRoot() );
if( !global.LoadResourcesFiles() )
{
System.Console.WriteLine( "Could not LoadResourcesFiles" );
return 1;
}
if( args.Length != 2 )
{
System.Console.WriteLine( "Usage:" );
System.Console.WriteLine( "ClinicalTrialIdentificationWorkflow input_dir output_dir" );
return 1;
}
string dir1 = args[0];
string dir2 = args[1];
if( !gdcm.PosixEmulation.FileIsDirectory(dir1) )
{
System.Console.WriteLine( "Input directory: " + dir1 + " does not exist. Sorry" );
return 1;
}
if( !gdcm.PosixEmulation.FileIsDirectory(dir2) )
{
System.Console.WriteLine( "Output directory: " + dir2 + " does not exist. Sorry" );
return 1;
}
Directory d = new Directory();
uint nfiles = d.Load( dir1, true );
if(nfiles == 0) return 1;
string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem" );
if( !cms.ParseCertificateFile( certpath ) )
{
System.Console.WriteLine( "PEM Certificate : " + certpath + " could not be read. Sorry" );
return 1;
}
SmartPtrAno sano = Anonymizer.New();
Anonymizer ano = sano.__ref__();
MyWatcher watcher = new MyWatcher(ano);
ano.SetCryptographicMessageSyntax( cms );
FilenamesType filenames = d.GetFilenames();
for( uint i = 0; i < nfiles; ++i )
{
string filename = filenames[ (int)i ];
string outfilename = filename.Replace( dir1, dir2 );
System.Console.WriteLine( "Filename: " + filename );
System.Console.WriteLine( "Out Filename: " + outfilename );
if( !ProcessOneFile( ano , filename, outfilename ) )
{
System.Console.WriteLine( "Could not process filename: " + filename );
return 1;
}
}
return 0;
}
}