| 1 | package XML::Parser::ClinicalTrials::Study; | ||||||||||
| 2 | { | ||||||||||
| 3 | 1 | $XML::Parser::ClinicalTrials::Study::VERSION = '1.20140111'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use constant PREFIX => 'XML::Parser::ClinicalTrials::Study'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use XML::Rabbit::Root; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use DateTime::Format::Natural; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | has_xpath_value nct_number => './id_info/nct_id'; | |||||||||
| 14 | 1 | has_xpath_value sponsor => './sponsors/lead_sponsor/agency'; | |||||||||
| 15 | 1 | has_xpath_value condition => './condition'; | |||||||||
| 16 | 1 | has_xpath_value study_design => './study_design'; | |||||||||
| 17 | 1 | has_xpath_value description_raw => './detailed_description/textblock'; | |||||||||
| 18 | 1 | has_xpath_value recruitment_status => './overall_status'; | |||||||||
| 19 | 1 | has_xpath_value source => './source'; | |||||||||
| 20 | 1 | has_xpath_value summary_raw => './brief_summary/textblock'; | |||||||||
| 21 | 1 | has_xpath_value type => './study_type'; | |||||||||
| 22 | 1 | has_xpath_value brief_title => './brief_title'; | |||||||||
| 23 | 1 | has_xpath_value official_title => './official_title'; | |||||||||
| 24 | 1 | has_xpath_value phase => './phase'; | |||||||||
| 25 | |||||||||||
| 26 | 1 | has_xpath_value start_date_raw => './start_date'; | |||||||||
| 27 | 1 | has_xpath_value last_changed_raw => './lastchanged_date'; | |||||||||
| 28 | 1 | has_xpath_value first_received_raw => './firstreceived_date'; | |||||||||
| 29 | 1 | has_xpath_value completion_date_raw => | |||||||||
| 30 | q|./completion_date[@type='Actual']|; | ||||||||||
| 31 | 1 | has_xpath_value estimated_completion_date_raw => | |||||||||
| 32 | q|./completion_date[@type='Anticipated']|; | ||||||||||
| 33 | 1 | has_xpath_value primary_completion_date_raw => | |||||||||
| 34 | q|./primary_completion_date[@type='Actual']|; | ||||||||||
| 35 | |||||||||||
| 36 | 1 | has_xpath_value actual_enrollment => q|./enrollment[@type='Actual']|; | |||||||||
| 37 | 1 | has_xpath_value estimated_enrollment => q|./enrollment[@type='Anticipated']|; | |||||||||
| 38 | |||||||||||
| 39 | 1 | has_xpath_value_list secondary_ids => | |||||||||
| 40 | './id_info/org_study_id|./id_info/secondary_id'; | ||||||||||
| 41 | |||||||||||
| 42 | 1 | has_xpath_value_list sponsors => | |||||||||
| 43 | './sponsors/lead_sponsor/agency|./sponsors/collaborator/agency'; | ||||||||||
| 44 | |||||||||||
| 45 | 1 | has_xpath_object_list link => './link' | |||||||||
| 46 | => PREFIX . '::Link'; | ||||||||||
| 47 | |||||||||||
| 48 | 1 | has_xpath_object_list interventions => | |||||||||
| 49 | './intervention' => PREFIX . '::Intervention'; | ||||||||||
| 50 | 1 | has_xpath_object_list design => | |||||||||
| 51 | './study_design' => PREFIX . '::Design'; | ||||||||||
| 52 | 1 | has_xpath_object_list mesh_terms => | |||||||||
| 53 | './condition_browse/mesh_term|./intervention_browse/mesh_term' | ||||||||||
| 54 | => PREFIX . '::MeSHTerm'; | ||||||||||
| 55 | |||||||||||
| 56 | 1 | has_xpath_object_list locations => './location' | |||||||||
| 57 | => PREFIX . '::Location'; | ||||||||||
| 58 | 1 | has_xpath_object_list contacts => './overall_contact|./overall_contact_backup' | |||||||||
| 59 | => PREFIX . '::Contact'; | ||||||||||
| 60 | |||||||||||
| 61 | 1 | has [qw( last_changed first_received start_date completion_date | |||||||||
| 62 | estimated_completion_date primary_completion_date )], is => 'rw'; | ||||||||||
| 63 | |||||||||||
| 64 | 1 | has 'summary', is => 'ro', lazy => 1, builder => '_build_summary'; | |||||||||
| 65 | 1 | has 'description', is => 'ro', lazy => 1, builder => '_build_description'; | |||||||||
| 66 | |||||||||||
| 67 | 1 | has 'normalized_phase', is => 'ro', lazy => 1, | |||||||||
| 68 | builder => '_build_normalized_phase'; | ||||||||||
| 69 | |||||||||||
| 70 | sub _build_summary { | ||||||||||
| 71 | 1 | ▶ | my $raw = $_[0]->summary_raw; | ||||||||
|
Subroutine
_build_summary: called CC=2 SCAR=7.0
| |||||||||||
| 72 | 1 | ▶ | return unless $raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | 1 | $raw =~ s/\s+/ /g; | |||||||||
| 75 | 1 | $raw =~ s/\n/ /g; | |||||||||
| 76 | 1 | $raw =~ s/\A\s+|\s+\Z//g; | |||||||||
| 77 | |||||||||||
| 78 | 1 | return $raw; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | sub _build_description { | ||||||||||
| 82 | 1 | ▶ | my $raw = $_[0]->description_raw; | ||||||||
|
Subroutine
_build_description: called CC=3 SCAR=11.0
| |||||||||||
| 83 | 1 | ▶ | return unless $raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | |||||||||||
| 85 | 1 | my @lines = split /\n\n/, $raw; | |||||||||
| 86 | |||||||||||
| 87 | do { | ||||||||||
| 88 | 3 | s/^\s+|\s+$//g; | |||||||||
| 89 | 3 | s/\s+/ /g; | |||||||||
| 90 | 1 | } for @lines; | |||||||||
| 91 | |||||||||||
| 92 | 1 | return join "\n\n", @lines; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | sub _build_normalized_phase { | ||||||||||
| 96 | 1 | ▶ | state $phases = { | ||||||||
|
Subroutine
_build_normalized_phase: called CC=2 SCAR=7.0
| |||||||||||
| 97 | 1 => 'I', | ||||||||||
| 98 | 2 => 'II', | ||||||||||
| 99 | 3 => 'III', | ||||||||||
| 100 | 4 => 'IV', | ||||||||||
| 101 | 5 => 'V', | ||||||||||
| 102 | }; | ||||||||||
| 103 | |||||||||||
| 104 | 1 | my $raw = $_[0]->phase; | |||||||||
| 105 | 1 | ▶ | return if $raw eq 'N/A'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | |||||||||||
| 107 | 1 | $raw =~ s/Phase (\d+)/$phases->{$1}/gi; | |||||||||
| 108 | |||||||||||
| 109 | 1 | return $raw; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 1 | has [qw( last_changed first_received start_date | |||||||||
| 113 | completion_date estimated_completion_date primary_completion_date )], | ||||||||||
| 114 | is => 'ro', lazy_build => 1; | ||||||||||
| 115 | |||||||||||
| 116 | 1 | ▶ | sub _build_last_changed { $_[0]->_normalize_date( 'last_changed_raw' ) } | ||||||||
|
Subroutine
_build_last_changed: called CC=1 SCAR=0.0
| |||||||||||
| 117 | 1 | ▶ | sub _build_first_received { $_[0]->_normalize_date( 'first_received_raw' ) } | ||||||||
|
Subroutine
_build_first_received: called CC=1 SCAR=0.0
| |||||||||||
| 118 | 2 | ▶ | sub _build_start_date { $_[0]->_normalize_date( 'start_date_raw' ) } | ||||||||
|
Subroutine
_build_start_date: called CC=1 SCAR=0.0
| |||||||||||
| 119 | 2 | ▶ | sub _build_completion_date { $_[0]->_normalize_date( 'completion_date_raw' ) } | ||||||||
|
Subroutine
_build_completion_date: called CC=1 SCAR=0.0
| |||||||||||
| 120 | |||||||||||
| 121 | sub _build_estimated_completion_date { | ||||||||||
| 122 | 0 | ▶ | $_[0]->_normalize_date( 'estimated_completion_date_raw' ) | ||||||||
|
Subroutine
_build_estimated_completion_date: not called CC=1 SCAR=6.9
| |||||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | sub _build_primary_completion_date { | ||||||||||
| 126 | 1 | ▶ | $_[0]->_normalize_date( 'primary_completion_date_raw' ) | ||||||||
|
Subroutine
_build_primary_completion_date: called CC=1 SCAR=0.0
| |||||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | sub _normalize_date { | ||||||||||
| 130 | 7 | ▶ | my ($self, $raw) = @_; | ||||||||
|
Subroutine
_normalize_date: called CC=2 SCAR=6.9
| |||||||||||
| 131 | 7 | my $value = $self->$raw; | |||||||||
| 132 | 7 | ▶ | return unless $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | |||||||||||
| 134 | 6 | return DateTime::Format::Natural->new->parse_datetime( $value )->ymd; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 1 | finalize_class(); | |||||||||
| 138 | |||||||||||
| 139 | __END__ | ||||||||||
| 140 | =pod | ||||||||||
| 141 | |||||||||||
| 142 | =head1 NAME | ||||||||||
| 143 | |||||||||||
| 144 | XML::Parser::ClinicalTrials::Study - XML parser/representation for ClinicalTrials.gov data | ||||||||||
| 145 | |||||||||||
| 146 | =head1 SYNOPSIS | ||||||||||
| 147 | |||||||||||
| 148 | use File::Slurp; | ||||||||||
| 149 | use XML::Parser::ClinicalTrials::Study; | ||||||||||
| 150 | |||||||||||
| 151 | # XML file downloaded from clinicaltrials.gov | ||||||||||
| 152 | my $xml = read_file( 'NCT00003095.xml', binmode => ':utf8' ); | ||||||||||
| 153 | my $study = XML::Parser::ClinicalTrials::Study->new( xml => $xml ); | ||||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | =head1 DESCRIPTION | ||||||||||
| 157 | |||||||||||
| 158 | The web site L<http://clinicaltrials.gov/> publishes information about | ||||||||||
| 159 | pharmaceutical clinical trials. This module parses the XML files available for | ||||||||||
| 160 | those trials into Moose objects with data accessors. For more details about the | ||||||||||
| 161 | contents of these files, see the glossary of CT.gov site terms at | ||||||||||
| 162 | L<http://www.clinicaltrials.gov/ct2/info/glossary>. | ||||||||||
| 163 | |||||||||||
| 164 | =head1 ACCESSORS | ||||||||||
| 165 | |||||||||||
| 166 | Study instances have several accessors, both simple value accessors and object | ||||||||||
| 167 | accessors. | ||||||||||
| 168 | |||||||||||
| 169 | =head2 Value Accessors | ||||||||||
| 170 | |||||||||||
| 171 | These accessors provide simple values. When a value is not present in the XML | ||||||||||
| 172 | file, this accessor will return the empty string. | ||||||||||
| 173 | |||||||||||
| 174 | =over 4 | ||||||||||
| 175 | |||||||||||
| 176 | =item * nct_number | ||||||||||
| 177 | |||||||||||
| 178 | =item * sponsor | ||||||||||
| 179 | |||||||||||
| 180 | =item * condition | ||||||||||
| 181 | |||||||||||
| 182 | =item * study_design | ||||||||||
| 183 | |||||||||||
| 184 | =item * description | ||||||||||
| 185 | |||||||||||
| 186 | =item * recruitment_status | ||||||||||
| 187 | |||||||||||
| 188 | =item * source | ||||||||||
| 189 | |||||||||||
| 190 | =item * summary | ||||||||||
| 191 | |||||||||||
| 192 | =item * type | ||||||||||
| 193 | |||||||||||
| 194 | =item * brief_title | ||||||||||
| 195 | |||||||||||
| 196 | =item * official_title | ||||||||||
| 197 | |||||||||||
| 198 | =item * phase | ||||||||||
| 199 | |||||||||||
| 200 | =item * start_date | ||||||||||
| 201 | |||||||||||
| 202 | =item * last_changed | ||||||||||
| 203 | |||||||||||
| 204 | =item * first_received | ||||||||||
| 205 | |||||||||||
| 206 | =item * completion_date | ||||||||||
| 207 | |||||||||||
| 208 | =item * estimated_completion_date | ||||||||||
| 209 | |||||||||||
| 210 | =item * primary_completion_date | ||||||||||
| 211 | |||||||||||
| 212 | =item * actual_enrollment | ||||||||||
| 213 | |||||||||||
| 214 | =item * estimated_enrollment | ||||||||||
| 215 | |||||||||||
| 216 | =item * normalized_phase | ||||||||||
| 217 | |||||||||||
| 218 | =back | ||||||||||
| 219 | |||||||||||
| 220 | =head2 Object Accessors | ||||||||||
| 221 | |||||||||||
| 222 | These accessors provide array references of other Moose objects with their own | ||||||||||
| 223 | accessors. Where a value is not present in the source XML file, the returned | ||||||||||
| 224 | array reference will be empty. | ||||||||||
| 225 | |||||||||||
| 226 | =over 4 | ||||||||||
| 227 | |||||||||||
| 228 | =item * link | ||||||||||
| 229 | |||||||||||
| 230 | An array reference of L<XML::Parser::ClinicalTrials::Study::Link> objects. | ||||||||||
| 231 | |||||||||||
| 232 | =item * interventions | ||||||||||
| 233 | |||||||||||
| 234 | An array reference of L<XML::Parser::ClinicalTrials::Study::Intervention> | ||||||||||
| 235 | objects. | ||||||||||
| 236 | |||||||||||
| 237 | =item * design | ||||||||||
| 238 | |||||||||||
| 239 | An array reference of L<XML::Parser::ClinicalTrials::Study::Design> objects. | ||||||||||
| 240 | |||||||||||
| 241 | =item * mesh_terms | ||||||||||
| 242 | |||||||||||
| 243 | An array reference of L<XML::Parser::ClinicalTrials::Study::MeSHTerm> objects. | ||||||||||
| 244 | |||||||||||
| 245 | =item * locations | ||||||||||
| 246 | |||||||||||
| 247 | An array reference of L<XML::Parser::ClinicalTrials::Study::Location> objects. | ||||||||||
| 248 | |||||||||||
| 249 | =item * contacts | ||||||||||
| 250 | |||||||||||
| 251 | An array reference of L<XML::Parser::ClinicalTrials::Study::Contact> objects. | ||||||||||
| 252 | |||||||||||
| 253 | =back | ||||||||||
| 254 | |||||||||||
| 255 | =head1 NOTES | ||||||||||
| 256 | |||||||||||
| 257 | These modules don't represent I<all> of the data found in CT.gov XML files. | ||||||||||
| 258 | Patches welcome. | ||||||||||
| 259 | |||||||||||
| 260 | =head1 AUTHOR | ||||||||||
| 261 | |||||||||||
| 262 | chromatic E<lt>chromatic@cpan.orgE<gt>, sponsored by Golden Guru | ||||||||||
| 263 | (L<http://goldenguru.com/>). | ||||||||||
| 264 | |||||||||||
| 265 | =head1 SEE ALSO | ||||||||||
| 266 | |||||||||||
| 267 | L<XML::Rabbit>, L<WebService::ClinicalTrialsdotGov> | ||||||||||
| 268 | |||||||||||
| 269 | =head1 LICENSE | ||||||||||
| 270 | |||||||||||
| 271 | This library is free software; you can redistribute it and/or modify it under | ||||||||||
| 272 | the terms of the Artistic License, version 2. | ||||||||||