File Coverage

blib/lib/DicomPack/Util/DicomAnonymizer.pm
Criterion Covered Total %
statement 12 28 42.8
branch 0 2 0.0
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 18 38 47.3


line stmt bran cond sub pod time code
1             ##############################################################################
2             # DicomAnonymizer.pm -- a module to anonymize Dicom files
3             #
4             # Copyright (c) 2010 Baoshe Zhang. All rights reserved.
5             # This file is part of "DicomPack". DicomReader is free software. You can
6             # redistribute it and/or modify it under the same terms as Perl itself.
7             ##############################################################################
8              
9             package DicomPack::Util::DicomAnonymizer;
10              
11 1     1   1818 use strict;
  1         1  
  1         34  
12 1     1   4 use warnings;
  1         2  
  1         24  
13              
14 1     1   5 use DicomPack::IO::DicomReader;
  1         2  
  1         17  
15 1     1   5 use DicomPack::IO::DicomWriter;
  1         2  
  1         209  
16              
17             our $VERSION = '0.95';
18              
19             sub new
20             {
21 0     0 1   my $classname = shift;
22 0           my $self = {};
23 0           bless $self, $classname;
24 0           return $self;
25             }
26              
27             # get dicom fields from DICOM data file
28             sub anonymize
29             {
30 0     0 1   my $self = shift;
31              
32 0           my $infile = shift;
33 0           my $outfile = shift;
34              
35 0           my $anonymizedFieldList = shift;
36              
37 0           my $reader = DicomPack::IO::DicomReader->new($infile);
38 0           my $dicomFields = $reader->getDicomField();
39              
40 0           my $writer = DicomPack::IO::DicomWriter->new($dicomFields);
41 0           while(my ($tagPath, $tagValue) = each(%$anonymizedFieldList))
42             {
43 0 0         if(my ($value,$vr) = $reader->getValue($tagPath))
44             {
45 0           $writer->setValue($tagPath, $tagValue, $vr);
46             }
47             else
48             {
49 0           print $tagPath." : does not exists in $infile!!!\n";
50             }
51             }
52 0           $writer->flush($outfile);
53             }
54              
55             1;
56              
57             __END__