| 1 | package Convert::Pheno::CDISC::ODM::V2; | ||||||||||||||||||||||||||||
| 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(attr children element_text); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | sub parse_records { | ||||||||||||||||||||||||||
|
Subroutine
parse_records: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 3 | my ( $class, $descriptor, %arg ) = @_; | |||||||||||||||||||||||||||
| 12 | 3 | my @records; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | for my $clinical_data ( @{ children( $descriptor->{root}, 'ClinicalData' ) } ) { | |||||||||||||||||||||||||||
| 15 | 3 | my $study_oid = _required_attr( $clinical_data, 'StudyOID', 'ClinicalData' ); | |||||||||||||||||||||||||||
| 16 | 3 | my $metadata_oid = _required_attr( | |||||||||||||||||||||||||||
| 17 | $clinical_data, | ||||||||||||||||||||||||||||
| 18 | 'MetaDataVersionOID', | ||||||||||||||||||||||||||||
| 19 | 'ClinicalData', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | my $metadata = $descriptor->{recordProfile} eq 'redcap' | ||||||||||||||||||||||||||||
| 22 | ? $arg{metadata} | ||||||||||||||||||||||||||||
| 23 | : $arg{metadata_catalog}->provider_for( | ||||||||||||||||||||||||||||
| 24 | 3 | ▶ | $study_oid, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | $metadata_oid, | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | for my $subject ( @{ children( $clinical_data, 'SubjectData' ) } ) { | |||||||||||||||||||||||||||
| 29 | 3 | my $subject_key = _required_attr( $subject, 'SubjectKey', 'SubjectData' ); | |||||||||||||||||||||||||||
| 30 | 3 | my @events = @{ children( $subject, 'StudyEventData' ) }; | |||||||||||||||||||||||||||
| 31 | 3 | ▶ | die "CDISC-ODM SubjectData <SubjectKey=$subject_key> has no StudyEventData\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | unless @events; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | for my $event (@events) { | |||||||||||||||||||||||||||
| 35 | 3 | 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 | 2 | ▶ | die "CDISC-ODM input contains no subject-event records\n" unless @records; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | return \@records; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | sub _event_record { | ||||||||||||||||||||||||||
|
Subroutine
_event_record: called CC=7 SCAR=21.2
| |||||||||||||||||||||||||||||
| 53 | my ( | ||||||||||||||||||||||||||||
| 54 | 3 | $descriptor, $metadata, $study_oid, $metadata_oid, | |||||||||||||||||||||||||||
| 55 | $subject, $subject_key, $event, | ||||||||||||||||||||||||||||
| 56 | ) = @_; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | my $event_oid = _required_attr( $event, 'StudyEventOID', 'StudyEventData' ); | |||||||||||||||||||||||||||
| 59 | 3 | my $event_repeat = attr( $event, 'StudyEventRepeatKey' ); | |||||||||||||||||||||||||||
| 60 | 3 | my ( $context, $context_order ); | |||||||||||||||||||||||||||
| 61 | 3 | ▶ | if ( $descriptor->{recordProfile} eq 'redcap' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | my $event_name = attribute_by_namespace( | ||||||||||||||||||||||||||||
| 63 | $event, | ||||||||||||||||||||||||||||
| 64 | $descriptor->{namespaces}, | ||||||||||||||||||||||||||||
| 65 | 0 | qr{projectredcap\.org}i, | |||||||||||||||||||||||||||
| 66 | 'UniqueEventName', | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 0 | $context = { | |||||||||||||||||||||||||||
| 69 | study_id => $subject_key, | ||||||||||||||||||||||||||||
| 70 | redcap_event_name => $event_name, | ||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||
| 72 | 0 | $context_order = [qw(study_id redcap_event_name)]; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||
| 75 | my $subject_id = attribute_by_namespace( | ||||||||||||||||||||||||||||
| 76 | $subject, | ||||||||||||||||||||||||||||
| 77 | $descriptor->{namespaces}, | ||||||||||||||||||||||||||||
| 78 | 3 | qr{openclinica}i, | |||||||||||||||||||||||||||
| 79 | 'StudySubjectID', | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | 3 | ▶ | $subject_id = attr( $subject, 'StudySubjectID' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | unless defined $subject_id; | ||||||||||||||||||||||||||||
| 83 | 3 | ▶ | $subject_id = $subject_key | ||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||
| 84 | unless defined $subject_id && length $subject_id; | ||||||||||||||||||||||||||||
| 85 | 3 | $context = { | |||||||||||||||||||||||||||
| 86 | subjectId => $subject_id, | ||||||||||||||||||||||||||||
| 87 | subjectKey => $subject_key, | ||||||||||||||||||||||||||||
| 88 | studyEventOID => $event_oid, | ||||||||||||||||||||||||||||
| 89 | studyEventRepeatKey => $event_repeat, | ||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||
| 91 | 3 | $context_order = [ | |||||||||||||||||||||||||||
| 92 | qw(subjectId subjectKey studyEventOID studyEventRepeatKey) | ||||||||||||||||||||||||||||
| 93 | ]; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | my @groups; | |||||||||||||||||||||||||||
| 97 | 3 | for my $group ( @{ children( $event, 'ItemGroupData' ) } ) { | |||||||||||||||||||||||||||
| 98 | 7 | _collect_group( | |||||||||||||||||||||||||||
| 99 | \@groups, | ||||||||||||||||||||||||||||
| 100 | $group, | ||||||||||||||||||||||||||||
| 101 | [], | ||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | studyOID => $study_oid, | ||||||||||||||||||||||||||||
| 104 | metaDataVersionOID => $metadata_oid, | ||||||||||||||||||||||||||||
| 105 | subjectKey => $subject_key, | ||||||||||||||||||||||||||||
| 106 | studyEventOID => $event_oid, | ||||||||||||||||||||||||||||
| 107 | studyEventRepeatKey => $event_repeat, | ||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | ▶ | die "CDISC-ODM StudyEventData <StudyEventOID=$event_oid> contains no ItemGroupData\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | unless @groups; | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | return Convert::Pheno::CDISC::ODM::Record->new( | ||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | context => $context, | ||||||||||||||||||||||||||||
| 118 | context_order => $context_order, | ||||||||||||||||||||||||||||
| 119 | descriptor => { | ||||||||||||||||||||||||||||
| 120 | odmVersion => $descriptor->{odmVersion}, | ||||||||||||||||||||||||||||
| 121 | sourceSystem => $descriptor->{sourceSystem}, | ||||||||||||||||||||||||||||
| 122 | vendor => $descriptor->{vendor}, | ||||||||||||||||||||||||||||
| 123 | }, | ||||||||||||||||||||||||||||
| 124 | groups => \@groups, | ||||||||||||||||||||||||||||
| 125 | metadata => $metadata, | ||||||||||||||||||||||||||||
| 126 | record_profile => $descriptor->{recordProfile}, | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 2 | ); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 9 | ▶ | sub _collect_group { | ||||||||||||||||||||||||||
|
Subroutine
_collect_group: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 132 | 9 | my ( $out, $group, $parent_path, $base_context ) = @_; | |||||||||||||||||||||||||||
| 133 | 9 | my $group_oid = _required_attr( $group, 'ItemGroupOID', 'ItemGroupData' ); | |||||||||||||||||||||||||||
| 134 | 9 | my $group_repeat = attr( $group, 'ItemGroupRepeatKey' ); | |||||||||||||||||||||||||||
| 135 | 9 | my $group_seq = attr( $group, 'ItemGroupDataSeq' ); | |||||||||||||||||||||||||||
| 136 | 9 | my $scope = _scope_part( | |||||||||||||||||||||||||||
| 137 | 'itemGroup', | ||||||||||||||||||||||||||||
| 138 | $group_oid, | ||||||||||||||||||||||||||||
| 139 | $group_repeat, | ||||||||||||||||||||||||||||
| 140 | $group_seq, | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | 9 | my @scope_path = ( @{$parent_path}, $scope ); | |||||||||||||||||||||||||||
| 143 | my @path_labels = map { | ||||||||||||||||||||||||||||
| 144 | 9 | my ( undef, $oid, $repeat, $seq ) = split /\x1f/, $_, -1; | |||||||||||||||||||||||||||
| 145 | 11 | my $label = $oid; | |||||||||||||||||||||||||||
| 146 | 11 | ▶ | $label .= "[$repeat]" if defined $repeat && length $repeat; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $repeat and length $repeat
MC/DC50%1/2
defined $repeat and length $repeat
defined $repeat
length $repeat
Truth table66%2/3
A and B
A= defined $repeatB= length $repeat
| |||||||||||||||||||||||||||||
| 147 | 11 | ▶ | $label .= "#$seq" if defined $seq && length $seq; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $seq and length $seq
MC/DC50%1/2
defined $seq and length $seq
defined $seq
length $seq
Truth table66%2/3
A and B
A= defined $seqB= length $seq
| |||||||||||||||||||||||||||||
| 148 | 11 | $label; | |||||||||||||||||||||||||||
| 149 | } @scope_path; | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 9 | my @items; | |||||||||||||||||||||||||||
| 152 | 9 | for my $item ( @{ children( $group, 'ItemData' ) } ) { | |||||||||||||||||||||||||||
| 153 | 19 | my $item_oid = _required_attr( $item, 'ItemOID', 'ItemData' ); | |||||||||||||||||||||||||||
| 154 | 19 | my @values = @{ children( $item, 'Value' ) }; | |||||||||||||||||||||||||||
| 155 | 19 | ▶ | die "CDISC-ODM 2.0 ItemData <ItemOID=$item_oid> contains multiple Value elements; this conversion requires one scalar value per item occurrence\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | if @values > 1; | ||||||||||||||||||||||||||||
| 157 | 18 | ▶ | push @items, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | itemOID => $item_oid, | ||||||||||||||||||||||||||||
| 159 | value => @values ? element_text( $values[0] ) : undef, | ||||||||||||||||||||||||||||
| 160 | }; | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 8 | push @{$out}, { | |||||||||||||||||||||||||||
| 164 | context => { | ||||||||||||||||||||||||||||
| 165 | 8 | %{$base_context}, | |||||||||||||||||||||||||||
| 166 | itemGroupOID => $group_oid, | ||||||||||||||||||||||||||||
| 167 | itemGroupRepeatKey => $group_repeat, | ||||||||||||||||||||||||||||
| 168 | itemGroupDataSeq => $group_seq, | ||||||||||||||||||||||||||||
| 169 | itemGroupPath => join( '/', @path_labels ), | ||||||||||||||||||||||||||||
| 170 | }, | ||||||||||||||||||||||||||||
| 171 | scopePath => \@scope_path, | ||||||||||||||||||||||||||||
| 172 | items => \@items, | ||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 8 | for my $nested ( @{ children( $group, 'ItemGroupData' ) } ) { | |||||||||||||||||||||||||||
| 176 | 2 | _collect_group( | |||||||||||||||||||||||||||
| 177 | $out, | ||||||||||||||||||||||||||||
| 178 | $nested, | ||||||||||||||||||||||||||||
| 179 | \@scope_path, | ||||||||||||||||||||||||||||
| 180 | $base_context, | ||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 8 | return; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 9 | ▶ | sub _scope_part { | ||||||||||||||||||||||||||
|
Subroutine
_scope_part: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 187 | 9 | my ( $kind, @parts ) = @_; | |||||||||||||||||||||||||||
| 188 | 9 | ▶ | return join "\x1f", $kind, map { defined $_ ? $_ : q{} } @parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 40 | ▶ | sub _required_attr { | ||||||||||||||||||||||||||
|
Subroutine
_required_attr: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 192 | 40 | my ( $node, $name, $element ) = @_; | |||||||||||||||||||||||||||
| 193 | 40 | my $value = attr( $node, $name ); | |||||||||||||||||||||||||||
| 194 | 40 | ▶ | 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
| |||||||||||||||||||||||||||||
| 195 | unless defined $value && length $value; | ||||||||||||||||||||||||||||
| 196 | 40 | return $value; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 136 | 1; | |||||||||||||||||||||||||||