File Coverage

blib/lib/XML/Parser/ClinicalTrials/Study.pm
Criterion Covered Total %
statement 6 8 75.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 9 11 81.8


line stmt bran cond sub pod time code
1             package XML::Parser::ClinicalTrials::Study;
2             $XML::Parser::ClinicalTrials::Study::VERSION = '1.20150818';
3 1     1   3450725 use 5.010;
  1         33  
4              
5 1     1   5 use constant PREFIX => 'XML::Parser::ClinicalTrials::Study';
  1         1  
  1         53  
6              
7 1     1   1150 use XML::Rabbit::Root;
  0            
  0            
8             use DateTime::Format::Natural;
9              
10             has_xpath_value nct_number => './id_info/nct_id';
11             has_xpath_value sponsor => './sponsors/lead_sponsor/agency';
12             has_xpath_value condition => './condition';
13             has_xpath_value study_design => './study_design';
14             has_xpath_value description_raw => './detailed_description/textblock';
15             has_xpath_value recruitment_status => './overall_status';
16             has_xpath_value source => './source';
17             has_xpath_value summary_raw => './brief_summary/textblock';
18             has_xpath_value type => './study_type';
19             has_xpath_value brief_title => './brief_title';
20             has_xpath_value official_title => './official_title';
21             has_xpath_value phase => './phase';
22              
23             has_xpath_value start_date_raw => './start_date';
24             has_xpath_value last_changed_raw => './lastchanged_date';
25             has_xpath_value first_received_raw => './firstreceived_date';
26             has_xpath_value completion_date_raw =>
27             q|./completion_date[@type='Actual']|;
28             has_xpath_value estimated_completion_date_raw =>
29             q|./completion_date[@type='Anticipated']|;
30             has_xpath_value primary_completion_date_raw =>
31             q|./primary_completion_date[@type='Actual']|;
32              
33             has_xpath_value actual_enrollment => q|./enrollment[@type='Actual']|;
34             has_xpath_value estimated_enrollment => q|./enrollment[@type='Anticipated']|;
35              
36             has_xpath_value_list secondary_ids =>
37             './id_info/org_study_id|./id_info/secondary_id';
38              
39             has_xpath_value_list sponsors =>
40             './sponsors/lead_sponsor/agency|./sponsors/collaborator/agency';
41              
42             has_xpath_object_list link => './link'
43             => PREFIX . '::Link';
44              
45             has_xpath_object_list interventions =>
46             './intervention' => PREFIX . '::Intervention';
47             has_xpath_object_list design =>
48             './study_design' => PREFIX . '::Design';
49             has_xpath_object_list mesh_terms =>
50             './condition_browse/mesh_term|./intervention_browse/mesh_term'
51             => PREFIX . '::MeSHTerm';
52              
53             has_xpath_object_list locations => './location'
54             => PREFIX . '::Location';
55             has_xpath_object_list contacts => './overall_contact|./overall_contact_backup'
56             => PREFIX . '::Contact';
57              
58             has [qw( last_changed first_received start_date completion_date
59             estimated_completion_date primary_completion_date )], is => 'rw';
60              
61             has 'summary', is => 'ro', lazy => 1, builder => '_build_summary';
62             has 'description', is => 'ro', lazy => 1, builder => '_build_description';
63              
64             has 'normalized_phase', is => 'ro', lazy => 1,
65             builder => '_build_normalized_phase';
66              
67             sub _build_summary {
68             my $raw = $_[0]->summary_raw;
69             return unless $raw;
70              
71             $raw =~ s/\s+/ /g;
72             $raw =~ s/\n/ /g;
73             $raw =~ s/\A\s+|\s+\Z//g;
74              
75             return $raw;
76             }
77              
78             sub _build_description {
79             my $raw = $_[0]->description_raw;
80             return unless $raw;
81              
82             my @lines = split /\n\n/, $raw;
83              
84             do {
85             s/^\s+|\s+$//g;
86             s/\s+/ /g;
87             } for @lines;
88              
89             return join "\n\n", @lines;
90             }
91              
92             sub _build_normalized_phase {
93             state $phases = {
94             1 => 'I',
95             2 => 'II',
96             3 => 'III',
97             4 => 'IV',
98             5 => 'V',
99             };
100              
101             my $raw = $_[0]->phase;
102             return if $raw eq 'N/A';
103              
104             $raw =~ s/Phase (\d+)/$phases->{$1}/gi;
105              
106             return $raw;
107             }
108              
109             has [qw( last_changed first_received start_date
110             completion_date estimated_completion_date primary_completion_date )],
111             is => 'ro', lazy_build => 1;
112              
113             sub _build_last_changed { $_[0]->_normalize_date( 'last_changed_raw' ) }
114             sub _build_first_received { $_[0]->_normalize_date( 'first_received_raw' ) }
115             sub _build_start_date { $_[0]->_normalize_date( 'start_date_raw' ) }
116             sub _build_completion_date { $_[0]->_normalize_date( 'completion_date_raw' ) }
117              
118             sub _build_estimated_completion_date {
119             $_[0]->_normalize_date( 'estimated_completion_date_raw' )
120             }
121              
122             sub _build_primary_completion_date {
123             $_[0]->_normalize_date( 'primary_completion_date_raw' )
124             }
125              
126             sub _normalize_date {
127             my ($self, $raw) = @_;
128             my $value = $self->$raw;
129             return unless $value;
130              
131             return DateTime::Format::Natural->new->parse_datetime( $value )->ymd;
132             }
133              
134             finalize_class();
135              
136             __END__