ICD10.pm

filter: Statementstmt 14.0% 17 / 121 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 29.4% 5 / 17 Podpod 100% 11 / 11 totaltotal 15.5% 33 / 212 CC 33 SCAR 33.2
CC
33
Cov
10%
get_parent_terms
56.0
get_child_terms
56.0
get_parent_term
30.0
CRAP 27.8
↑ Summary ICD10/Parser.pm »
1 package Medical::ICD10;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Medical::ICD10::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Medical::ICD10::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Medical::ICD10 - ICD10 Wrapper module
14  
15 =head1 VERSION
16  
17 Version 0.05
18  
19 =cut
20  
21 2 our $VERSION = '0.05';
22  
23 =head1 SYNOPSIS
24  
25 The International Statistical Classification of Diseases and Related Health Problems 10th
26 Revision (ICD-10) is a coding of diseases and signs, symptoms, abnormal findings,
27 complaints, social circumstances and external causes of injury or diseases, as classified by
28 the World Health Organization. (WHO). The code set allows more than 14,400 different codes and
29 permits the tracking of many new diagnoses.
30  
31 You can find more information about ICD10 at: L<http://www.who.int/classifications/icd/en/>
32  
33 The NHS provides the ICD10 codes as a flat tab separated file which can be obtained from the Connecting For
34 Health Data Standars helpdesk at: L<http://www.connectingforhealth.nhs.uk/systemsandservices/data/clinicalcoding/codingstandards/icd-10/icd10_prod>
35  
36 This module is designed to parse that file and provide a wrapper around the ICD10
37 classification codes.
38  
39 use Medical::ICD10;
40
41 my $MICD = Medical::ICD10->new();
42
43 $MICD->parse( "/path/to/tsv/file/with/codes.txt" );
44
45 ## Get an individual term
46
47 my $Term = $MICD->get_term( 'A809' );
48 my $description = $Term->description; # "Acute poliomyelitis, unspecified"
49
50 ## Get the terms parent
51
52 my $ParentTerm = $MICD->get_parent_term_string( 'A809' );
53
54 ## Get all the parents from the term
55
56 my $ra_parent_terms = $MICD->get_parent_terms( 'A809' );
57 my $ra_parent_terms = $MICD->get_parent_terms_string( 'A803' );
58
59 ## Get all the children of the term
60
61 my $ra_child_terms = $MICD->get_child_terms_string( 'A809' );
62 my $ra_child_terms = $MICD->get_child_terms( 'B27' );
63  
64 =head1 METHODS
65  
66 =head2 new
67  
68 Creates a new instance of the module.
69  
70 my $MICD = Medical::ICD10->new();
71  
72 =cut
73  
74 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
75 0 my $class = shift;
76 0 my $self = { };
77
78 $self->{parser} =
79 0 Medical::ICD10::Parser->new;
80
81 0 return bless $self, $class;
82 }
83  
84 =head2 parse
85  
86 Parses the flat file containing the ICD10 codes.
87  
88 $MICD->parse( "/path/to/tsv/file/with/codes.txt" );
89  
90 This method returns true on success and undef on failure.
91  
92 =cut
93  
94 0 ▶sub parse {
Subroutine parse: not called CC=3 SCAR=24.8
Pod documented
95 0 my $self = shift;
96 0 my $filename = shift;
97
98 0 ▶ unless ( -e $filename && -r $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filename and -r $filename) 0 0 0
Condition0%0/3
-e $filename and -r $filename
!ll&&!rl&&r
000
MC/DC0%0/2
-e $filename and -r $filename
-e $filename -r $filename
Truth table0%0/3
A and B
A= -e $filenameB= -r $filename
ABresult
0X0
100
111
99 0 die "Error opening/loading $filename";
100 }
101
102 # Filename exists, lets try to parse it
103 # using the parser
104  
105 0 return $self->{parser}->parse( $filename );
106
107 }
108  
109 =head2 get_term
110  
111 my $Term = $MICD->get_term( 'A809' );
112  
113 This method returns an Medical::ICD10::Term object and undef on error.
114  
115 =cut
116  
117 0 ▶sub get_term {
Subroutine get_term: not called CC=3 SCAR=24.8
Pod documented
118 0 my $self = shift;
119 0 my $term = shift;
120
121 0 ▶ return undef if ( ! defined $term );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 0 0 0
122
123 0 ▶ return undef if ( !$self->{parser}->graph->has_vertex( $term ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->has_vertex($term) 0 0 0
124
125 my $description =
126 0 $self->{parser}->graph->get_vertex_attribute( $term, 'description' );
127
128 0 return Medical::ICD10::Term->new(
129 {
130 'term' => $term,
131 'description' => $description,
132 } );
133
134 }
135  
136  
137 =head2 get_all_terms
138  
139 my $ra_all_terms = $MICD->get_all_terms;
140  
141 Returns a reference to an array of Medical::ICD10::Term objects with all terms
142 in the current file distribution.
143  
144 This method returns undef on error.
145  
146 =cut
147  
148 0 ▶sub get_all_terms {
Subroutine get_all_terms: not called CC=2 SCAR=17.9
Pod documented
149 0 my $self = shift;
150
151 my @vertices =
152 0 $self->{parser}->graph->vertices;
153
154 0 my @out;
155
156 0 foreach my $vertex ( @vertices ) {
157
158 my $description =
159 0 $self->{parser}->graph->get_vertex_attribute( $vertex, 'description');
160
161 0 push @out, Medical::ICD10::Term->new(
162 { 'term' => $vertex,
163 'description' => $description } );
164 }
165  
166 0 return \@out;
167  
168 }
169  
170 =head2 get_all_terms_hashref
171  
172 my $rh_all_terms = $MICD->get_all_terms_hashref;
173
174 Returns a reference to a hash with all terms in the current file distribution. The keys of
175 the hash are the ICD10 terms and the values are the textual descriptions.
176  
177 This method returns undef on error.
178  
179 =cut
180  
181 0 ▶sub get_all_terms_hashref {
Subroutine get_all_terms_hashref: not called CC=2 SCAR=17.9
Pod documented
182 0 my $self = shift;
183
184 my @vertices =
185 0 $self->{parser}->graph->vertices;
186
187 0 my $rh_out;
188  
189 0 foreach my $vertex ( @vertices ) {
190  
191 my $description =
192 0 $self->{parser}->graph->get_vertex_attribute( $vertex, 'description');
193  
194 0 $rh_out->{ $vertex } = $description;
195  
196 }
197
198 0 return $rh_out;
199
200 }
201  
202 =head2 get_parent_term
203  
204 my $ParentTerm = $MICD->get_parent_term( 'A809' );
205
206 or
207  
208 my $ParentTerm = $MICD->get_parent_term( $Term );
209  
210 Returns the immediate parent term of a given term as an Medical::ICD10::Term object.
211 This method accepts both a scalar with the term name
212 and a Medical::ICD10::Term object as input
213  
214 This method returns undef on error.
215  
216 =cut
217  
218 0 ▶sub get_parent_term {
Subroutine get_parent_term: not called CC=5 SCAR=34.0
Pod documented
219 0 my $self = shift;
220 0 my $term = shift;
221
222 0 my $search_term;
223
224 0 ▶ if ( ref $term && ref $term eq 'Medical::ICD10::Term' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $term and ref $term eq 'Medical::ICD10::Term') { } 0 0 0
Condition0%0/3
ref $term and ref $term eq "Medical::ICD10::Term"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $term and ref $term eq "Medical::ICD10::Term"
ref $term ref $term eq "Medical::ICD10::Term"
Truth table0%0/3
A and B
A= ref $termB= ref $term eq "Medical::ICD10::Term"
ABresult
0X0
100
111
225 0 $search_term = $term->term;
226 } else {
227 0 $search_term = $term;
228 }
229
230 return undef
231 0 ▶ if ( !$self->{parser}->graph->has_vertex( $search_term ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->has_vertex($search_term) 0 0 0
232
233 return undef
234 0 ▶ if ( !$self->{parser}->graph->is_predecessorful_vertex( $search_term) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->is_predecessorful_vertex($search_term) 0 0 0
235  
236 my @predecessors =
237 0 $self->{parser}->graph->predecessors( $search_term );
238
239 0 my $predecessor = $predecessors[ 0 ];
240
241 my $predecessor_description =
242 0 $self->{parser}->graph->get_vertex_attribute( $predecessor, 'description' );
243
244 0 return Medical::ICD10::Term->new(
245 {
246 'term' => $predecessor,
247 'description' => $predecessor_description,
248 } );
249
250 }
251  
252 =head2 get_parent_term_string
253  
254 my $ParentTerm = $MICD->get_parent_term_string( 'A809' );
255
256 or
257  
258 my $ParentTerm = $MICD->get_parent_term_string( $Term );
259  
260 Returns the immediate parent term of a given term as a scalar.
261 This method accepts both a scalar with the term name and a
262 Medical::ICD10::Term object as input.
263  
264 This method returns undef on error.
265  
266 =cut
267  
268 0 ▶sub get_parent_term_string {
Subroutine get_parent_term_string: not called CC=2 SCAR=17.9
Pod documented
269 0 my $self = shift;
270 0 my $term = shift;
271
272 return undef
273 0 ▶ unless ( defined $term );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 0 0 0
274
275 0 my $predecessor =
276 $self->get_parent_term( $term );
277
278 0 return $predecessor->term;
279
280 }
281  
282 =head2 get_parent_terms
283  
284 my $ra_parent_terms = $MICD->get_parent_terms( 'A809' );
285
286 or
287  
288 my $ra_parent_terms = $MICD->get_parent_terms( $Term );
289  
290 Returns a reference to an array of Medical::ICD10::Term objects of all parent terms
291 of a given term. This method accepts both a scalar with the term name and
292 a Medical::ICD10::Term object as input.
293  
294 This method returns undef on error.
295  
296 =cut
297  
298 0 ▶sub get_parent_terms {
Subroutine get_parent_terms: not called CC=7 SCAR=40.3
Pod documented
299 0 my $self = shift;
300 0 my $term = shift;
301  
302 return undef
303 0 ▶ unless defined ( $term );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 0 0 0
304  
305 0 my $search_term;
306
307 0 ▶ if ( ref $term && ref $term eq 'Medical::ICD10::Term' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $term and ref $term eq 'Medical::ICD10::Term') { } 0 0 0
Condition0%0/3
ref $term and ref $term eq "Medical::ICD10::Term"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $term and ref $term eq "Medical::ICD10::Term"
ref $term ref $term eq "Medical::ICD10::Term"
Truth table0%0/3
A and B
A= ref $termB= ref $term eq "Medical::ICD10::Term"
ABresult
0X0
100
111
308 0 $search_term = $term->term;
309 } else {
310 0 $search_term = $term;
311 }
312
313 return undef
314 0 ▶ if ( !$self->{parser}->graph->has_vertex( $search_term ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->has_vertex($search_term) 0 0 0
315
316 return undef
317 0 ▶ if ( !$self->{parser}->graph->is_predecessorful_vertex( $search_term) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->is_predecessorful_vertex($search_term) 0 0 0
318  
319 0 my $ra_out = [ ];
320  
321 my @predecessors =
322 0 $self->{parser}->graph->all_predecessors( $search_term );
323
324 0 foreach my $term ( @predecessors ) {
325
326 my $predecessor_description =
327 0 $self->{parser}->graph->get_vertex_attribute( $term, 'description' );
328
329 0 my $obj =
330 Medical::ICD10::Term->new(
331 {
332 'term' => $term,
333 'description' => $predecessor_description,
334 });
335
336 0 push( @$ra_out, $obj );
337
338 }
339
340 0 return $ra_out;
341
342 }
343  
344 =head2 get_parent_terms_string
345  
346 my $ra_parent_terms = $MICD->get_parent_terms_string( 'A809' );
347
348 or
349  
350 my $ra_parent_terms = $MICD->get_parent_terms_string( $Term );
351  
352 Returns a reference to an array of scalars of all parent terms
353 of a given term. This method accepts both a scalar with the term name and
354 a Medical::ICD10::Term object as input.
355  
356 This method returns undef on error.
357  
358 =cut
359  
360 0 ▶sub get_parent_terms_string {
Subroutine get_parent_terms_string: not called CC=5 SCAR=34.0
Pod documented
361 0 my $self = shift;
362 0 my $term = shift;
363
364 return undef
365 0 ▶ unless ( defined $term );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 0 0 0
366
367 0 my $ra_parent_terms =
368 $self->get_parent_terms( $term );
369
370 return undef
371 0 ▶ unless ( defined $ra_parent_terms && scalar(@$ra_parent_terms) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ra_parent_terms and scalar @$ra_parent_terms 0 0 0
Condition0%0/2
defined $ra_parent_terms and scalar @$ra_parent_terms
!ll
00
MC/DC0%0/1
defined $ra_parent_terms and scalar @$ra_parent_terms
defined $ra_parent_terms
Truth table0%0/2
A
A= defined $ra_parent_terms
Aresult
00
11
372
373 0 my $ra_out = [ ];
374  
375 0 foreach my $term ( @$ra_parent_terms ) {
376 0 push ( @$ra_out, $term->term );
377 }
378
379 0 return $ra_out;
380
381 }
382  
383  
384 =head2 get_child_terms
385  
386 my $ra_child_terms = $MICD->get_child_terms( 'A809' );
387
388 or
389  
390 my $ra_child_terms = $MICD->get_child_terms( $Term );
391  
392 Returns a reference to an array of Medical::ICD10::Term objects of all child terms
393 of a given term. This method accepts both a scalar with the term name and
394 a Medical::ICD10::Term object as input.
395  
396 This method returns undef on error.
397  
398 =cut
399  
400 0 ▶sub get_child_terms {
Subroutine get_child_terms: not called CC=7 SCAR=40.3
Pod documented
401 0 my $self = shift;
402 0 my $term = shift;
403
404 return undef
405 0 ▶ unless ( defined $term );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 0 0 0
406
407 0 my $search_term;
408  
409 0 ▶ if ( ref $term && ref $term eq 'Medical::ICD10::Term' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $term and ref $term eq 'Medical::ICD10::Term') { } 0 0 0
Condition0%0/3
ref $term and ref $term eq "Medical::ICD10::Term"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $term and ref $term eq "Medical::ICD10::Term"
ref $term ref $term eq "Medical::ICD10::Term"
Truth table0%0/3
A and B
A= ref $termB= ref $term eq "Medical::ICD10::Term"
ABresult
0X0
100
111
410 0 $search_term = $term->term;
411 } else {
412 0 $search_term = $term;
413 }
414
415 return undef
416 0 ▶ if ( !$self->{parser}->graph->has_vertex( $search_term ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->has_vertex($search_term) 0 0 0
417  
418 return undef
419 0 ▶ if ( !$self->{parser}->graph->is_successorful_vertex( $search_term) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"}->graph->is_successorful_vertex($search_term) 0 0 0
420
421 my @successors =
422 0 $self->{parser}->graph->all_successors( $search_term );
423  
424 0 my $ra_out = [ ];
425  
426 0 foreach my $term ( @successors ) {
427  
428 my $successor_description =
429 0 $self->{parser}->graph->get_vertex_attribute( $term, 'description' );
430  
431 0 my $obj =
432 Medical::ICD10::Term->new(
433 {
434 'term' => $term,
435 'description' => $successor_description,
436 });
437  
438 0 push( @$ra_out, $obj );
439  
440 }
441  
442 0 return $ra_out;
443 }
444  
445  
446 =head2 get_child_terms_string
447  
448 my $ra_child_terms = $MICD->get_child_terms_string( 'A809' );
449
450 or
451  
452 my $ra_child_terms = $MICD->get_child_terms_string( $Term );
453  
454 Returns a reference to an array of scalars of all child terms
455 of a given term. This method accepts both a scalar with the term name and
456 a Medical::ICD10::Term object as input.
457  
458 This method returns undef on error.
459  
460 =cut
461  
462 0 ▶sub get_child_terms_string {
Subroutine get_child_terms_string: not called CC=2 SCAR=17.9
Pod documented
463 0 my $self = shift;
464 0 my $term = shift;
465
466 return undef
467 0 ▶ unless ( defined $term );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $term 0 0 0
468
469 0 my $ra_successor_terms =
470 $self->get_child_terms( $term );
471
472 0 return $self->_format_output( $ra_successor_terms, 'string' );
473
474 }
475  
476 =head2 _format_output
477  
478 Internal method used to format the output from different methods. Do not
479 use this method directly.
480  
481 =cut
482  
483 0 ▶sub _format_output {
Subroutine _format_output: not called CC=5 SCAR=34.0
484 0 my $self = shift;
485 0 my $ra_data = shift;
486 0 my $mode = shift;
487
488 0 my $ra_out = [ ];
489
490 0 ▶ if ( $mode eq 'string' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'string') { } 0 0 0
elsif ($mode eq 'objects') { } 0 0 0
491
492 0 foreach my $term ( @$ra_data ) {
493 0 push( @$ra_out, $term->term );
494 }
495
496 }
497
498 elsif ( $mode eq 'objects' ) {
499  
500 0 foreach my $term ( @$ra_data ) {
501
502 my $description =
503 0 $self->{parser}->graph->get_vertex_attribute( $term, 'description' );
504  
505 0 my $obj =
506 Medical::ICD10::Term->new(
507 {
508 'term' => $term,
509 'description' => $description,
510 });
511  
512 0 push( @$ra_out, $obj );
513
514 }
515
516 }
517
518 0 return $ra_out;
519
520 }
521  
522 =head1 AUTHOR
523  
524 Spiros Denaxas, C<< <s.denaxas at gmail.com> >>
525  
526 =head1 BUGS
527  
528 Please report any bugs or feature requests to C<bug-medical-icd10 at rt.cpan.org>, or through
529 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Medical-ICD10>. I will be notified, and then you'll
530 automatically be notified of progress on your bug as I make changes.
531  
532 =head1 SOURCE CODE
533  
534 The source code can be found on github L<https://github.com/spiros/Medical-ICD10>
535  
536 =head1 SUPPORT
537  
538 You can find documentation for this module with the perldoc command.
539  
540 perldoc Medical::ICD10
541  
542  
543 You can also look for information at:
544  
545 =over 4
546  
547 =item * RT: CPAN's request tracker
548  
549 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Medical-ICD10>
550  
551 =item * AnnoCPAN: Annotated CPAN documentation
552  
553 L<http://annocpan.org/dist/Medical-ICD10>
554  
555 =item * CPAN Ratings
556  
557 L<http://cpanratings.perl.org/d/Medical-ICD10>
558  
559 =item * Search CPAN
560  
561 L<http://search.cpan.org/dist/Medical-ICD10/>
562  
563 =back
564  
565 =head1 LICENSE AND COPYRIGHT
566  
567 Copyright 2011 Spiros Denaxas.
568  
569 This program is free software; you can redistribute it and/or modify it
570 under the terms of either: the GNU General Public License as published
571 by the Free Software Foundation; or the Artistic License.
572  
573 See http://dev.perl.org/licenses/ for more information.
574  
575  
576 =cut
577  
578 2 1; # End of Medical::ICD10
↑ Summary ICD10/Parser.pm »