| 1 | package Convert::Pheno::Source::CDISC::DatasetJSON; | ||||||||||||||||||||||||||||
| 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 File::ShareDir::ProjectDistDir qw(dist_dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 136 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 136 | ▶ | use JSON::Validator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 136 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 136 | ▶ | use Convert::Pheno::CDISC::DefineXML qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | enrich_dataset_from_define | ||||||||||||||||||||||||||||
| 13 | load_define_catalog | ||||||||||||||||||||||||||||
| 14 | 136 | ); | |||||||||||||||||||||||||||
| 15 | 136 | ▶ | use Convert::Pheno::CDISC::SDTM::Normalizer qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | derive_sdtm_entity_overrides | ||||||||||||||||||||||||||||
| 17 | normalize_sdtm_datasets | ||||||||||||||||||||||||||||
| 18 | 136 | ); | |||||||||||||||||||||||||||
| 19 | 136 | ▶ | use Convert::Pheno::CDISC::SDTM::Terminology qw(prepare_sdtm_terminology); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 136 | ▶ | use Convert::Pheno::IO::FileIO qw(read_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 136 | ▶ | use Convert::Pheno::Mapping::Shared qw(get_info); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 136 | ▶ | use Convert::Pheno::Source::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 136 | my $SCHEMA_FILE = | |||||||||||||||||||||||||||
| 25 | catfile( dist_dir('Convert-Pheno'), 'schema', 'dataset-json-1.1.json' ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 22 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 22 | my ( $class, $converter ) = @_; | |||||||||||||||||||||||||||
| 29 | 22 | return bless { converter => $converter }, $class; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 22 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=13 SCAR=26.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 22 | my ($self) = @_; | |||||||||||||||||||||||||||
| 34 | 22 | my $converter = $self->{converter}; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 22 | my ( @datasets, @labels ); | |||||||||||||||||||||||||||
| 37 | 22 | ▶ | if ( exists $converter->{data} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 9 | my $data = $converter->{data}; | |||||||||||||||||||||||||||
| 39 | 9 | ▶ | @datasets = ref($data) eq 'ARRAY' ? @{$data} : ($data); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 9 | @datasets = map { dclone($_) } @datasets; | |||||||||||||||||||||||||||
| 41 | 9 | @labels = map { 'in-memory dataset ' . ( $_ + 1 ) } 0 .. $#datasets; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | 13 | ▶ | my @files = @{ $converter->{in_files} || [] }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$converter->{'in_files'} || []
MC/DC0%0/1
$converter->{'in_files'} || []
$converter->{'in_files'}
Truth table50%1/2
A
A= $converter->{'in_files'}
| |||||||||||||||||||||||||||||
| 45 | push @files, $converter->{in_file} | ||||||||||||||||||||||||||||
| 46 | 13 | ▶ | if !@files && defined $converter->{in_file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @files and defined $converter->{"in_file"}
MC/DC0%0/2
not @files and defined $converter->{"in_file"}
not @files
defined $converter->{"in_file"}
Truth table33%1/3
not(A) and B
A= not @filesB= defined $converter->{"in_file"}
| |||||||||||||||||||||||||||||
| 47 | 13 | ▶ | die "Dataset-JSON input requires at least one JSON file\n" unless @files; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 13 | for my $file (@files) { | |||||||||||||||||||||||||||
| 50 | 130 | push @datasets, read_json($file); | |||||||||||||||||||||||||||
| 51 | 130 | push @labels, $file; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 22 | my $validator = JSON::Validator->new; | |||||||||||||||||||||||||||
| 56 | 22 | $validator->schema( read_json($SCHEMA_FILE) ); | |||||||||||||||||||||||||||
| 57 | 22 | for my $index ( 0 .. $#datasets ) { | |||||||||||||||||||||||||||
| 58 | 167 | my @errors = $validator->validate( $datasets[$index] ); | |||||||||||||||||||||||||||
| 59 | 167 | ▶ | next unless @errors; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | die "Dataset-JSON schema validation failed for <$labels[$index]>:\n" | ||||||||||||||||||||||||||||
| 61 | 0 | . join( q{}, map { " $_\n" } @errors ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 22 | ▶ | if ( defined $converter->{define_xml} && length $converter->{define_xml} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $converter->{"define_xml"} and length $converter->{"define_xml"}
MC/DC50%1/2
defined $converter->{"define_xml"} and length $converter->{"define_xml"}
defined $converter->{"define_xml"}
length $converter->{"define_xml"}
Truth table66%2/3
A and B
A= defined $converter->{"define_xml"}B= length $converter->{"define_xml"}
| |||||||||||||||||||||||||||||
| 65 | my $catalog = load_define_catalog( | ||||||||||||||||||||||||||||
| 66 | $converter->{define_xml}, | ||||||||||||||||||||||||||||
| 67 | 1 | "Define-XML <$converter->{define_xml}>", | |||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | 1 | for my $index ( 0 .. $#datasets ) { | |||||||||||||||||||||||||||
| 70 | 1 | enrich_dataset_from_define( | |||||||||||||||||||||||||||
| 71 | $datasets[$index], | ||||||||||||||||||||||||||||
| 72 | $catalog, | ||||||||||||||||||||||||||||
| 73 | "Dataset-JSON input <$labels[$index]>", | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 22 | my $normalized = normalize_sdtm_datasets( | |||||||||||||||||||||||||||
| 79 | \@datasets, | ||||||||||||||||||||||||||||
| 80 | \@labels, | ||||||||||||||||||||||||||||
| 81 | format_name => 'Dataset-JSON', | ||||||||||||||||||||||||||||
| 82 | source_format => 'dataset-json', | ||||||||||||||||||||||||||||
| 83 | version_key => 'datasetJSONVersion', | ||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||
| 85 | my $terminology = prepare_sdtm_terminology( | ||||||||||||||||||||||||||||
| 86 | $converter, | ||||||||||||||||||||||||||||
| 87 | $normalized->{metadata}, | ||||||||||||||||||||||||||||
| 88 | 18 | ); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | return Convert::Pheno::Source::Result->new( | ||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | data => $normalized->{subjects}, | ||||||||||||||||||||||||||||
| 93 | owned => 1, | ||||||||||||||||||||||||||||
| 94 | artifacts => { | ||||||||||||||||||||||||||||
| 95 | dataset_metadata => $normalized->{metadata}, | ||||||||||||||||||||||||||||
| 96 | subject_independent_domains => $normalized->{subject_independent}, | ||||||||||||||||||||||||||||
| 97 | terminology_mapping => $terminology->{mapping}, | ||||||||||||||||||||||||||||
| 98 | source_terminology => $terminology->{source_terms}, | ||||||||||||||||||||||||||||
| 99 | terminology_requires_sqlite => $terminology->{requires_sqlite}, | ||||||||||||||||||||||||||||
| 100 | derived_entity_overrides => derive_sdtm_entity_overrides( | ||||||||||||||||||||||||||||
| 101 | $converter, | ||||||||||||||||||||||||||||
| 102 | $normalized->{metadata}, | ||||||||||||||||||||||||||||
| 103 | $normalized->{subject_independent}, | ||||||||||||||||||||||||||||
| 104 | 18 | format_label => 'Dataset-JSON', | |||||||||||||||||||||||||||
| 105 | provenance_key => 'datasetJson', | ||||||||||||||||||||||||||||
| 106 | ), | ||||||||||||||||||||||||||||
| 107 | }, | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 16 | ▶ | sub prepare { | ||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=12 SCAR=25.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||
| 114 | 16 | my $converter = $self->{converter}; | |||||||||||||||||||||||||||
| 115 | return 1 if $converter->{dataset_json_input_prepared} | ||||||||||||||||||||||||||||
| 116 | 16 | ▶ | && exists $converter->{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$converter->{"dataset_json_input_prepared"} and exists $converter->{"data"}
MC/DC0%0/2
$converter->{"dataset_json_input_prepared"} and exists $converter->{"data"}
$converter->{"dataset_json_input_prepared"}
exists $converter->{"data"}
Truth table66%2/3
A and B
A= $converter->{"dataset_json_input_prepared"}B= exists $converter->{"data"}
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | $converter->{_dataset_json_source_data} = $converter->{data} | ||||||||||||||||||||||||||||
| 119 | if exists $converter->{data} | ||||||||||||||||||||||||||||
| 120 | 16 | ▶ | && !exists $converter->{_dataset_json_source_data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $converter->{"data"} and not exists $converter->{"_dataset_json_source_data"}
MC/DC50%1/2
exists $converter->{"data"} and not exists $converter->{"_dataset_json_source_data"}
exists $converter->{"data"}
not exists $converter->{"_dataset_json_source_data"}
Truth table66%2/3
A and not(B)
A= exists $converter->{"data"}B= not exists $converter->{"_dataset_json_source_data"}
| |||||||||||||||||||||||||||||
| 121 | $converter->{data} = $converter->{_dataset_json_source_data} | ||||||||||||||||||||||||||||
| 122 | if !exists $converter->{data} | ||||||||||||||||||||||||||||
| 123 | 16 | ▶ | && exists $converter->{_dataset_json_source_data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $converter->{"data"} and exists $converter->{"_dataset_json_source_data"}
MC/DC100%2/2
not exists $converter->{"data"} and exists $converter->{"_dataset_json_source_data"}
not exists $converter->{"data"}
exists $converter->{"_dataset_json_source_data"}
Truth table100%3/3
not(A) and B
A= not exists $converter->{"data"}B= exists $converter->{"_dataset_json_source_data"}
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 16 | my $source = $self->load; | |||||||||||||||||||||||||||
| 126 | 16 | $source->apply_to($converter); | |||||||||||||||||||||||||||
| 127 | $converter->{dataset_json_metadata} = | ||||||||||||||||||||||||||||
| 128 | 16 | $source->artifact('dataset_metadata'); | |||||||||||||||||||||||||||
| 129 | $converter->{dataset_json_subject_independent_domains} = | ||||||||||||||||||||||||||||
| 130 | 16 | $source->artifact('subject_independent_domains'); | |||||||||||||||||||||||||||
| 131 | $converter->{source_derived_entity_overrides} = | ||||||||||||||||||||||||||||
| 132 | 16 | ▶ | $source->artifact('derived_entity_overrides') || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$source->artifact('derived_entity_overrides') || {}
MC/DC0%0/1
$source->artifact('derived_entity_overrides') || {}
$source->artifact('derived_entity_overrides')
Truth table50%1/2
A
A= $source->artifact('derived_entity_overrides')
| |||||||||||||||||||||||||||||
| 133 | $converter->{sdtm_terminology_mapping} = | ||||||||||||||||||||||||||||
| 134 | 16 | ▶ | $source->artifact('terminology_mapping') || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$source->artifact('terminology_mapping') || {}
MC/DC100%1/1
$source->artifact('terminology_mapping') || {}
$source->artifact('terminology_mapping')
Truth table100%2/2
A
A= $source->artifact('terminology_mapping')
| |||||||||||||||||||||||||||||
| 135 | $converter->{sdtm_source_terms} = | ||||||||||||||||||||||||||||
| 136 | 16 | ▶ | $source->artifact('source_terminology') || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$source->artifact('source_terminology') || {}
MC/DC0%0/1
$source->artifact('source_terminology') || {}
$source->artifact('source_terminology')
Truth table50%1/2
A
A= $source->artifact('source_terminology')
| |||||||||||||||||||||||||||||
| 137 | $converter->{terminology_lookup_required} = | ||||||||||||||||||||||||||||
| 138 | 16 | ▶ | $source->artifact('terminology_requires_sqlite') ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 16 | ▶ | $converter->{convertPheno} ||= get_info($converter); | ||||||||||||||||||||||||||
|
Condition66%2/3
$converter->{"convertPheno"} ||= get_info($converter)
MC/DC0%0/2
$converter->{"convertPheno"} ||= get_info($converter)
$converter->{"convertPheno"}
get_info($converter)
Truth table66%2/3
A ||= B
A= $converter->{"convertPheno"}B= get_info($converter)
| |||||||||||||||||||||||||||||
| 140 | 16 | $converter->{dataset_json_input_prepared} = 1; | |||||||||||||||||||||||||||
| 141 | 16 | return 1; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 136 | 1; | |||||||||||||||||||||||||||