ICD10/Parser.pm

filter: Statementstmt 66.6% 30 / 45 Branchbran 60.0% 6 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 65.7% 46 / 70 CC 8 SCAR 19.6
CC
8
Cov
63%
parse
20.0
_get_parent
5.1
graph
2.0
CRAP 7.1
« ICD10.pm ↑ Summary ICD10/Graph.pm »
1 package Medical::ICD10::Parser;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Text::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Medical::ICD10::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
26 1 my $class = shift;
27 1 my $self = { };
28
29 $self->{csv} =
30 1 Text::CSV->new({ 'sep_char' => "\t" });
31
32 1 $self->{csv}->column_names( qw( icd description) );
33
34 $self->{g} =
35 1 Medical::ICD10::Graph->new;
36
37 1 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 0 ▶sub parse {
Subroutine parse: not called CC=4 SCAR=30.0
Pod documented
51 0 my $self = shift;
52 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 ▶ open my $io, "<:encoding(utf8)", $filename
Condition0%0/2
$filename || die("${filename}: $!")
l!l
00
MC/DC0%0/1
$filename || die("${filename}: $!")
$filename
Truth table0%0/2
A
A= $filename
Aresult
11
00
59 || die "$filename: $!";
60  
61 ##
62 ## First pass: add all the nodes
63
64 0 ▶ while ( my $rh = $self->{csv}->getline_hr( $io) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rh = $self->{"csv"}->getline_hr($io)) 0 0 0
65 0 my $icd = $rh->{icd};
66 0 $self->{g}->add_vertex( $rh->{icd} );
67 0 $self->{g}->set_vertex_attribute( $rh->{icd}, 'description', $rh->{description} );
68 }
69
70 ##
71 ## Second pass: add all the edges
72
73 0 my @vertices = $self->{g}->vertices;
74
75 0 foreach my $vertex ( @vertices ) {
76 0 my $parent = $self->_get_parent( $vertex );
77 0 $self->{g}->add_edge( $parent, $vertex );
78 }
79  
80 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 3 ▶sub _get_parent {
Subroutine _get_parent: called CC=5 SCAR=16.4
94 3 my $self = shift;
95 3 my $term = shift;
96  
97 3 ▶ if ( $term eq 'root' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term eq "root") 0 3 3
98 0 return 'root';
99 }
100  
101 3 my $length = length( $term );
102
103 3 ▶ if ( $length == 5 ){
Branch: 3 branches
BranchTrueFalseTotal
if ($length == 5) { } 1 2 3
elsif ($length == 4) { } 1 1 2
elsif ($length == 3) { } 1 0 1
104 1 return substr( $term, 0, 4 );
105 }
106
107 elsif ( $length == 4){
108 1 return substr($term, 0, 3);
109 }
110
111 elsif ( $length == 3 ) {
112 1 return 'root'
113 }
114
115 }
116  
117 =head2 graph
118  
119 Returns the internal Medical::ICD10::Graph object.
120  
121 =cut
122  
123 0 ▶sub graph {
Subroutine graph: not called CC=1 SCAR=6.9
Pod documented
124 0 my $self = shift;
125 0 return $self->{g};
126 }
127  
128  
129 =head1 AUTHOR
130  
131 Spiros Denaxas, C<< <s.denaxas at gmail.com> >>
132  
133 =head1 BUGS
134  
135 Please report any bugs or feature requests to C<bug-medical-icd10 at rt.cpan.org>, or through
136 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Medical-ICD10>. 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<https://github.com/spiros/Medical-ICD10>
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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Medical-ICD10>
156  
157 =item * AnnoCPAN: Annotated CPAN documentation
158  
159 L<http://annocpan.org/dist/Medical-ICD10>
160  
161 =item * CPAN Ratings
162  
163 L<http://cpanratings.perl.org/d/Medical-ICD10>
164  
165 =item * Search CPAN
166  
167 L<http://search.cpan.org/dist/Medical-ICD10/>
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 3 1;
« ICD10.pm ↑ Summary ICD10/Graph.pm »