| 1 | package Convert::Pheno::CDISC::ODM::V1; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 136 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 136 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 136 | ▶ | use Convert::Pheno::CDISC::ODM::Detector qw(attribute_by_namespace); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 136 | ▶ | use Convert::Pheno::CDISC::ODM::Record; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 136 | ▶ | use Convert::Pheno::CDISC::ODM::Util qw(as_array attr children); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | sub parse_records { | ||||||||||||||||||||||||||
|
Subroutine
parse_records: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 7 | my ( $class, $descriptor, %arg ) = @_; | |||||||||||||||||||||||||||
| 12 | 7 | my @records; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 7 | for my $clinical_data ( @{ children( $descriptor->{root}, 'ClinicalData' ) } ) { | |||||||||||||||||||||||||||
| 15 | 7 | my $study_oid = _required_attr( $clinical_data, 'StudyOID', 'ClinicalData' ); | |||||||||||||||||||||||||||
| 16 | 7 | my $metadata_oid = _required_attr( | |||||||||||||||||||||||||||
| 17 | $clinical_data, | ||||||||||||||||||||||||||||
| 18 | 'MetaDataVersionOID', | ||||||||||||||||||||||||||||
| 19 | 'ClinicalData', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | 7 | my $metadata = _metadata_provider( | |||||||||||||||||||||||||||
| 22 | $descriptor, | ||||||||||||||||||||||||||||
| 23 | \%arg, | ||||||||||||||||||||||||||||
| 24 | $study_oid, | ||||||||||||||||||||||||||||
| 25 | $metadata_oid, | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | for my $subject ( @{ children( $clinical_data, 'SubjectData' ) } ) { | |||||||||||||||||||||||||||
| 29 | 49 | my $subject_key = _required_attr( $subject, 'SubjectKey', 'SubjectData' ); | |||||||||||||||||||||||||||
| 30 | 49 | my @events = @{ children( $subject, 'StudyEventData' ) }; | |||||||||||||||||||||||||||
| 31 | 49 | ▶ | die "CDISC-ODM SubjectData <SubjectKey=$subject_key> has no StudyEventData\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | unless @events; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 49 | for my $event (@events) { | |||||||||||||||||||||||||||
| 35 | 217 | push @records, _event_record( | |||||||||||||||||||||||||||
| 36 | $descriptor, | ||||||||||||||||||||||||||||
| 37 | $metadata, | ||||||||||||||||||||||||||||
| 38 | $study_oid, | ||||||||||||||||||||||||||||
| 39 | $metadata_oid, | ||||||||||||||||||||||||||||
| 40 | $subject, | ||||||||||||||||||||||||||||
| 41 | $subject_key, | ||||||||||||||||||||||||||||
| 42 | $event, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 7 | ▶ | die "CDISC-ODM input contains no subject-event records\n" unless @records; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 7 | return \@records; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 217 | ▶ | sub _event_record { | ||||||||||||||||||||||||||
|
Subroutine
_event_record: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 53 | my ( | ||||||||||||||||||||||||||||
| 54 | 217 | $descriptor, $metadata, $study_oid, $metadata_oid, | |||||||||||||||||||||||||||
| 55 | $subject, $subject_key, $event, | ||||||||||||||||||||||||||||
| 56 | ) = @_; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 217 | my $event_oid = _required_attr( $event, 'StudyEventOID', 'StudyEventData' ); | |||||||||||||||||||||||||||
| 59 | 217 | my $event_repeat = attr( $event, 'StudyEventRepeatKey' ); | |||||||||||||||||||||||||||
| 60 | 217 | my ( $context, $context_order ) = _record_context( | |||||||||||||||||||||||||||
| 61 | $descriptor, | ||||||||||||||||||||||||||||
| 62 | $subject, | ||||||||||||||||||||||||||||
| 63 | $subject_key, | ||||||||||||||||||||||||||||
| 64 | $event, | ||||||||||||||||||||||||||||
| 65 | $event_oid, | ||||||||||||||||||||||||||||
| 66 | $event_repeat, | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 217 | my @groups; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 217 | for my $form ( @{ children( $event, 'FormData' ) } ) { | |||||||||||||||||||||||||||
| 71 | 1315 | my $form_oid = _required_attr( $form, 'FormOID', 'FormData' ); | |||||||||||||||||||||||||||
| 72 | 1315 | my $form_repeat = attr( $form, 'FormRepeatKey' ); | |||||||||||||||||||||||||||
| 73 | 1315 | my $form_scope = _scope_part( 'form', $form_oid, $form_repeat ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1315 | for my $group ( @{ children( $form, 'ItemGroupData' ) } ) { | |||||||||||||||||||||||||||
| 76 | 9975 | my $group_oid = _required_attr( | |||||||||||||||||||||||||||
| 77 | $group, | ||||||||||||||||||||||||||||
| 78 | 'ItemGroupOID', | ||||||||||||||||||||||||||||
| 79 | 'ItemGroupData', | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | 9975 | my $group_repeat = attr( $group, 'ItemGroupRepeatKey' ); | |||||||||||||||||||||||||||
| 82 | 9975 | my $group_seq = _item_group_data_seq( $group, $descriptor ); | |||||||||||||||||||||||||||
| 83 | 9975 | my $group_scope = _scope_part( | |||||||||||||||||||||||||||
| 84 | 'itemGroup', | ||||||||||||||||||||||||||||
| 85 | $group_oid, | ||||||||||||||||||||||||||||
| 86 | $group_repeat, | ||||||||||||||||||||||||||||
| 87 | $group_seq, | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 9975 | push @groups, { | |||||||||||||||||||||||||||
| 91 | context => { | ||||||||||||||||||||||||||||
| 92 | studyOID => $study_oid, | ||||||||||||||||||||||||||||
| 93 | metaDataVersionOID => $metadata_oid, | ||||||||||||||||||||||||||||
| 94 | subjectKey => $subject_key, | ||||||||||||||||||||||||||||
| 95 | studyEventOID => $event_oid, | ||||||||||||||||||||||||||||
| 96 | studyEventRepeatKey => $event_repeat, | ||||||||||||||||||||||||||||
| 97 | formOID => $form_oid, | ||||||||||||||||||||||||||||
| 98 | formRepeatKey => $form_repeat, | ||||||||||||||||||||||||||||
| 99 | itemGroupOID => $group_oid, | ||||||||||||||||||||||||||||
| 100 | itemGroupRepeatKey => $group_repeat, | ||||||||||||||||||||||||||||
| 101 | itemGroupDataSeq => $group_seq, | ||||||||||||||||||||||||||||
| 102 | }, | ||||||||||||||||||||||||||||
| 103 | scopePath => [ $form_scope, $group_scope ], | ||||||||||||||||||||||||||||
| 104 | items => _v1_items($group), | ||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 217 | ▶ | die "CDISC-ODM StudyEventData <StudyEventOID=$event_oid> contains no ItemGroupData\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | unless @groups; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | return Convert::Pheno::CDISC::ODM::Record->new( | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | context => $context, | ||||||||||||||||||||||||||||
| 115 | context_order => $context_order, | ||||||||||||||||||||||||||||
| 116 | descriptor => _record_descriptor($descriptor), | ||||||||||||||||||||||||||||
| 117 | groups => \@groups, | ||||||||||||||||||||||||||||
| 118 | metadata => $metadata, | ||||||||||||||||||||||||||||
| 119 | record_profile => $descriptor->{recordProfile}, | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 217 | ); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 217 | ▶ | sub _record_context { | ||||||||||||||||||||||||||
|
Subroutine
_record_context: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||
| 125 | my ( | ||||||||||||||||||||||||||||
| 126 | 217 | $descriptor, $subject, $subject_key, $event, $event_oid, | |||||||||||||||||||||||||||
| 127 | $event_repeat, | ||||||||||||||||||||||||||||
| 128 | ) = @_; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 217 | ▶ | if ( $descriptor->{recordProfile} eq 'redcap' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | my $event_name = attribute_by_namespace( | ||||||||||||||||||||||||||||
| 132 | $event, | ||||||||||||||||||||||||||||
| 133 | $descriptor->{namespaces}, | ||||||||||||||||||||||||||||
| 134 | 216 | qr{projectredcap\.org}i, | |||||||||||||||||||||||||||
| 135 | 'UniqueEventName', | ||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||
| 137 | return ( | ||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 216 | study_id => $subject_key, | |||||||||||||||||||||||||||
| 140 | redcap_event_name => $event_name, | ||||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||
| 142 | [qw(study_id redcap_event_name)], | ||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | my $subject_id = attribute_by_namespace( | ||||||||||||||||||||||||||||
| 147 | $subject, | ||||||||||||||||||||||||||||
| 148 | $descriptor->{namespaces}, | ||||||||||||||||||||||||||||
| 149 | 1 | qr{openclinica}i, | |||||||||||||||||||||||||||
| 150 | 'StudySubjectID', | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | 1 | ▶ | $subject_id = attr( $subject, 'StudySubjectID' ) unless defined $subject_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 1 | ▶ | $subject_id = $subject_key unless defined $subject_id && length $subject_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $subject_id and length $subject_id
MC/DC0%0/2
defined $subject_id and length $subject_id
defined $subject_id
length $subject_id
Truth table33%1/3
A and B
A= defined $subject_idB= length $subject_id
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | return ( | ||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||
| 157 | 1 | subjectId => $subject_id, | |||||||||||||||||||||||||||
| 158 | subjectKey => $subject_key, | ||||||||||||||||||||||||||||
| 159 | studyEventOID => $event_oid, | ||||||||||||||||||||||||||||
| 160 | studyEventRepeatKey => $event_repeat, | ||||||||||||||||||||||||||||
| 161 | }, | ||||||||||||||||||||||||||||
| 162 | [qw(subjectId subjectKey studyEventOID studyEventRepeatKey)], | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 9975 | ▶ | sub _v1_items { | ||||||||||||||||||||||||||
|
Subroutine
_v1_items: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 167 | 9975 | my ($group) = @_; | |||||||||||||||||||||||||||
| 168 | 9975 | my @items; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 9975 | for my $key ( sort keys %{$group} ) { | |||||||||||||||||||||||||||
| 171 | 29925 | ( my $local_name = $key ) =~ s/^.*://; | |||||||||||||||||||||||||||
| 172 | 29925 | ▶ | next unless $local_name =~ /\AItemData(?:[A-Z]\w*)?\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 9975 | for my $item ( @{ as_array( $group->{$key} ) } ) { | |||||||||||||||||||||||||||
| 175 | 70304 | ▶ | next unless ref($item) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 70304 | push @items, { | |||||||||||||||||||||||||||
| 177 | itemOID => attr( $item, 'ItemOID' ), | ||||||||||||||||||||||||||||
| 178 | value => attr( $item, 'Value' ), | ||||||||||||||||||||||||||||
| 179 | }; | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 9975 | return \@items; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 9975 | ▶ | sub _item_group_data_seq { | ||||||||||||||||||||||||||
|
Subroutine
_item_group_data_seq: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 186 | 9975 | my ( $group, $descriptor ) = @_; | |||||||||||||||||||||||||||
| 187 | 9975 | my $plain = attr( $group, 'ItemGroupDataSeq' ); | |||||||||||||||||||||||||||
| 188 | 9975 | ▶ | return $plain if defined $plain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | return attribute_by_namespace( | ||||||||||||||||||||||||||||
| 190 | $group, | ||||||||||||||||||||||||||||
| 191 | $descriptor->{namespaces}, | ||||||||||||||||||||||||||||
| 192 | 9975 | qr{Dataset-XML}i, | |||||||||||||||||||||||||||
| 193 | 'ItemGroupDataSeq', | ||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 7 | ▶ | sub _metadata_provider { | ||||||||||||||||||||||||||
|
Subroutine
_metadata_provider: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 198 | 7 | my ( $descriptor, $arg, $study_oid, $metadata_oid ) = @_; | |||||||||||||||||||||||||||
| 199 | 7 | ▶ | return $arg->{metadata} if $descriptor->{recordProfile} eq 'redcap'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 1 | return $arg->{metadata_catalog}->provider_for( $study_oid, $metadata_oid ); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 217 | ▶ | sub _record_descriptor { | ||||||||||||||||||||||||||
|
Subroutine
_record_descriptor: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 204 | 217 | my ($descriptor) = @_; | |||||||||||||||||||||||||||
| 205 | return { | ||||||||||||||||||||||||||||
| 206 | odmVersion => $descriptor->{odmVersion}, | ||||||||||||||||||||||||||||
| 207 | sourceSystem => $descriptor->{sourceSystem}, | ||||||||||||||||||||||||||||
| 208 | vendor => $descriptor->{vendor}, | ||||||||||||||||||||||||||||
| 209 | 217 | }; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 11290 | ▶ | sub _scope_part { | ||||||||||||||||||||||||||
|
Subroutine
_scope_part: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 213 | 11290 | my ( $kind, @parts ) = @_; | |||||||||||||||||||||||||||
| 214 | 11290 | ▶ | return join "\x1f", $kind, map { defined $_ ? $_ : q{} } @parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 11570 | ▶ | sub _required_attr { | ||||||||||||||||||||||||||
|
Subroutine
_required_attr: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 218 | 11570 | my ( $node, $name, $element ) = @_; | |||||||||||||||||||||||||||
| 219 | 11570 | my $value = attr( $node, $name ); | |||||||||||||||||||||||||||
| 220 | 11570 | ▶ | die "CDISC-ODM <$element> is missing required attribute <$name>\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||
| 221 | unless defined $value && length $value; | ||||||||||||||||||||||||||||
| 222 | 11570 | return $value; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 136 | 1; | |||||||||||||||||||||||||||