lib/Convert/Pheno/OMOP/ToBFF/Biosamples.pm

filter: Statementstmt 100% 82 / 82 Branchbran 82.6% 38 / 46 Conditioncond 66.6% 12 / 18 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 2 totaltotal 87.4% 153 / 175 CC 31 SCAR 16.0
CC
31
Cov
90%
map_specimen_to_biosample
10.0
extract_participant_biosamples
7.1
_has_value
5.2
CRAP 5.0
« lib/Convert/Pheno/Model/Bundle.pm ↑ Summary lib/Convert/Pheno/CDISC/ODM/Util.pm »
1 package Convert::Pheno::OMOP::ToBFF::Biosamples;
2  
3 138 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 138 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 138 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 138 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 138 ▶use Convert::Pheno::Mapping::Shared qw(get_age_from_date_and_birthday map2ohdsi);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 138 ▶use Convert::Pheno::Utils::Default qw(get_defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 138 our @EXPORT_OK = qw(extract_participant_biosamples map_specimen_to_biosample);
12  
13 138 my $DEFAULT = get_defaults();
14  
15 1022 ▶sub extract_participant_biosamples {
Subroutine extract_participant_biosamples: called CC=7 SCAR=19.6
Pod undocumented
16 1022 my ( $self, $participant, $individual ) = @_;
17 1022 my $table = 'SPECIMEN';
18  
19 return []
20 unless exists $participant->{$table}
21 1022 ▶ && ref( $participant->{$table} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless exists $participant->{$table} and ref $participant->{$table} eq "ARRAY" 970 52 1022
Condition66%2/3
exists $participant->{$table} and ref $participant->{$table} eq "ARRAY"
!ll&&!rl&&r
970052
MC/DC50%1/2
exists $participant->{$table} and ref $participant->{$table} eq "ARRAY"
exists $participant->{$table} ref $participant->{$table} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $participant->{$table}B= ref $participant->{$table} eq "ARRAY"
ABresult
0X0
100
111
22  
23 my $individual_id =
24 defined $individual
25 && ref($individual) eq 'HASH'
26 && defined $individual->{id}
27 ? $individual->{id}
28 52 ▶ : _stringify_if_defined( $participant->{PERSON}{person_id} );
Branch: 1 branch
BranchTrueFalseTotal
defined $individual && ref $individual eq 'HASH' && defined $individual->{'id'} ? : 31 21 52
Condition66%4/6
defined $individual and ref $individual eq "HASH" and defined $individual->{"id"}
!ll&&!rl&&r
21031
defined $individual and ref $individual eq "HASH"
!ll&&!rl&&r
21031
MC/DC33%1/3
defined $individual and ref $individual eq "HASH" and defined $individual->{"id"}
defined $individual ref $individual eq "HASH" defined $individual->{"id"}
Truth table50%2/4
A and B and C
A= defined $individualB= ref $individual eq "HASH"C= defined $individual->{"id"}
ABCresult
0XX0
10X0
1100
1111
29  
30 52 my @biosamples;
31 52 for my $specimen ( @{ $participant->{$table} } ) {
32 push @biosamples,
33 79 map_specimen_to_biosample( $self, $specimen, $participant->{PERSON}, $individual_id );
34 }
35  
36 52 return \@biosamples;
37 }
38  
39 79 ▶sub map_specimen_to_biosample {
Subroutine map_specimen_to_biosample: called CC=10 SCAR=23.1
Pod undocumented
40 79 my ( $self, $specimen, $person, $individual_id ) = @_;
41 79 my $ohdsi_dict = $self->{data_ohdsi_dict};
42  
43 my $biosample = {
44 id => _stringify_if_defined( $specimen->{specimen_id} ),
45 biosampleStatus => $DEFAULT->{ontology_term},
46 sampleOriginType => _map_concept_or_default(
47 $self,
48 $ohdsi_dict,
49 $specimen->{specimen_concept_id},
50 79 ),
51 };
52 79 ▶ $biosample->{info}{SPECIMEN}{OMOP_columns} = $specimen if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 77 2 79
53 79 ▶ $biosample->{individualId} = $individual_id if defined $individual_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $individual_id 79 0 79
54  
55 79 ▶ if ( _has_value( $specimen->{specimen_date} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_has_value($specimen->{"specimen_date"})) 79 0 79
56 79 $biosample->{collectionDate} = $specimen->{specimen_date};
57  
58 my $collection_moment = get_age_from_date_and_birthday(
59 {
60 date => $specimen->{specimen_date},
61 birth_day => $person->{birth_datetime},
62 }
63 79 );
64 79 ▶ $biosample->{collectionMoment} = $collection_moment
Branch: 1 branch
BranchTrueFalseTotal
if defined $collection_moment 79 0 79
65 if defined $collection_moment;
66 }
67  
68 my $sample_origin_detail = _map_concept(
69 $self,
70 $ohdsi_dict,
71 $specimen->{anatomic_site_concept_id},
72 79 );
73 79 ▶ $biosample->{sampleOriginDetail} = $sample_origin_detail
Branch: 1 branch
BranchTrueFalseTotal
if defined $sample_origin_detail 3 76 79
74 if defined $sample_origin_detail;
75  
76 my $obtention_procedure = _map_concept(
77 $self,
78 $ohdsi_dict,
79 $specimen->{specimen_type_concept_id},
80 79 );
81 79 ▶ if ( defined $obtention_procedure ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obtention_procedure) 74 5 79
82 $biosample->{obtentionProcedure} = {
83 74 procedureCode => $obtention_procedure,
84 };
85 }
86  
87 my $histological_diagnosis = _map_concept(
88 $self,
89 $ohdsi_dict,
90 $specimen->{disease_status_concept_id},
91 79 );
92 79 ▶ $biosample->{histologicalDiagnosis} = $histological_diagnosis
Branch: 1 branch
BranchTrueFalseTotal
if defined $histological_diagnosis 3 76 79
93 if defined $histological_diagnosis;
94  
95 79 my $measurement = _map_specimen_quantity_measurement( $self, $ohdsi_dict, $specimen );
96 79 ▶ $biosample->{measurements} = [$measurement] if defined $measurement;
Branch: 1 branch
BranchTrueFalseTotal
if defined $measurement 6 73 79
97  
98 79 ▶ unless ( $self->{test} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"}) 3 76 79
99 3 $biosample->{info}{convertPheno} = $self->{convertPheno};
100 }
101  
102 79 return $biosample;
103 }
104  
105 79 ▶sub _map_specimen_quantity_measurement {
Subroutine _map_specimen_quantity_measurement: called CC=4 SCAR=14.5
106 79 my ( $self, $ohdsi_dict, $specimen ) = @_;
107 79 ▶ return unless _has_numeric_value( $specimen->{quantity} );
Branch: 1 branch
BranchTrueFalseTotal
unless _has_numeric_value($specimen->{"quantity"}) 73 6 79
108  
109 my $unit = _map_concept( $self, $ohdsi_dict, $specimen->{unit_concept_id} )
110 || _unit_from_source_value( $specimen->{unit_source_value} )
111 6 ▶ || $DEFAULT->{ontology_term};
Condition50%3/6
_map_concept($self, $ohdsi_dict, $specimen->{'unit_concept_id'}) || _unit_from_source_value($specimen->{'unit_source_value'}) || $DEFAULT->{'ontology_term'}
l!l&&r!l&&!r
600
_map_concept($self, $ohdsi_dict, $specimen->{"unit_concept_id"}) or _unit_from_source_value($specimen->{"unit_source_value"})
l!l&&r!l&&!r
330
MC/DC0%0/3
_map_concept($self, $ohdsi_dict, $specimen->{'unit_concept_id'}) || _unit_from_source_value($specimen->{'unit_source_value'}) || $DEFAULT->{'ontology_term'}
_map_concept($self, $ohdsi_dict, $specimen->{"unit_concept_id"}) _unit_from_source_value($specimen->{"unit_source_value"}) $DEFAULT->{'ontology_term'}
Truth table50%2/4
A or B || C
A= _map_concept($self, $ohdsi_dict, $specimen->{"unit_concept_id"})B= _unit_from_source_value($specimen->{"unit_source_value"})C= $DEFAULT->{'ontology_term'}
ABCresult
1XX1
01X1
0011
0000
112  
113 # OMOP SPECIMEN has quantity and unit fields but no measurement_concept_id.
114 # Use a valid CURIE that explicitly identifies the OMOP source field instead
115 # of pretending that specimen_concept_id or specimen_type_concept_id is an assay.
116 return {
117 assayCode => {
118 id => 'OMOP:SPECIMEN.quantity',
119 label => 'Specimen quantity',
120 },
121 measurementValue => {
122 quantity => {
123 6 value => $specimen->{quantity} + 0,
124 unit => $unit,
125 },
126 },
127 };
128 }
129  
130 79 ▶sub _map_concept_or_default {
Subroutine _map_concept_or_default: called CC=2 SCAR=6.9
131 79 my ( $self, $ohdsi_dict, $concept_id ) = @_;
132 79 my $mapped = _map_concept( $self, $ohdsi_dict, $concept_id );
133 79 ▶ return defined $mapped ? $mapped : $DEFAULT->{ontology_term};
Branch: 1 branch
BranchTrueFalseTotal
defined $mapped ? : 78 1 79
134 }
135  
136 79 ▶sub _source_info_enabled {
Subroutine _source_info_enabled: called CC=2 SCAR=6.9
137 79 my ($self) = @_;
138 79 ▶ return !exists $self->{source_info} || $self->{source_info};
Condition100%3/3
!exists $self->{'source_info'} || $self->{'source_info'}
l!l&&r!l&&!r
3742
MC/DC100%2/2
!exists $self->{'source_info'} || $self->{'source_info'}
!exists $self->{'source_info'} $self->{'source_info'}
Truth table100%3/3
not(A) || B
A= !exists $self->{'source_info'}B= $self->{'source_info'}
ABresult
1X1
011
000
139 }
140  
141 322 ▶sub _map_concept {
Subroutine _map_concept: called CC=2 SCAR=6.9
142 322 my ( $self, $ohdsi_dict, $concept_id ) = @_;
143 322 ▶ return unless _has_concept_id($concept_id);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_concept_id($concept_id) 161 161 322
144  
145 161 return map2ohdsi(
146 {
147 ohdsi_dict => $ohdsi_dict,
148 concept_id => $concept_id,
149 self => $self,
150 }
151 );
152 }
153  
154 322 ▶sub _has_concept_id {
Subroutine _has_concept_id: called CC=3 SCAR=11.0
155 322 my ($value) = @_;
156 322 ▶ return 0 unless _has_value($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($value) 3 319 322
157 319 ▶ return 0 if $value =~ /\A0+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A0+\z/ 158 161 319
158 161 return 1;
159 }
160  
161 483 ▶sub _has_value {
Subroutine _has_value: called CC=5 SCAR=16.6
162 483 my ($value) = @_;
163 483 ▶ return 0 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 76 407 483
164 407 ▶ return 0 if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 407 407
165 407 ▶ return 0 if $value eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" 0 407 407
166 407 ▶ return 0 if $value eq '\\N';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "\\N" 0 407 407
167 407 return 1;
168 }
169  
170 79 ▶sub _has_numeric_value {
Subroutine _has_numeric_value: called CC=2 SCAR=6.9
171 79 my ($value) = @_;
172 79 ▶ return 0 unless _has_value($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($value) 73 6 79
173 6 return $value =~ /\A[+-]?(?:\d+(?:\.\d*)?|\.\d+)\z/;
174 }
175  
176 3 ▶sub _unit_from_source_value {
Subroutine _unit_from_source_value: called CC=2 SCAR=7.1
177 3 my ($value) = @_;
178 3 ▶ return unless _has_value($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($value) 0 3 3
179 return {
180 id => $DEFAULT->{ontology_term}{id},
181 3 label => $value,
182 };
183 }
184  
185 100 ▶sub _stringify_if_defined {
Subroutine _stringify_if_defined: called CC=2 SCAR=7.1
186 100 my ($value) = @_;
187 100 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 100 100
188 100 return qq{$value};
189 }
190  
191 138 1;
« lib/Convert/Pheno/Model/Bundle.pm ↑ Summary lib/Convert/Pheno/CDISC/ODM/Util.pm »