line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::HL7::Dump; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
75246
|
use strict; |
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
114
|
|
4
|
4
|
|
|
4
|
|
31
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
114
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2037
|
use Class::Utils qw(set_params); |
|
4
|
|
|
|
|
52377
|
|
|
4
|
|
|
|
|
77
|
|
7
|
4
|
|
|
4
|
|
255
|
use English; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
18
|
|
8
|
4
|
|
|
4
|
|
1767
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
192
|
|
9
|
4
|
|
|
4
|
|
13218
|
use Getopt::Std; |
|
4
|
|
|
|
|
207
|
|
|
4
|
|
|
|
|
231
|
|
10
|
4
|
|
|
4
|
|
1890
|
use Net::HL7::Message; |
|
4
|
|
|
|
|
14798
|
|
|
4
|
|
|
|
|
120
|
|
11
|
4
|
|
|
4
|
|
1984
|
use Perl6::Slurp qw(slurp); |
|
4
|
|
|
|
|
6470
|
|
|
4
|
|
|
|
|
23
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.07; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constructor. |
16
|
|
|
|
|
|
|
sub new { |
17
|
2
|
|
|
2
|
1
|
1783
|
my ($class, @params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Create object. |
20
|
2
|
|
|
|
|
7
|
my $self = bless {}, $class; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Process params. |
23
|
2
|
|
|
|
|
12
|
set_params($self, @params); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Object. |
26
|
2
|
|
|
|
|
18
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Run. |
30
|
|
|
|
|
|
|
sub run { |
31
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Process arguments. |
34
|
1
|
|
|
|
|
19
|
$self->{'_opts'} = { |
35
|
|
|
|
|
|
|
'c' => 0, |
36
|
|
|
|
|
|
|
'h' => 0, |
37
|
|
|
|
|
|
|
}; |
38
|
1
|
50
|
33
|
|
|
7
|
if (! getopts('ch', $self->{'_opts'}) || @ARGV < 1 |
|
|
|
33
|
|
|
|
|
39
|
|
|
|
|
|
|
|| $self->{'_opts'}->{'h'}) { |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
112
|
print STDERR "Usage: $0 [-c] [-h] [--version] hl7_file\n"; |
42
|
1
|
|
|
|
|
17
|
print STDERR "\t-c\t\tColor mode.\n"; |
43
|
1
|
|
|
|
|
13
|
print STDERR "\t-h\t\tPrint help.\n"; |
44
|
1
|
|
|
|
|
25
|
print STDERR "\t--version\tPrint version.\n"; |
45
|
1
|
|
|
|
|
21
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
$self->{'_hl7_file'} = $ARGV[0]; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($ENV{'COLOR'}) { |
50
|
0
|
|
|
|
|
|
$self->{'_opts'}->{'c'} = 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Load Term::ANSIColor. |
54
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'c'}) { |
55
|
0
|
|
|
|
|
|
eval "require Term::ANSIColor;"; |
56
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
57
|
0
|
|
|
|
|
|
err "Cannot load 'Term::ANSIColor'.", |
58
|
|
|
|
|
|
|
'Eval error', $EVAL_ERROR; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Get hl7_file. |
63
|
0
|
|
|
|
|
|
my $hl7 = slurp($self->{'_hl7_file'}); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Create message. |
66
|
0
|
|
|
|
|
|
my $msg = Net::HL7::Message->new($hl7); |
67
|
0
|
0
|
|
|
|
|
if (! $msg) { |
68
|
0
|
|
|
|
|
|
err 'Cannot parse HL7 file.', 'File', $self->{'_hl7_file'}; |
69
|
0
|
|
|
|
|
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Segment name: size |
73
|
0
|
|
|
|
|
|
foreach my $seg ($msg->getSegments) { |
74
|
0
|
|
|
|
|
|
foreach my $index (1 .. $seg->size) { |
75
|
0
|
|
|
|
|
|
my $val = $seg->getField($index); |
76
|
0
|
0
|
|
|
|
|
if (defined $val) { |
77
|
0
|
|
|
|
|
|
my $print_val; |
78
|
0
|
0
|
|
|
|
|
if (ref $val eq 'ARRAY') { |
79
|
0
|
|
|
|
|
|
$print_val = $seg->getFieldAsString($index); |
80
|
|
|
|
|
|
|
} else { |
81
|
0
|
|
|
|
|
|
$print_val = $val; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'c'}) { |
84
|
0
|
|
|
|
|
|
print Term::ANSIColor::color('green').$seg->getName. |
85
|
|
|
|
|
|
|
Term::ANSIColor::color('reset').'-'. |
86
|
|
|
|
|
|
|
Term::ANSIColor::color('red').$index. |
87
|
|
|
|
|
|
|
Term::ANSIColor::color('reset').':'. |
88
|
|
|
|
|
|
|
Term::ANSIColor::color('bold white'). |
89
|
|
|
|
|
|
|
$print_val.Term::ANSIColor::color('reset')."\n"; |
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
|
print $seg->getName.'-'.$index.':'.$print_val."\n"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |