| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Medical::OPCS4; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Medical::OPCS4::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Medical::OPCS4::Term; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Medical::OPCS4 - OPCS4 Wrapper module | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 VERSION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Version 0.03 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | OPCS-4 is an abbreviation of the Office of Population, Censuses and Surveys Classification of | ||||||||||||||||||||||||||||
| 26 | Surgical Operations and Procedures (4th revision)[1]. It translates operations, procedures | ||||||||||||||||||||||||||||
| 27 | and interventions carried out on a patient during an episode of health care in the NHS into | ||||||||||||||||||||||||||||
| 28 | alphanumeric code usually done by trained health care professionals working in an area called | ||||||||||||||||||||||||||||
| 29 | clinical coding. As such it is comparable with ICD-10, which is used for coding diagnoses in | ||||||||||||||||||||||||||||
| 30 | the same setting. There are some areas of overlapping between ICD-10 and OPCS-4. for example | ||||||||||||||||||||||||||||
| 31 | both feature codes for the delivery of children. In the U.K. it is recommended clinical coders use | ||||||||||||||||||||||||||||
| 32 | the OPCS-4. codes for these procedures. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | This modules provides a wrapper around the NHS CFH OPCS-4 distribution which can be | ||||||||||||||||||||||||||||
| 35 | found here L<http://www.connectingforhealth.nhs.uk/systemsandservices/data/clinicalcoding/codingstandards/opcs4> | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | my $O = Medical::OPCS4->new(); | ||||||||||||||||||||||||||||
| 38 | $O->parse('./t/testdata.txt'); | ||||||||||||||||||||||||||||
| 39 | my $Term = $O->get_term('O16'); | ||||||||||||||||||||||||||||
| 40 | my $Parent = $O->get_parent_term( 'O16.1' ); | ||||||||||||||||||||||||||||
| 41 | my $ra_ch = $O->get_child_terms( 'O16' ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | The GitHub page for this module is here L<https://github.com/spiros/Medical-OPCS4> | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 METHODS | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head2 new | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Creates a new instance of the module. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | my $O = Medical::OPCS4->new(); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 57 | 1 | my $self = { }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | $self->{parser} = | ||||||||||||||||||||||||||||
| 60 | 1 | Medical::OPCS4::Parser->new; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head2 parse | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Parses the flat file containing the OPCS4 codes. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | $O->parse( "/path/to/tsv/file/with/codes.txt" ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | This method returns true on success and undef on failure. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 1 | my $filename = shift; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | unless ( -e $filename && -r $filename ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $filename and -r $filename
MC/DC0%0/2
-e $filename and -r $filename
-e $filename
-r $filename
Truth table33%1/3
A and B
A= -e $filenameB= -r $filename
| |||||||||||||||||||||||||||||
| 80 | 0 | die "Error opening/loading $filename"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # Filename exists, lets try to parse it | ||||||||||||||||||||||||||||
| 84 | # using the parser | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | return $self->{parser}->parse( $filename ); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head2 get_term | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | my $Term = $O->get_term( 'A809' ); | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | This method returns an Medical::OPCS4::Term object and undef on error. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | sub get_term { | ||||||||||||||||||||||||||
|
Subroutine
get_term: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 2 | my $term = shift; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | return undef if ( ! defined $term ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | return undef if ( !$self->{parser}->graph->has_vertex( $term ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | my $description = | ||||||||||||||||||||||||||||
| 107 | 1 | $self->{parser}->graph->get_vertex_attribute( $term, 'description' ); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | return Medical::OPCS4::Term->new( | |||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 'term' => $term, | ||||||||||||||||||||||||||||
| 112 | 'description' => $description, | ||||||||||||||||||||||||||||
| 113 | } ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head2 get_all_terms | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | my $ra_all_terms = $O->get_all_terms; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Returns a reference to an array of Medical::OPCS4::Term objects with all terms | ||||||||||||||||||||||||||||
| 123 | in the current file distribution. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub get_all_terms { | ||||||||||||||||||||||||||
|
Subroutine
get_all_terms: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | my @vertices = | ||||||||||||||||||||||||||||
| 133 | 1 | $self->{parser}->graph->vertices; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | my @out; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | foreach my $vertex ( @vertices ) { | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | my $description = | ||||||||||||||||||||||||||||
| 140 | 6 | $self->{parser}->graph->get_vertex_attribute( $vertex, 'description'); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 6 | push @out, Medical::OPCS4::Term->new( | |||||||||||||||||||||||||||
| 143 | { 'term' => $vertex, | ||||||||||||||||||||||||||||
| 144 | 'description' => $description } ); | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | return \@out; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head2 get_all_terms_hashref | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | my $rh_all_terms = $O->get_all_terms_hashref; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Returns a reference to a hash with all terms in the current file distribution. The keys of | ||||||||||||||||||||||||||||
| 156 | the hash are the OPCS4 terms and the values are the textual descriptions. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub get_all_terms_hashref { | ||||||||||||||||||||||||||
|
Subroutine
get_all_terms_hashref: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | my @vertices = | ||||||||||||||||||||||||||||
| 166 | 1 | $self->{parser}->graph->vertices; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 1 | my $rh_out; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | foreach my $vertex ( @vertices ) { | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | my $description = | ||||||||||||||||||||||||||||
| 173 | 6 | $self->{parser}->graph->get_vertex_attribute( $vertex, 'description'); | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 6 | $rh_out->{ $vertex } = $description; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | return $rh_out; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head2 get_parent_term | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | my $ParentTerm = $O->get_parent_term( 'A809' ); | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | or | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | my $ParentTerm = $O->get_parent_term( $Term ); | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Returns the immediate parent term of a given term as an Medical::OPCS4::Term object. | ||||||||||||||||||||||||||||
| 192 | This method accepts both a scalar with the term name | ||||||||||||||||||||||||||||
| 193 | and a Medical::OPCS4::Term object as input | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | ▶ | sub get_parent_term { | ||||||||||||||||||||||||||
|
Subroutine
get_parent_term: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 200 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 201 | 2 | my $term = shift; | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 2 | my $search_term; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 2 | ▶ | if ( ref $term && ref $term eq 'Medical::OPCS4::Term' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $term and ref $term eq "Medical::OPCS4::Term"
MC/DC50%1/2
ref $term and ref $term eq "Medical::OPCS4::Term"
ref $term
ref $term eq "Medical::OPCS4::Term"
Truth table66%2/3
A and B
A= ref $termB= ref $term eq "Medical::OPCS4::Term"
| |||||||||||||||||||||||||||||
| 206 | 1 | $search_term = $term->term; | |||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||
| 208 | 1 | $search_term = $term; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | return undef | ||||||||||||||||||||||||||||
| 212 | 2 | ▶ | if ( !$self->{parser}->graph->has_vertex( $search_term ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | return undef | ||||||||||||||||||||||||||||
| 215 | 2 | ▶ | if ( !$self->{parser}->graph->is_predecessorful_vertex( $search_term) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | my @predecessors = | ||||||||||||||||||||||||||||
| 218 | 2 | $self->{parser}->graph->predecessors( $search_term ); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 2 | my $predecessor = $predecessors[ 0 ]; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | my $predecessor_description = | ||||||||||||||||||||||||||||
| 223 | 2 | $self->{parser}->graph->get_vertex_attribute( $predecessor, 'description' ); | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 2 | return Medical::OPCS4::Term->new( | |||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||
| 227 | 'term' => $predecessor, | ||||||||||||||||||||||||||||
| 228 | 'description' => $predecessor_description, | ||||||||||||||||||||||||||||
| 229 | } ); | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =head2 get_parent_term_string | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | my $ParentTerm = $O->get_parent_term_string( 'A809' ); | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | or | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | my $ParentTerm = $O->get_parent_term_string( $Term ); | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | Returns the immediate parent term of a given term as a scalar. | ||||||||||||||||||||||||||||
| 242 | This method accepts both a scalar with the term name and a | ||||||||||||||||||||||||||||
| 243 | Medical::OPCS4::Term object as input. | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =cut | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub get_parent_term_string { | ||||||||||||||||||||||||||
|
Subroutine
get_parent_term_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 251 | 0 | my $term = shift; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | return undef | ||||||||||||||||||||||||||||
| 254 | 0 | ▶ | unless ( defined $term ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | my $predecessor = | |||||||||||||||||||||||||||
| 257 | $self->get_parent_term( $term ); | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | return $predecessor->term; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | =head2 get_parent_terms | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | my $ra_parent_terms = $O->get_parent_terms( 'A809' ); | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | or | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | my $ra_parent_terms = $O->get_parent_terms( $Term ); | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | Returns a reference to an array of Medical::OPCS4::Term objects of all parent terms | ||||||||||||||||||||||||||||
| 272 | of a given term. This method accepts both a scalar with the term name and | ||||||||||||||||||||||||||||
| 273 | a Medical::OPCS4::Term object as input. | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =cut | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub get_parent_terms { | ||||||||||||||||||||||||||
|
Subroutine
get_parent_terms: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 280 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 281 | 0 | my $term = shift; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | return undef | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | unless defined ( $term ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | my $search_term; | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ( ref $term && ref $term eq 'Medical::OPCS4::Term' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $term and ref $term eq "Medical::OPCS4::Term"
MC/DC0%0/2
ref $term and ref $term eq "Medical::OPCS4::Term"
ref $term
ref $term eq "Medical::OPCS4::Term"
Truth table0%0/3
A and B
A= ref $termB= ref $term eq "Medical::OPCS4::Term"
| |||||||||||||||||||||||||||||
| 289 | 0 | $search_term = $term->term; | |||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||
| 291 | 0 | $search_term = $term; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | return undef | ||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ( !$self->{parser}->graph->has_vertex( $search_term ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | return undef | ||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( !$self->{parser}->graph->is_predecessorful_vertex( $search_term) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 0 | my $ra_out = [ ]; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | my @predecessors = | ||||||||||||||||||||||||||||
| 303 | 0 | $self->{parser}->graph->all_predecessors( $search_term ); | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | foreach my $term ( @predecessors ) { | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | my $predecessor_description = | ||||||||||||||||||||||||||||
| 308 | 0 | $self->{parser}->graph->get_vertex_attribute( $term, 'description' ); | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | my $obj = | |||||||||||||||||||||||||||
| 311 | Medical::OPCS4::Term->new( | ||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||
| 313 | 'term' => $term, | ||||||||||||||||||||||||||||
| 314 | 'description' => $predecessor_description, | ||||||||||||||||||||||||||||
| 315 | }); | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | push( @$ra_out, $obj ); | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | return $ra_out; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | =head2 get_parent_terms_string | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | my $ra_parent_terms = $O->get_parent_terms_string( 'A809' ); | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | or | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | my $ra_parent_terms = $O->get_parent_terms_string( $Term ); | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | Returns a reference to an array of scalars of all parent terms | ||||||||||||||||||||||||||||
| 334 | of a given term. This method accepts both a scalar with the term name and | ||||||||||||||||||||||||||||
| 335 | a Medical::OPCS4::Term object as input. | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | =cut | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub get_parent_terms_string { | ||||||||||||||||||||||||||
|
Subroutine
get_parent_terms_string: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 342 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 343 | 0 | my $term = shift; | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | return undef | ||||||||||||||||||||||||||||
| 346 | 0 | ▶ | unless ( defined $term ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | my $ra_parent_terms = | |||||||||||||||||||||||||||
| 349 | $self->get_parent_terms( $term ); | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | return undef | ||||||||||||||||||||||||||||
| 352 | 0 | ▶ | unless ( defined $ra_parent_terms && scalar(@$ra_parent_terms) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
defined $ra_parent_terms and scalar @$ra_parent_terms
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
| |||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | my $ra_out = [ ]; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | foreach my $term ( @$ra_parent_terms ) { | |||||||||||||||||||||||||||
| 357 | 0 | push ( @$ra_out, $term->term ); | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | return $ra_out; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =head2 get_child_terms | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | my $ra_child_terms = $O->get_child_terms( 'A809' ); | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | or | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | my $ra_child_terms = $O->get_child_terms( $Term ); | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | Returns a reference to an array of Medical::OPCS4::Term objects of all child terms | ||||||||||||||||||||||||||||
| 374 | of a given term. This method accepts both a scalar with the term name and | ||||||||||||||||||||||||||||
| 375 | a Medical::OPCS4::Term object as input. | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | =cut | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 1 | ▶ | sub get_child_terms { | ||||||||||||||||||||||||||
|
Subroutine
get_child_terms: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||||||
| 382 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 383 | 1 | my $term = shift; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | return undef | ||||||||||||||||||||||||||||
| 386 | 1 | ▶ | unless ( defined $term ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 1 | my $search_term; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 1 | ▶ | if ( ref $term && ref $term eq 'Medical::OPCS4::Term' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $term and ref $term eq "Medical::OPCS4::Term"
MC/DC0%0/2
ref $term and ref $term eq "Medical::OPCS4::Term"
ref $term
ref $term eq "Medical::OPCS4::Term"
Truth table33%1/3
A and B
A= ref $termB= ref $term eq "Medical::OPCS4::Term"
| |||||||||||||||||||||||||||||
| 391 | 0 | $search_term = $term->term; | |||||||||||||||||||||||||||
| 392 | } else { | ||||||||||||||||||||||||||||
| 393 | 1 | $search_term = $term; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | return undef | ||||||||||||||||||||||||||||
| 397 | 1 | ▶ | if ( !$self->{parser}->graph->has_vertex( $search_term ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | return undef | ||||||||||||||||||||||||||||
| 400 | 1 | ▶ | if ( !$self->{parser}->graph->is_successorful_vertex( $search_term) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | my @successors = | ||||||||||||||||||||||||||||
| 403 | 1 | $self->{parser}->graph->all_successors( $search_term ); | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 1 | my $ra_out = [ ]; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 1 | foreach my $term ( @successors ) { | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | my $successor_description = | ||||||||||||||||||||||||||||
| 410 | 4 | $self->{parser}->graph->get_vertex_attribute( $term, 'description' ); | |||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 4 | my $obj = | |||||||||||||||||||||||||||
| 413 | Medical::OPCS4::Term->new( | ||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||
| 415 | 'term' => $term, | ||||||||||||||||||||||||||||
| 416 | 'description' => $successor_description, | ||||||||||||||||||||||||||||
| 417 | }); | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 4 | push( @$ra_out, $obj ); | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 1 | return $ra_out; | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =head2 get_child_terms_string | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | my $ra_child_terms = $O->get_child_terms_string( 'A809' ); | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | or | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | my $ra_child_terms = $O->get_child_terms_string( $Term ); | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | Returns a reference to an array of scalars of all child terms | ||||||||||||||||||||||||||||
| 436 | of a given term. This method accepts both a scalar with the term name and | ||||||||||||||||||||||||||||
| 437 | a Medical::OPCS4::Term object as input. | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | This method returns undef on error. | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =cut | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | ▶ | sub get_child_terms_string { | ||||||||||||||||||||||||||
|
Subroutine
get_child_terms_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 444 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 445 | 0 | my $term = shift; | |||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | return undef | ||||||||||||||||||||||||||||
| 448 | 0 | ▶ | unless ( defined $term ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 0 | my $ra_successor_terms = | |||||||||||||||||||||||||||
| 451 | $self->get_child_terms( $term ); | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 0 | return $self->_format_output( $ra_successor_terms, 'string' ); | |||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | =head2 _format_output | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | Internal method used to format the output from different methods. Do not | ||||||||||||||||||||||||||||
| 460 | use this method directly. | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | =cut | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | ▶ | sub _format_output { | ||||||||||||||||||||||||||
|
Subroutine
_format_output: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 465 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 466 | 0 | my $ra_data = shift; | |||||||||||||||||||||||||||
| 467 | 0 | my $mode = shift; | |||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 0 | my $ra_out = [ ]; | |||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ( $mode eq 'string' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 0 | foreach my $term ( @$ra_data ) { | |||||||||||||||||||||||||||
| 474 | 0 | push( @$ra_out, $term->term ); | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | elsif ( $mode eq 'objects' ) { | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 0 | foreach my $term ( @$ra_data ) { | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | my $description = | ||||||||||||||||||||||||||||
| 484 | 0 | $self->{parser}->graph->get_vertex_attribute( $term, 'description' ); | |||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 0 | my $obj = | |||||||||||||||||||||||||||
| 487 | Medical::OPCS4::Term->new( | ||||||||||||||||||||||||||||
| 488 | { | ||||||||||||||||||||||||||||
| 489 | 'term' => $term, | ||||||||||||||||||||||||||||
| 490 | 'description' => $description, | ||||||||||||||||||||||||||||
| 491 | }); | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 0 | push( @$ra_out, $obj ); | |||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 0 | return $ra_out; | |||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 1 | 1; # End of Medical::OPCS4 | |||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 1 | 1; | |||||||||||||||||||||||||||