line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Medical::ICD10::Parser; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
782
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1378
|
use Data::Dumper; |
|
2
|
|
|
|
|
7418
|
|
|
2
|
|
|
|
|
175
|
|
7
|
2
|
|
|
2
|
|
2191
|
use Text::CSV; |
|
2
|
|
|
|
|
26818
|
|
|
2
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1289
|
use Medical::ICD10::Graph; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
895
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Medical::ICD10::Parser - ICD10 Parser object |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 new |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Create a new parser object. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Do not use directly. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
1
|
|
|
1
|
1
|
895
|
my $class = shift; |
27
|
1
|
|
|
|
|
3
|
my $self = { }; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
11
|
$self->{csv} = |
30
|
|
|
|
|
|
|
Text::CSV->new({ 'sep_char' => "\t" }); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
114
|
$self->{csv}->column_names( qw( icd description) ); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
34
|
$self->{g} = |
35
|
|
|
|
|
|
|
Medical::ICD10::Graph->new; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
5
|
return bless $self, $class; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 parse |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
The main parser function. Accepts a tab separated file of ICD10 codes |
44
|
|
|
|
|
|
|
along with their descriptions and parses it. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Returns true on success and undef on failure. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub parse { |
51
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
52
|
0
|
|
|
|
|
0
|
my $filename = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# UTF8 is needed as there is a single term with an accept character |
55
|
|
|
|
|
|
|
# in the term description: |
56
|
|
|
|
|
|
|
# M91.1 Juvenile osteochondrosis of head of femur [Legg-Calvé-Perthes] |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
0
|
|
|
0
|
open my $io, "<:encoding(utf8)", $filename |
59
|
|
|
|
|
|
|
|| die "$filename: $!"; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
## |
62
|
|
|
|
|
|
|
## First pass: add all the nodes |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
while ( my $rh = $self->{csv}->getline_hr( $io) ) { |
65
|
0
|
|
|
|
|
0
|
my $icd = $rh->{icd}; |
66
|
0
|
|
|
|
|
0
|
$self->{g}->add_vertex( $rh->{icd} ); |
67
|
0
|
|
|
|
|
0
|
$self->{g}->set_vertex_attribute( $rh->{icd}, 'description', $rh->{description} ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
## |
71
|
|
|
|
|
|
|
## Second pass: add all the edges |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my @vertices = $self->{g}->vertices; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
foreach my $vertex ( @vertices ) { |
76
|
0
|
|
|
|
|
0
|
my $parent = $self->_get_parent( $vertex ); |
77
|
0
|
|
|
|
|
0
|
$self->{g}->add_edge( $parent, $vertex ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
return $self->{g}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 _get_parent |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Internal parser function used to discover the parent |
87
|
|
|
|
|
|
|
of each node. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Do not use directly. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _get_parent { |
94
|
3
|
|
|
3
|
|
1501
|
my $self = shift; |
95
|
3
|
|
|
|
|
5
|
my $term = shift; |
96
|
|
|
|
|
|
|
|
97
|
3
|
50
|
|
|
|
10
|
if ( $term eq 'root' ) { |
98
|
0
|
|
|
|
|
0
|
return 'root'; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
5
|
my $length = length( $term ); |
102
|
|
|
|
|
|
|
|
103
|
3
|
100
|
|
|
|
12
|
if ( $length == 5 ){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
104
|
1
|
|
|
|
|
5
|
return substr( $term, 0, 4 ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
elsif ( $length == 4){ |
108
|
1
|
|
|
|
|
6
|
return substr($term, 0, 3); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
elsif ( $length == 3 ) { |
112
|
1
|
|
|
|
|
7
|
return 'root' |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 graph |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the internal Medical::ICD10::Graph object. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub graph { |
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
return $self->{g}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Spiros Denaxas, C<< >> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 BUGS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
136
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
137
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SOURCE CODE |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The source code can be found on github L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SUPPORT |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
perldoc Medical::ICD10 |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can also look for information at: |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over 4 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * CPAN Ratings |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * Search CPAN |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright 2011 Spiros Denaxas. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
176
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
177
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |