| 1 | package Convert::Pheno::Source::CDISC::ODM; | ||||||||||||||||||||||||||||
| 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 Path::Tiny qw(path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 136 | ▶ | use XML::Fast qw(xml2hash); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 136 | ▶ | use Convert::Pheno::BFF::DerivedEntities qw(mapping_entity_overrides); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 136 | ▶ | use Convert::Pheno::CDISC::ODM::Detector qw(detect_odm_document); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 136 | ▶ | use Convert::Pheno::CDISC::ODM::Metadata; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 136 | ▶ | use Convert::Pheno::CDISC::ODM::Parser qw(parse_odm_records); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 136 | ▶ | use Convert::Pheno::IO::CSVHandler qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | read_mapping_file | ||||||||||||||||||||||||||||
| 15 | read_redcap_dict_file | ||||||||||||||||||||||||||||
| 16 | 136 | ); | |||||||||||||||||||||||||||
| 17 | 136 | ▶ | use Convert::Pheno::Mapping::Compiler qw(compile_mapping); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 136 | ▶ | use Convert::Pheno::Mapping::Shared qw(get_info get_metaData); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 136 | ▶ | use Convert::Pheno::Source::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 11 | my ( $class, $converter ) = @_; | |||||||||||||||||||||||||||
| 23 | 11 | return bless { converter => $converter }, $class; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 11 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||
| 28 | 11 | my $converter = $self->{converter}; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 11 | my $xml = path( $converter->{in_file} )->slurp_utf8; | |||||||||||||||||||||||||||
| 31 | 11 | my $odm = xml2hash $xml, attr => '-', text => '~'; | |||||||||||||||||||||||||||
| 32 | 11 | my $descriptor = detect_odm_document($odm); | |||||||||||||||||||||||||||
| 33 | my $mapping = read_mapping_file( | ||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | mapping_file => $converter->{mapping_file}, | ||||||||||||||||||||||||||||
| 36 | self_validate_schema => $converter->{self_validate_schema}, | ||||||||||||||||||||||||||||
| 37 | schema_file => $converter->{schema_file}, | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 11 | ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 11 | my ( $redcap_dictionary, $metadata_catalog ); | |||||||||||||||||||||||||||
| 42 | 11 | ▶ | if ( $descriptor->{recordProfile} eq 'redcap' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | die "REDCap-origin CDISC-ODM input requires --redcap-dictionary <file>\n" | ||||||||||||||||||||||||||||
| 44 | unless defined $converter->{redcap_dictionary} | ||||||||||||||||||||||||||||
| 45 | 7 | ▶ | && length $converter->{redcap_dictionary}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $converter->{"redcap_dictionary"} and length $converter->{"redcap_dictionary"}
MC/DC50%1/2
defined $converter->{"redcap_dictionary"} and length $converter->{"redcap_dictionary"}
defined $converter->{"redcap_dictionary"}
length $converter->{"redcap_dictionary"}
Truth table66%2/3
A and B
A= defined $converter->{"redcap_dictionary"}B= length $converter->{"redcap_dictionary"}
| |||||||||||||||||||||||||||||
| 46 | $redcap_dictionary = read_redcap_dict_file( | ||||||||||||||||||||||||||||
| 47 | { redcap_dictionary => $converter->{redcap_dictionary} } | ||||||||||||||||||||||||||||
| 48 | 6 | ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||
| 51 | die "--redcap-dictionary is only valid for REDCap-origin CDISC-ODM input\n" | ||||||||||||||||||||||||||||
| 52 | if defined $converter->{redcap_dictionary} | ||||||||||||||||||||||||||||
| 53 | 4 | ▶ | && length $converter->{redcap_dictionary}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $converter->{"redcap_dictionary"} and length $converter->{"redcap_dictionary"}
MC/DC50%1/2
defined $converter->{"redcap_dictionary"} and length $converter->{"redcap_dictionary"}
defined $converter->{"redcap_dictionary"}
length $converter->{"redcap_dictionary"}
Truth table66%2/3
A and B
A= defined $converter->{"redcap_dictionary"}B= length $converter->{"redcap_dictionary"}
| |||||||||||||||||||||||||||||
| 54 | 3 | $metadata_catalog = Convert::Pheno::CDISC::ODM::Metadata->from_document( | |||||||||||||||||||||||||||
| 55 | $descriptor | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 9 | my $data = parse_odm_records( | |||||||||||||||||||||||||||
| 60 | $descriptor, | ||||||||||||||||||||||||||||
| 61 | metadata => $redcap_dictionary, | ||||||||||||||||||||||||||||
| 62 | metadata_catalog => $metadata_catalog, | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | my $compiled_mapping = compile_mapping( | ||||||||||||||||||||||||||||
| 65 | $mapping, | ||||||||||||||||||||||||||||
| 66 | source_profile => 'cdisc-odm', | ||||||||||||||||||||||||||||
| 67 | record_profile => $descriptor->{recordProfile}, | ||||||||||||||||||||||||||||
| 68 | 9 | headers => _record_headers($data), | |||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 9 | my %artifacts = ( | |||||||||||||||||||||||||||
| 72 | mapping => $mapping, | ||||||||||||||||||||||||||||
| 73 | entity_mapping => $compiled_mapping, | ||||||||||||||||||||||||||||
| 74 | odm_descriptor => $descriptor, | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | 9 | ▶ | $artifacts{redcap_dictionary} = $redcap_dictionary | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | if defined $redcap_dictionary; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 9 | return Convert::Pheno::Source::Result->new( | |||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | data => $data, | ||||||||||||||||||||||||||||
| 82 | owned => 1, | ||||||||||||||||||||||||||||
| 83 | artifacts => \%artifacts, | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 6 | ▶ | sub prepare { | ||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 89 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 90 | 6 | my $converter = $self->{converter}; | |||||||||||||||||||||||||||
| 91 | return 1 if exists $converter->{data} | ||||||||||||||||||||||||||||
| 92 | 6 | ▶ | && exists $converter->{data_mapping_file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $converter->{"data"} and exists $converter->{"data_mapping_file"}
MC/DC0%0/2
exists $converter->{"data"} and exists $converter->{"data_mapping_file"}
exists $converter->{"data"}
exists $converter->{"data_mapping_file"}
Truth table33%1/3
A and B
A= exists $converter->{"data"}B= exists $converter->{"data_mapping_file"}
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 6 | my $source = $self->load; | |||||||||||||||||||||||||||
| 95 | 6 | $source->apply_to($converter); | |||||||||||||||||||||||||||
| 96 | 6 | ▶ | $converter->{data_redcap_dict} = $source->artifact('redcap_dictionary') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | if defined $source->artifact('redcap_dictionary'); | ||||||||||||||||||||||||||||
| 98 | 6 | $converter->{data_mapping_file} = $source->artifact('entity_mapping'); | |||||||||||||||||||||||||||
| 99 | 6 | $converter->{metaData} = get_metaData($converter); | |||||||||||||||||||||||||||
| 100 | 6 | $converter->{convertPheno} = get_info($converter); | |||||||||||||||||||||||||||
| 101 | $converter->{mapping_file_derived_entity_overrides} = | ||||||||||||||||||||||||||||
| 102 | 6 | mapping_entity_overrides( $source->artifact('mapping') ); | |||||||||||||||||||||||||||
| 103 | 6 | return 1; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 9 | ▶ | sub _record_headers { | ||||||||||||||||||||||||||
|
Subroutine
_record_headers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 107 | 9 | my ($records) = @_; | |||||||||||||||||||||||||||
| 108 | 9 | my ( @headers, %seen ); | |||||||||||||||||||||||||||
| 109 | 9 | for my $record ( @{$records} ) { | |||||||||||||||||||||||||||
| 110 | 219 | for my $header ( @{ $record->headers } ) { | |||||||||||||||||||||||||||
| 111 | 70704 | ▶ | push @headers, $header unless $seen{$header}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 9 | return \@headers; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 136 | 1; | |||||||||||||||||||||||||||