lib/Convert/Pheno.pm

filter: Statementstmt 97.0% 300 / 309 Branchbran 83.3% 25 / 30 Conditioncond 62.0% 36 / 58 MC/DCmcdc 25.8% 8 / 31 Subroutinesub 99.1% 122 / 123 Podpod 0.0% 0 / 55 totaltotal 81.0% 491 / 606 CC 38 SCAR 6.4
CC
38
Cov
91%
__ANON__
6.7
_dispatcher_input_data
5.6
BUILD
5.0
CRAP 1.9
« blib/lib/auto/share/dist/Convert-Pheno/ex/perl.pl ↑ Summary lib/Convert/Pheno/CDISC/ODM/Parser.pm »
1 package Convert::Pheno;
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 136 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 136 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 136 ▶use File::Spec::Functions qw(catdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 136 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 136 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 136 ▶use File::ShareDir::ProjectDistDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 136 ▶use List::Util qw(any uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 136 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 136 ▶use Types::Standard qw(Str Int Num Enum ArrayRef Undef);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 136 ▶use File::ShareDir::ProjectDistDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 #use Devel::Size qw(size total_size);
16 136 ▶use Convert::Pheno::IO::CSVHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 136 ▶use Convert::Pheno::IO::FileIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 136 ▶use Convert::Pheno::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 136 ▶use Convert::Pheno::Pipeline qw(run_conversion_pipeline);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 136 ▶use Convert::Pheno::Runner qw(run_operation);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 136 ▶use Convert::Pheno::Source qw(prepare_source source_adapter);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 136 ▶use Convert::Pheno::Operations qw(conversion_spec);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 136 ▶use Convert::Pheno::Emit::OMOP qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 dispatcher_open_stream_out
25 transform_item
26 finalize_stream_out
27 omop_stream_targets_open
28 omop_stream_targets_write
29 omop_stream_targets_finalize
30 omop_streams_multiple_entities
31 136 );
32 136 ▶use Convert::Pheno::OMOP::Definitions;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 136 ▶use Convert::Pheno::DB::SQLite;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 136 ▶use Convert::Pheno::Mapping::Shared;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 136 ▶use Convert::Pheno::Mapping::Metadata qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
36 apply_metadata_mapping
37 load_metadata_mapping
38 136 );
39 136 ▶use Convert::Pheno::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 136 ▶use Convert::Pheno::JSONLD qw(do_bff2jsonld do_pxf2jsonld);
Subroutine BEGIN: called CC=1 SCAR=0.0
41 136 ▶use Convert::Pheno::OMOP::ToBFF qw(do_omop2bff);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 136 ▶use Convert::Pheno::BFF::ToPXF;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 136 ▶use Convert::Pheno::BFF::ToOMOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 136 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
46 136 our @EXPORT =
47 qw($VERSION io_yaml_or_json omop2bff_stream_processing share_dir); # Symbols imported by default
48  
49 #our @EXPORT_OK = qw(foo bar); # Symbols imported by request
50  
51 136 ▶use constant DEVEL_MODE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 # Global variables:
54 136 our $VERSION = '0.35';
55 # Packaged applications provide an explicit share directory so runtime lookup
56 # does not depend on development-tree or CPAN installation heuristics.
57 136 ▶our $share_dir = $ENV{CONVERT_PHENO_SHARE_DIR} || dist_dir('Convert-Pheno');
Condition33%1/3
$ENV{'CONVERT_PHENO_SHARE_DIR'} || dist_dir('Convert-Pheno')
l!l&&r!l&&!r
01360
MC/DC0%0/2
$ENV{'CONVERT_PHENO_SHARE_DIR'} || dist_dir('Convert-Pheno')
$ENV{'CONVERT_PHENO_SHARE_DIR'} dist_dir('Convert-Pheno')
Truth table33%1/3
A || B
A= $ENV{'CONVERT_PHENO_SHARE_DIR'}B= dist_dir('Convert-Pheno')
ABresult
1X1
011
000
58  
59 # SQLite database
60 136 my @all_sqlites = qw(ncit icd10 ohdsi cdisc omim hpo);
61 136 my @non_ohdsi_sqlites = qw(ncit icd10 cdisc omim hpo);
62  
63 # Define a subroutine that computes the default username.
64 334 ▶my $default_username = sub {
Subroutine __ANON__: called CC=4 SCAR=19.1
65 334 ▶ return $ENV{'LOGNAME'} || $ENV{'USER'} || $ENV{'USERNAME'} || 'dummy-user';
Condition37%3/8
$ENV{'LOGNAME'} || $ENV{'USER'} || $ENV{'USERNAME'} || 'dummy-user'
l!l
0334
$ENV{"LOGNAME"} or $ENV{"USER"} or $ENV{"USERNAME"}
l!l&&r!l&&!r
00334
$ENV{"LOGNAME"} or $ENV{"USER"}
l!l&&r!l&&!r
00334
MC/DC0%0/3
$ENV{'LOGNAME'} || $ENV{'USER'} || $ENV{'USERNAME'} || 'dummy-user'
$ENV{"LOGNAME"} $ENV{"USER"} $ENV{"USERNAME"}
Truth table25%1/4
A or B or C
A= $ENV{"LOGNAME"}B= $ENV{"USER"}C= $ENV{"USERNAME"}
ABCresult
1XX1
01X1
0011
0000
66 136 };
67  
68 ############################################
69 # Start declaring attributes for the class #
70 ############################################
71  
72 # Complex defaults here
73 has search => (
74 is => 'ro',
75 183 ▶ default => sub { 'exact' },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 431 ▶ coerce => sub { $_[0] // 'exact' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0] // "exact"
l!l
38051
MC/DC100%1/1
$_[0] // "exact"
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
77 136 isa => Enum [qw(exact mixed fuzzy)]
78 );
79  
80 has text_similarity_method => (
81 is => 'ro',
82 284 ▶ default => sub { 'cosine' },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 431 ▶ coerce => sub { $_[0] // 'cosine' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0] // "cosine"
l!l
38051
MC/DC100%1/1
$_[0] // "cosine"
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
84 136 isa => Enum [qw(cosine dice)]
85 );
86  
87 has min_text_similarity_score => (
88 is => 'ro',
89 284 ▶ default => sub { 0.8 },
Subroutine __ANON__: called CC=1 SCAR=0.0
90 431 ▶ coerce => sub { $_[0] // 0.8 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0] // "0.8"
l!l
38051
MC/DC100%1/1
$_[0] // "0.8"
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
91 431 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
92 431 ▶ die "Only values between 0 .. 1 supported!"
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] >= 0 and $_[0] <= 1 0 431 431
Condition33%1/3
$_[0] >= 0 and $_[0] <= 1
!ll&&!rl&&r
00431
MC/DC0%0/2
$_[0] >= 0 and $_[0] <= 1
$_[0] >= 0 $_[0] <= 1
Truth table33%1/3
A and B
A= $_[0] >= 0B= $_[0] <= 1
ABresult
0X0
100
111
93 unless ( $_[0] >= 0.0 && $_[0] <= 1.0 );
94 }
95 136 );
96 has levenshtein_weight => (
97 is => 'ro',
98 284 ▶ default => sub { 0.1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 431 ▶ coerce => sub { $_[0] // 0.1 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0] // "0.1"
l!l
38051
MC/DC100%1/1
$_[0] // "0.1"
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
100 431 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
101 431 ▶ die "Only values between 0 .. 1 supported!"
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] >= 0 and $_[0] <= 1 0 431 431
Condition33%1/3
$_[0] >= 0 and $_[0] <= 1
!ll&&!rl&&r
00431
MC/DC0%0/2
$_[0] >= 0 and $_[0] <= 1
$_[0] >= 0 $_[0] <= 1
Truth table33%1/3
A and B
A= $_[0] >= 0B= $_[0] <= 1
ABresult
0X0
100
111
102 unless ( $_[0] >= 0.0 && $_[0] <= 1.0 );
103 }
104 136 );
105  
106 has username => (
107 is => 'ro',
108 isa => Str,
109 default => $default_username, # Use the subroutine for the default.
110 431 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
111 431 ▶ $_[0] // $default_username->();
Condition66%2/3
$_[0] // &$default_username()
l!l&&r!l&&!r
379520
MC/DC0%0/2
$_[0] // &$default_username()
$_[0] &$default_username()
Truth table66%2/3
A // B
A= $_[0]B= &$default_username()
ABresult
1X1
011
000
112 },
113 136 );
114  
115 has id => (
116 is => 'ro',
117 isa => Str,
118 284 ▶ default => sub { time . substr( "00000$$", -5 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
119 431 ▶ coerce => sub { $_[0] // time . substr( "00000$$", -5 ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0] // time . substr("00000${$}", -5)
l!l
4310
MC/DC0%0/1
$_[0] // time . substr("00000${$}", -5)
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
120 136 );
121  
122 has max_lines_sql => (
123 default => 500, # Limit to speed up runtime
124 is => 'ro',
125 431 ▶ coerce => sub { $_[0] // 500 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[0] // 500
l!l
38249
MC/DC100%1/1
$_[0] // 500
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
126 136 isa => Int
127 );
128  
129 # Internal safety limit used by HTTP uploads. A value of zero leaves local
130 # CLI and module conversions unrestricted.
131 has max_archive_uncompressed_bytes => (
132 is => 'ro',
133 418 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
134 431 ▶ coerce => sub { $_[0] // 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0] // 0
l!l
4310
MC/DC0%0/1
$_[0] // 0
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
135 136 isa => Int,
136 );
137  
138 has 'omop_tables' => (
139 183 ▶ default => sub { [@omop_supported_tables] },
Subroutine __ANON__: called CC=1 SCAR=0.0
140 431 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
141 431 my $tables = shift;
142  
143 $tables =
144 @$tables
145 431 ▶ ? [ uniq( map { uc($_) } ( 'CONCEPT', 'PERSON', @$tables ) ) ]
Branch: 1 branch
BranchTrueFalseTotal
@$tables ? : 281 150 431
146 : \@omop_supported_tables;
147  
148 431 return $tables;
149 },
150 136 is => 'rw',
151 isa => ArrayRef
152 );
153  
154 has exposures_file => (
155 default =>
156 catfile( $share_dir, 'db', 'concepts_candidates_2_exposure.csv' ),
157 431 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
158 431 ▶ $_[0]
Condition66%2/3
$_[0] // catfile($Convert::Pheno::share_dir, "db", "concepts_candidates_2_exposure.csv")
l!l&&r!l&&!r
380510
MC/DC0%0/2
$_[0] // catfile($Convert::Pheno::share_dir, "db", "concepts_candidates_2_exposure.csv")
$_[0] catfile($Convert::Pheno::share_dir, "db", "concepts_candidates_2_exposure.csv")
Truth table66%2/3
A // B
A= $_[0]B= catfile($Convert::Pheno::share_dir, "db", "concepts_candidates_2_exposure.csv")
ABresult
1X1
011
000
159 // catfile( $share_dir, 'db', 'concepts_candidates_2_exposure.csv' );
160 },
161 136 is => 'ro',
162 isa => Str
163 );
164  
165 # Miscellanea atributes here
166 136 has [qw /test self_validate_schema path_to_ohdsi_db/] =>
167 ( default => undef, is => 'ro' );
168  
169 136 has [qw /stream ohdsi_db/] => ( default => 0, is => 'ro' );
170 136 has source_info => ( default => 1, is => 'ro' );
171 136 has include_dataset_id => ( default => 0, is => 'ro' );
172  
173 has default_vital_status => (
174 is => 'ro',
175 3 ▶ coerce => sub { $_[0] // 'ALIVE' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0] // "ALIVE"
l!l
30
MC/DC0%0/1
$_[0] // "ALIVE"
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
176 136 isa => Enum [qw(ALIVE DECEASED UNKNOWN_STATUS)]
177 );
178  
179 168 ▶has [qw /in_files/] => ( default => sub { [] }, is => 'ro' );
Subroutine __ANON__: called CC=1 SCAR=0.0
180  
181 136 has [
182 qw /out_file out_dir in_textfile in_file sep sql2csv redcap_dictionary mapping_file schema_file define_xml debug log verbose term_audit_file/
183 ] => ( is => 'ro' );
184  
185 136 has [qw /data method/] => ( is => 'rw' );
186 200 ▶has entities => ( is => 'ro', default => sub { ['individuals'] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
187 332 ▶has derived_entity_overrides => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
188 332 ▶has output_name_overrides => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
189  
190 ##########################################
191 # End declaring attributes for the class #
192 ##########################################
193  
194 431 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
195 431 my $self = shift;
196 die "--include-dataset-id is only supported for BFF output\n"
197 431 ▶ if $self->{include_dataset_id} && ($self->{method} || '') !~ /2bff\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"include_dataset_id"} and not +($self->{"method"} || "") =~ /2bff\z/ 1 430 431
Condition80%4/5
$self->{"include_dataset_id"} and not +($self->{"method"} || "") =~ /2bff\z/
!ll&&!rl&&r
420101
$self->{'method'} || ''
l!l
110
MC/DC0%0/2
$self->{"include_dataset_id"} and not +($self->{"method"} || "") =~ /2bff\z/
$self->{"include_dataset_id"} $self->{'method'}
Truth table66%2/3
A and not(B)
A= $self->{"include_dataset_id"}B= $self->{'method'}
ABresult
0X0
110
101
198 $self->{databases} =
199 430 ▶ $self->{ohdsi_db} ? \@all_sqlites : \@non_ohdsi_sqlites;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ohdsi_db'} ? : 58 372 430
200 }
201  
202 #############
203 #############
204 # BFF2PXF #
205 #############
206 #############
207  
208 42 ▶sub bff2pxf {
Subroutine bff2pxf: called CC=1 SCAR=0.0
Pod undocumented
209 42 my $self = shift;
210 42 return _run_primary_view($self);
211 }
212  
213 #############
214 #############
215 # BFF2CSV #
216 #############
217 #############
218  
219 5 ▶sub bff2csv {
Subroutine bff2csv: called CC=1 SCAR=0.0
Pod undocumented
220 5 my $self = shift;
221 5 return _run_primary_view($self);
222 }
223  
224 #############
225 #############
226 # BFF2JSONF #
227 #############
228 #############
229  
230 3 ▶sub bff2jsonf {
Subroutine bff2jsonf: called CC=1 SCAR=0.0
Pod undocumented
231 3 my $self = shift;
232 3 return _run_primary_view($self);
233 }
234  
235 ##############
236 ##############
237 # BFF2JSONLD #
238 ##############
239 ##############
240  
241 2 ▶sub bff2jsonld {
Subroutine bff2jsonld: called CC=1 SCAR=0.0
Pod undocumented
242 2 my $self = shift;
243 2 return _run_primary_view($self);
244 }
245  
246 ##############
247 ##############
248 # BFF2OMOP #
249 ##############
250 ##############
251  
252 23 ▶sub bff2omop {
Subroutine bff2omop: called CC=1 SCAR=0.0
Pod undocumented
253 23 my $self = shift;
254 23 Convert::Pheno::OMOP::Vocabulary::prepare_terminology_mapping($self);
255 23 return merge_omop_tables( _run_primary_view($self) );
256 }
257  
258 ################
259 ################
260 # REDCAP2BFF #
261 ################
262 ################
263  
264 8 ▶sub redcap2bff {
Subroutine redcap2bff: called CC=1 SCAR=0.0
Pod undocumented
265 8 my $self = shift;
266 8 return _run_source_to_bff( $self, 'redcap' );
267 }
268  
269 ################
270 ################
271 # REDCAP2PXF #
272 ################
273 ################
274  
275 3 ▶sub redcap2pxf {
Subroutine redcap2pxf: called CC=1 SCAR=0.0
Pod undocumented
276 3 my $self = shift;
277 3 return run_conversion_pipeline($self);
278 }
279  
280 #################
281 #################
282 # REDCAP2OMOP #
283 #################
284 #################
285  
286 1 ▶sub redcap2omop {
Subroutine redcap2omop: called CC=1 SCAR=0.0
Pod undocumented
287 1 my $self = shift;
288 1 return run_conversion_pipeline($self);
289 }
290  
291 ###################
292 ###################
293 # CBIOPORTAL2BFF #
294 ###################
295 ###################
296  
297 5 ▶sub cbioportal2bff {
Subroutine cbioportal2bff: called CC=1 SCAR=0.0
Pod undocumented
298 5 my $self = shift;
299 5 return _run_source_to_bff( $self, 'cbioportal' );
300 }
301  
302 ###################
303 ###################
304 # CBIOPORTAL2PXF #
305 ###################
306 ###################
307  
308 2 ▶sub cbioportal2pxf {
Subroutine cbioportal2pxf: called CC=1 SCAR=0.0
Pod undocumented
309 2 my $self = shift;
310 2 return run_conversion_pipeline($self);
311 }
312  
313 ###################
314 ###################
315 # CBIOPORTAL2OMOP #
316 ###################
317 ###################
318  
319 2 ▶sub cbioportal2omop {
Subroutine cbioportal2omop: called CC=1 SCAR=0.0
Pod undocumented
320 2 my $self = shift;
321 2 return run_conversion_pipeline($self);
322 }
323  
324 ########################
325 # RELATIONAL CDM INPUTS #
326 ########################
327  
328 6 ▶sub i2b22bff {
Subroutine i2b22bff: called CC=1 SCAR=0.0
Pod undocumented
329 6 my $self = shift;
330 6 return _run_source_to_bff( $self, 'i2b2' );
331 }
332  
333 1 ▶sub i2b22pxf {
Subroutine i2b22pxf: called CC=1 SCAR=0.0
Pod undocumented
334 1 my $self = shift;
335 1 return run_conversion_pipeline($self);
336 }
337  
338 1 ▶sub i2b22omop {
Subroutine i2b22omop: called CC=1 SCAR=0.0
Pod undocumented
339 1 my $self = shift;
340 1 return run_conversion_pipeline($self);
341 }
342  
343 5 ▶sub sentinel2bff {
Subroutine sentinel2bff: called CC=1 SCAR=0.0
Pod undocumented
344 5 my $self = shift;
345 5 return _run_source_to_bff( $self, 'sentinel' );
346 }
347  
348 1 ▶sub sentinel2pxf {
Subroutine sentinel2pxf: called CC=1 SCAR=0.0
Pod undocumented
349 1 my $self = shift;
350 1 return run_conversion_pipeline($self);
351 }
352  
353 1 ▶sub sentinel2omop {
Subroutine sentinel2omop: called CC=1 SCAR=0.0
Pod undocumented
354 1 my $self = shift;
355 1 return run_conversion_pipeline($self);
356 }
357  
358 6 ▶sub pcornet2bff {
Subroutine pcornet2bff: called CC=1 SCAR=0.0
Pod undocumented
359 6 my $self = shift;
360 6 return _run_source_to_bff( $self, 'pcornet' );
361 }
362  
363 1 ▶sub pcornet2pxf {
Subroutine pcornet2pxf: called CC=1 SCAR=0.0
Pod undocumented
364 1 my $self = shift;
365 1 return run_conversion_pipeline($self);
366 }
367  
368 1 ▶sub pcornet2omop {
Subroutine pcornet2omop: called CC=1 SCAR=0.0
Pod undocumented
369 1 my $self = shift;
370 1 return run_conversion_pipeline($self);
371 }
372  
373 ##############
374 ##############
375 # OMOP2BFF #
376 ##############
377 ##############
378  
379 31 ▶sub omop2bff {
Subroutine omop2bff: called CC=2 SCAR=6.9
Pod undocumented
380 31 my $self = shift;
381 31 _prepare_source_to_bff( $self, 'omop' );
382 27 _set_bff_context( $self, 'omop' );
383  
384 27 ▶ if ( $self->{stream} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"stream"}) 8 19 27
385 return _with_prepared_data_cleanup(
386 $self,
387 8 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
388 return omop_stream_dispatcher(
389 {
390 self => $self,
391 filepath => $self->{filepath_sql},
392 filepaths => $self->{filepaths_csv},
393 }
394 8 );
395 }
396 8 );
397 }
398  
399 19 return _run_primary_view($self);
400 }
401  
402 ##############
403 ##############
404 # OMOP2PXF #
405 ##############
406 ##############
407  
408 6 ▶sub omop2pxf {
Subroutine omop2pxf: called CC=1 SCAR=0.0
Pod undocumented
409 6 my $self = shift;
410 6 return run_conversion_pipeline($self);
411 }
412  
413 ###############
414 ###############
415 # CDISCODM2BFF #
416 ###############
417 ###############
418  
419 5 ▶sub cdiscodm2bff {
Subroutine cdiscodm2bff: called CC=1 SCAR=0.0
Pod undocumented
420 5 my $self = shift;
421 5 return _run_source_to_bff( $self, 'cdisc-odm' );
422 }
423  
424 ###############
425 ###############
426 # CDISCODM2PXF #
427 ###############
428 ###############
429  
430 2 ▶sub cdiscodm2pxf {
Subroutine cdiscodm2pxf: called CC=1 SCAR=0.0
Pod undocumented
431 2 my $self = shift;
432 2 return run_conversion_pipeline($self);
433 }
434  
435 ################
436 ################
437 # CDISCODM2OMOP #
438 ################
439 ################
440  
441 1 ▶sub cdiscodm2omop {
Subroutine cdiscodm2omop: called CC=1 SCAR=0.0
Pod undocumented
442 1 my $self = shift;
443 1 return run_conversion_pipeline($self);
444 }
445  
446 ####################
447 ####################
448 # DATASETJSON2BFF #
449 ####################
450 ####################
451  
452 14 ▶sub datasetjson2bff {
Subroutine datasetjson2bff: called CC=1 SCAR=0.0
Pod undocumented
453 14 my $self = shift;
454 14 return _run_source_to_bff( $self, 'dataset-json' );
455 }
456  
457 ####################
458 ####################
459 # DATASETJSON2PXF #
460 ####################
461 ####################
462  
463 4 ▶sub datasetjson2pxf {
Subroutine datasetjson2pxf: called CC=1 SCAR=0.0
Pod undocumented
464 4 my $self = shift;
465 4 return run_conversion_pipeline($self);
466 }
467  
468 ####################
469 ####################
470 # DATASETJSON2OMOP #
471 ####################
472 ####################
473  
474 2 ▶sub datasetjson2omop {
Subroutine datasetjson2omop: called CC=1 SCAR=0.0
Pod undocumented
475 2 my $self = shift;
476 2 return run_conversion_pipeline($self);
477 }
478  
479 ###################
480 ###################
481 # DATASETXML2BFF #
482 ###################
483 ###################
484  
485 11 ▶sub datasetxml2bff {
Subroutine datasetxml2bff: called CC=1 SCAR=0.0
Pod undocumented
486 11 my $self = shift;
487 11 return _run_source_to_bff( $self, 'dataset-xml' );
488 }
489  
490 ###################
491 ###################
492 # DATASETXML2PXF #
493 ###################
494 ###################
495  
496 1 ▶sub datasetxml2pxf {
Subroutine datasetxml2pxf: called CC=1 SCAR=0.0
Pod undocumented
497 1 my $self = shift;
498 1 return run_conversion_pipeline($self);
499 }
500  
501 ###################
502 ###################
503 # DATASETXML2OMOP #
504 ###################
505 ###################
506  
507 1 ▶sub datasetxml2omop {
Subroutine datasetxml2omop: called CC=1 SCAR=0.0
Pod undocumented
508 1 my $self = shift;
509 1 return run_conversion_pipeline($self);
510 }
511  
512 ##############
513 ##############
514 # FHIR2BFF #
515 ##############
516 ##############
517  
518 15 ▶sub fhir2bff {
Subroutine fhir2bff: called CC=1 SCAR=0.0
Pod undocumented
519 15 my $self = shift;
520 15 return _run_source_to_bff( $self, 'fhir' );
521 }
522  
523 ##############
524 ##############
525 # FHIR2PXF #
526 ##############
527 ##############
528  
529 4 ▶sub fhir2pxf {
Subroutine fhir2pxf: called CC=1 SCAR=0.0
Pod undocumented
530 4 my $self = shift;
531 4 return run_conversion_pipeline($self);
532 }
533  
534 ##############
535 ##############
536 # FHIR2OMOP #
537 ##############
538 ##############
539  
540 4 ▶sub fhir2omop {
Subroutine fhir2omop: called CC=1 SCAR=0.0
Pod undocumented
541 4 my $self = shift;
542 4 return run_conversion_pipeline($self);
543 }
544  
545 #############
546 #############
547 # PXF2BFF #
548 #############
549 #############
550  
551 15 ▶sub pxf2bff {
Subroutine pxf2bff: called CC=1 SCAR=0.0
Pod undocumented
552 15 my $self = shift;
553 15 return _run_source_to_bff( $self, 'pxf' );
554 }
555  
556 ##############
557 ##############
558 # PXF2OMOP #
559 ##############
560 ##############
561  
562 2 ▶sub pxf2omop {
Subroutine pxf2omop: called CC=1 SCAR=0.0
Pod undocumented
563 2 my $self = shift;
564 2 return run_conversion_pipeline($self);
565 }
566  
567 #################
568 #################
569 # OPENEHR2BFF #
570 #################
571 #################
572  
573 16 ▶sub openehr2bff {
Subroutine openehr2bff: called CC=1 SCAR=0.0
Pod undocumented
574 16 my $self = shift;
575 16 return _run_source_to_bff( $self, 'openehr' );
576 }
577  
578 #################
579 #################
580 # OPENEHR2PXF #
581 #################
582 #################
583  
584 4 ▶sub openehr2pxf {
Subroutine openehr2pxf: called CC=1 SCAR=0.0
Pod undocumented
585 4 my $self = shift;
586 4 return run_conversion_pipeline($self);
587 }
588  
589 #############
590 #############
591 # CSV2BFF #
592 #############
593 #############
594  
595 13 ▶sub csv2bff {
Subroutine csv2bff: called CC=1 SCAR=0.0
Pod undocumented
596 13 my $self = shift;
597 13 return _run_source_to_bff( $self, 'csv' );
598 }
599  
600 #############
601 #############
602 # CSV2PXF #
603 #############
604 #############
605  
606 2 ▶sub csv2pxf {
Subroutine csv2pxf: called CC=1 SCAR=0.0
Pod undocumented
607 2 my $self = shift;
608 2 return run_conversion_pipeline($self);
609 }
610  
611 ##############
612 ##############
613 # CSV2OMOP #
614 ##############
615 ##############
616  
617 2 ▶sub csv2omop {
Subroutine csv2omop: called CC=1 SCAR=0.0
Pod undocumented
618 2 my $self = shift;
619 2 return run_conversion_pipeline($self);
620 }
621  
622 #############
623 #############
624 # PXF2CSV #
625 #############
626 #############
627  
628 4 ▶sub pxf2csv {
Subroutine pxf2csv: called CC=1 SCAR=0.0
Pod undocumented
629 4 my $self = shift;
630 4 return _run_primary_view($self);
631 }
632  
633 #############
634 #############
635 # PXFJSONF #
636 #############
637 #############
638  
639 3 ▶sub pxf2jsonf {
Subroutine pxf2jsonf: called CC=1 SCAR=0.0
Pod undocumented
640 3 my $self = shift;
641 3 return _run_primary_view($self);
642 }
643  
644 ##############
645 ##############
646 # PXF2JSONLD #
647 ##############
648 ##############
649  
650 2 ▶sub pxf2jsonld {
Subroutine pxf2jsonld: called CC=1 SCAR=0.0
Pod undocumented
651 2 my $self = shift;
652 2 return _run_primary_view($self);
653 }
654  
655 #################
656 #################
657 # HELPER SUBS #
658 #################
659 #################
660  
661 262 ▶sub _dispatcher_input_data {
Subroutine _dispatcher_input_data: called CC=5 SCAR=17.2
662 262 my ($self) = @_;
663 262 ▶ return $self->{data} if exists $self->{data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"data"} 245 17 262
664 return $self->{data}
665 unless $self->{in_textfile}
666 17 ▶ && $self->{method} !~ m/^(redcap2|omop2|cdiscodm2|csv)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"in_textfile"} and not $self->{"method"} =~ /^(redcap2|omop2|cdiscodm2|csv)/ 0 17 17
Condition33%1/3
$self->{"in_textfile"} and not $self->{"method"} =~ /^(redcap2|omop2|cdiscodm2|csv)/
!ll&&!rl&&r
0017
MC/DC0%0/2
$self->{"in_textfile"} and not $self->{"method"} =~ /^(redcap2|omop2|cdiscodm2|csv)/
$self->{"in_textfile"} not $self->{"method"} =~ /^(redcap2|omop2|cdiscodm2|csv)/
Truth table33%1/3
A and not(B)
A= $self->{"in_textfile"}B= not $self->{"method"} =~ /^(redcap2|omop2|cdiscodm2|csv)/
ABresult
0X0
100
111
667  
668 my $spec = conversion_spec( $self->{method} )
669 17 ▶ or die "Unsupported conversion <$self->{method}>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $spec = conversion_spec($self->{"method"}) or die qq[Unsupported conversion <$self->{"method"}>\n] 17 0 17
670 17 return source_adapter( $self, $spec->{source} )->load->data;
671 }
672  
673 200 ▶sub _dispatcher_open_stream_out {
Subroutine _dispatcher_open_stream_out: called CC=1 SCAR=0.0
674 200 return dispatcher_open_stream_out(@_);
675 }
676  
677 201 ▶sub _run_primary_view {
Subroutine _run_primary_view: called CC=1 SCAR=0.0
678 201 my ($self) = @_;
679 201 return _run_view( $self, 'primary' );
680 }
681  
682 211 ▶sub _prepare_source_to_bff {
Subroutine _prepare_source_to_bff: called CC=2 SCAR=7.1
683 211 my ( $self, $format ) = @_;
684 211 my $metadata_overrides = load_metadata_mapping( $self, $format );
685 211 prepare_source( $self, $format );
686 197 apply_metadata_mapping( $self, $format, $metadata_overrides );
687 197 ▶ $self->{convertPheno} ||= get_info($self);
Condition33%1/3
$self->{"convertPheno"} ||= get_info($self)
l!l&&r!l&&!r
19700
MC/DC0%0/2
$self->{"convertPheno"} ||= get_info($self)
$self->{"convertPheno"} get_info($self)
Truth table33%1/3
A ||= B
A= $self->{"convertPheno"}B= get_info($self)
ABresult
1X1
011
000
688 197 return 1;
689 }
690  
691 137 ▶sub _set_bff_context {
Subroutine _set_bff_context: called CC=2 SCAR=7.1
692 137 my ( $self, $format ) = @_;
693 $self->{conversion_context} = Convert::Pheno::Context->from_self(
694 $self,
695 {
696 source_format => $format,
697 target_format => 'beacon',
698 137 ▶ entities => $self->{entities} || ['individuals'],
Condition50%1/2
$self->{'entities'} || ['individuals']
l!l
1370
MC/DC0%0/1
$self->{'entities'} || ['individuals']
$self->{'entities'}
Truth table50%1/2
A
A= $self->{'entities'}
Aresult
11
00
699 }
700 );
701 134 return 1;
702 }
703  
704 119 ▶sub _run_source_to_bff {
Subroutine _run_source_to_bff: called CC=1 SCAR=0.0
705 119 my ( $self, $format ) = @_;
706 119 _prepare_source_to_bff( $self, $format );
707 110 _set_bff_context( $self, $format );
708 107 return _run_primary_view($self);
709 }
710  
711 61 ▶sub _run_bundle_view {
Subroutine _run_bundle_view: called CC=2 SCAR=7.0
712 61 my ($self) = @_;
713 my $spec = conversion_spec( $self->{method} )
714 61 ▶ or die "Unsupported conversion <$self->{method}>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $spec = conversion_spec($self->{"method"}) or die qq[Unsupported conversion <$self->{"method"}>\n] 61 0 61
715 61 _prepare_source_to_bff( $self, $spec->{source} );
716 60 delete $self->{conversion_context};
717 60 return _run_view( $self, 'bundle' );
718 }
719  
720 261 ▶sub _run_view {
Subroutine _run_view: called CC=4 SCAR=13.9
721 261 my ( $self, $view ) = @_;
722 die "BFF terminology mapping files are supported only for bff2omop.\n"
723 if $self->{mapping_file} && $self->{method} =~ /^bff2/
724 261 ▶ && $self->{method} ne 'bff2omop';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mapping_file"} and $self->{"method"} =~ /^bff2/ and $self->{"method"} ne "bff2omop" 1 260 261
Condition100%6/6
$self->{"mapping_file"} and $self->{"method"} =~ /^bff2/ and $self->{"method"} ne "bff2omop"
!ll&&!rl&&r
25821
$self->{"mapping_file"} and $self->{"method"} =~ /^bff2/
!ll&&!rl&&r
220383
MC/DC100%3/3
$self->{"mapping_file"} and $self->{"method"} =~ /^bff2/ and $self->{"method"} ne "bff2omop"
$self->{"mapping_file"} $self->{"method"} =~ /^bff2/ $self->{"method"} ne "bff2omop"
Truth table100%4/4
A and B and C
A= $self->{"mapping_file"}B= $self->{"method"} =~ /^bff2/C= $self->{"method"} ne "bff2omop"
ABCresult
0XX0
10X0
1100
1111
725 260 my $input = _dispatcher_input_data($self);
726  
727 return _with_prepared_data_cleanup(
728 $self,
729 260 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
730 260 return run_operation(
731 $self,
732 $input,
733 view => $view,
734 );
735 }
736 260 );
737 }
738  
739 268 ▶sub _with_prepared_data_cleanup {
Subroutine _with_prepared_data_cleanup: called CC=4 SCAR=13.9
740 268 my ( $self, $code ) = @_;
741 268 my $owns_prepared_data = delete $self->{_owns_prepared_data};
742  
743 268 my ( $ok, $error, $result );
744 268 $ok = eval {
745 268 $result = $code->();
746 266 1;
747 };
748 268 ▶ $error = $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 266 268
749  
750 # Module callers own their references. Only release buffers loaded or
751 # derived internally; clearing a caller's array corrupts reusable input.
752 268 ▶ delete $self->{data} if $owns_prepared_data;
Branch: 1 branch
BranchTrueFalseTotal
if $owns_prepared_data 182 86 268
753 268 delete $self->{_source_cleanup_guards};
754  
755 268 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 266 268
756 266 return $result;
757 }
758  
759 6000 ▶sub _transform_item {
Subroutine _transform_item: called CC=1 SCAR=0.0
760 6000 return transform_item(@_);
761 }
762  
763 2 ▶sub omop_dispatcher {
Subroutine omop_dispatcher: called CC=1 SCAR=0.0
Pod undocumented
764 2 return Convert::Pheno::Emit::OMOP::omop_dispatcher(@_);
765 }
766  
767 8 ▶sub omop_stream_dispatcher {
Subroutine omop_stream_dispatcher: called CC=1 SCAR=0.0
Pod undocumented
768 8 return Convert::Pheno::OMOP::ParticipantStream::omop_stream_dispatcher(@_);
769 }
770  
771 1 ▶sub process_csv_files_stream {
Subroutine process_csv_files_stream: called CC=1 SCAR=0.0
Pod undocumented
772 1 return Convert::Pheno::OMOP::ParticipantStream::process_csv_files_stream(@_);
773 }
774  
775 1 ▶sub process_sqldump_stream {
Subroutine process_sqldump_stream: called CC=1 SCAR=0.0
Pod undocumented
776 1 return Convert::Pheno::OMOP::ParticipantStream::process_sqldump_stream(@_);
777 }
778  
779 6936 ▶sub omop2bff_stream_processing {
Subroutine omop2bff_stream_processing: called CC=2 SCAR=6.9
Pod undocumented
780 6936 my ( $self, $data ) = @_;
781 return Convert::Pheno::OMOP::ToBFF::run_omop_to_bundle(
782 $self, $data, $self->{conversion_context}
783 )
784 6936 ▶ if omop_streams_multiple_entities($self);
Branch: 1 branch
BranchTrueFalseTotal
if omop_streams_multiple_entities($self) 36 6900 6936
785  
786 6900 return do_omop2bff( $self, $data );
787 }
788  
789 3 ▶sub omop_stream_targets_open_wrapper {
Subroutine omop_stream_targets_open_wrapper: called CC=1 SCAR=0.0
Pod undocumented
790 3 return omop_stream_targets_open(@_);
791 }
792  
793 36 ▶sub omop_stream_targets_write_wrapper {
Subroutine omop_stream_targets_write_wrapper: called CC=1 SCAR=0.0
Pod undocumented
794 36 return omop_stream_targets_write(@_);
795 }
796  
797 3 ▶sub omop_stream_targets_finalize_wrapper {
Subroutine omop_stream_targets_finalize_wrapper: called CC=1 SCAR=0.0
Pod undocumented
798 3 return omop_stream_targets_finalize(@_);
799 }
800  
801 6952 ▶sub omop_streams_multiple_entities_wrapper {
Subroutine omop_streams_multiple_entities_wrapper: called CC=1 SCAR=0.0
Pod undocumented
802 6952 return omop_streams_multiple_entities(@_);
803 }
804  
805 0 ▶sub Dumper_concise {
Subroutine Dumper_concise: not called CC=1 SCAR=6.9
Pod undocumented
806 {
807 0 local $Data::Dumper::Terse = 1;
808 0 local $Data::Dumper::Indent = 1;
809 0 local $Data::Dumper::Useqq = 1;
810 0 local $Data::Dumper::Deparse = 1;
811 0 local $Data::Dumper::Quotekeys = 1;
812 0 local $Data::Dumper::Sortkeys = 1;
813 0 local $Data::Dumper::Pair = ' : ';
814 0 print Dumper shift;
815 }
816 }
817  
818 136 1;
819  
820 =head1 NAME
821  
822 Convert::Pheno - Convert clinical and phenotypic data between supported models
823  
824 =head1 SYNOPSIS
825  
826 use Convert::Pheno;
827  
828 my $pxf = {
829 "phenopacket" => {
830 "id" => "P0007500",
831 "subject" => {
832 "id" => "P0007500",
833 "dateOfBirth" => "2000-01-01T00:00:00Z",
834 "sex" => "FEMALE"
835 }
836 }
837 };
838  
839 my $converter = Convert::Pheno->new(
840 {
841 data => $pxf,
842 method => 'pxf2bff'
843 }
844 );
845  
846 my $individual = $converter->pxf2bff;
847  
848 =head1 DESCRIPTION
849  
850 C<Convert::Pheno> is the conversion engine used by the C<convert-pheno>
851 command-line program. It converts supported in-memory data structures and
852 route-specific file inputs between Beacon v2 Models Format (BFF),
853 Phenopackets v2 (PXF), OMOP-CDM, REDCap, cBioPortal clinical study packages,
854 CDISC-ODM, CDISC Dataset-JSON, CDISC Dataset-XML, FHIR R4, i2b2, PCORnet CDM,
855 Sentinel CDM, openEHR, and tabular representations.
856  
857 Conversion availability and required arguments depend on the selected route.
858 Mapping-file conversions use the Mapping V2 contract and require
859 C<mappingVersion: 2>; pre-V2 mapping files are rejected.
860  
861 =head1 METHODS
862  
863 =head2 new
864  
865 my $converter = Convert::Pheno->new(\%arguments);
866  
867 Creates a converter. C<method> identifies the public conversion method.
868 In-memory routes receive decoded input under C<data>; file-based routes use
869 the arguments documented for that conversion.
870  
871 =head2 Conversion methods
872  
873 my $result = $converter->$method;
874  
875 In-memory conversions return Perl data structures. Streaming and file-output
876 routes write to their configured destinations and may instead return a
877 completion status. See the module guide for supported methods, arguments,
878 multi-entity results, and Python interoperability.
879  
880 =head1 DOCUMENTATION
881  
882 =over
883  
884 =item Project documentation
885  
886 L<https://cnag-biomedical-informatics.github.io/convert-pheno>
887  
888 =item Module usage
889  
890 L<https://cnag-biomedical-informatics.github.io/convert-pheno/use-as-a-module>
891  
892 =item Command-line interface
893  
894 L<https://cnag-biomedical-informatics.github.io/convert-pheno/use-as-a-command-line-interface>
895  
896 =back
897  
898 =head1 ERRORS
899  
900 Invalid input, unsupported routes, and conversion failures raise exceptions.
901 Callers that need recovery should invoke conversion methods inside C<eval> or
902 another exception-handling mechanism.
903  
904 =head1 CITATION
905  
906 Please cite the following reference in published work that uses
907 C<Convert-Pheno>:
908  
909 Rueda, M et al., (2024). Convert-Pheno: A software toolkit for the interconversion of standard data models for phenotypic data. Journal of Biomedical Informatics. L<DOI|https://doi.org/10.1016/j.jbi.2023.104558>
910  
911 =head1 AUTHOR
912  
913 Written by Manuel Rueda, PhD. Info about CNAG can be found at L<https://www.cnag.eu>.
914  
915 =head1 COPYRIGHT AND LICENSE
916  
917 Copyright 2022-2026 Manuel Rueda and CNAG.
918  
919 This software is distributed under the Artistic License 2.0. See the LICENSE
920 file included in this distribution.
921  
922 =cut
« blib/lib/auto/share/dist/Convert-Pheno/ex/perl.pl ↑ Summary lib/Convert/Pheno/CDISC/ODM/Parser.pm »