lib/Convert/Pheno/FHIR/ToBFF.pm

filter: Statementstmt 89.8% 311 / 346 Branchbran 60.3% 134 / 222 Conditioncond 41.6% 90 / 216 MC/DCmcdc 11.5% 14 / 121 Subroutinesub 97.1% 34 / 35 Podpod 0.0% 0 / 1 totaltotal 61.9% 583 / 941 CC 205 SCAR 32.6
CC
205
Cov
68%
_resolve_local_or_bundle_reference
90.0
run_fhir_to_bundle
44.7
_map_specimen
37.5
CRAP 26.0
« lib/Convert/Pheno/Source/CDISC/DatasetXML.pm ↑ Summary lib/Convert/Pheno/CDISC/SDTM/Normalizer.pm »
1 package Convert::Pheno::FHIR::ToBFF;
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 Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 136 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 136 ▶use Scalar::Util qw(looks_like_number refaddr);
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::BFF::Biosample qw(biosample_to_phenopacket);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 136 ▶use Convert::Pheno::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 136 ▶use Convert::Pheno::FHIR::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 canonical_reference
15 codeable_concept_to_term
16 quantity_unit_to_term
17 resolve_reference
18 source_term
19 136 );
20 136 ▶use Convert::Pheno::FHIR::Profile::MCode qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 condition_stage
22 detected_profile_metadata
23 136 );
24 136 ▶use Convert::Pheno::Mapping::Shared qw(get_age_from_date_and_birthday);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 136 ▶use Convert::Pheno::Model::Bundle;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 136 ▶use Convert::Pheno::Utils::Default qw(get_defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 136 our @EXPORT_OK = qw(run_fhir_to_bundle);
29  
30 136 my $DEFAULT = get_defaults();
31 136 my %MAPPED_RESOURCE = map { $_ => 1 } qw(
32 Condition
33 MedicationAdministration
34 MedicationRequest
35 MedicationStatement
36 Observation
37 Procedure
38 Specimen
39 );
40 136 my %SPECIMEN_STATUS_DISPLAY = (
41 available => 'Available',
42 unavailable => 'Unavailable',
43 unsatisfactory => 'Unsatisfactory',
44 'entered-in-error' => 'Entered in Error',
45 );
46  
47 18 ▶sub run_fhir_to_bundle {
Subroutine run_fhir_to_bundle: called CC=34 SCAR=38.0
Pod undocumented
48 18 my ( $self, $record, $context ) = @_;
49  
50 $context ||= Convert::Pheno::Context->from_self(
51 $self,
52 {
53 source_format => 'fhir',
54 target_format => 'beacon',
55 18 ▶ entities => $self->{entities} || ['individuals'],
Condition20%1/5
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", "fhir", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
l!l&&r!l&&!r
1800
$self->{'entities'} || ['individuals']
l!l
00
MC/DC0%0/2
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", "fhir", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
$context "Convert::Pheno::Context"->from_self($self, {"source_format", "fhir", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
MC/DC0%0/1
$self->{'entities'} || ['individuals']
$self->{'entities'}
Truth table33%1/3
A ||= B
A= $contextB= "Convert::Pheno::Context"->from_self($self, {"source_format", "fhir", "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'entities'}
Aresult
11
00
56 }
57 );
58  
59 18 ▶ die "Normalized FHIR input must contain a patient-scoped object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $record eq "HASH" 0 18 18
60 unless ref($record) eq 'HASH';
61 die "Normalized FHIR input is missing its Patient resource\n"
62 unless ref( $record->{patient} ) eq 'HASH'
63 18 ▶ && ( $record->{patient}{resourceType} || q{} ) eq 'Patient';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $record->{"patient"} eq "HASH" and ($record->{"patient"}{"resourceType"} || "") eq "Patient" 0 18 18
Condition40%2/5
ref $record->{"patient"} eq "HASH" and ($record->{"patient"}{"resourceType"} || "") eq "Patient"
!ll&&!rl&&r
0018
$record->{'patient'}{'resourceType'} || ''
l!l
180
MC/DC0%0/2
ref $record->{"patient"} eq "HASH" and ($record->{"patient"}{"resourceType"} || "") eq "Patient"
ref $record->{"patient"} eq "HASH" $record->{'patient'}{'resourceType'}
Truth table33%1/3
A and B
A= ref $record->{"patient"} eq "HASH"B= $record->{'patient'}{'resourceType'}
ABresult
0X0
100
111
64  
65 18 my $bundle = Convert::Pheno::Model::Bundle->new(
66 {
67 context => $context,
68 entities => $context->entities,
69 }
70 );
71  
72 18 my $patient = $record->{patient};
73 18 ▶ my $resources = $record->{resources} || [];
Condition50%1/2
$record->{'resources'} || []
l!l
180
MC/DC0%0/1
$record->{'resources'} || []
$record->{'resources'}
Truth table50%1/2
A
A= $record->{'resources'}
Aresult
11
00
74 18 ▶ my $index = $record->{resourceIndex} || {};
Condition50%1/2
$record->{'resourceIndex'} || {}
l!l
180
MC/DC0%0/1
$record->{'resourceIndex'} || {}
$record->{'resourceIndex'}
Truth table50%1/2
A
A= $record->{'resourceIndex'}
Aresult
11
00
75 18 my $individual = _map_patient( $patient, $record->{id} );
76  
77 18 my ( @specimens, @specimen_observations );
78 18 for my $resource ( @{$resources} ) {
79 189 ▶ next unless ref($resource) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $resource eq "HASH" 0 189 189
80 189 ▶ my $type = $resource->{resourceType} || q{};
Condition50%1/2
$resource->{'resourceType'} || ''
l!l
1890
MC/DC0%0/1
$resource->{'resourceType'} || ''
$resource->{'resourceType'}
Truth table50%1/2
A
A= $resource->{'resourceType'}
Aresult
11
00
81  
82 189 ▶ if ( $type eq 'Condition' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Condition") 18 171 189
83 18 _push_mapped(
84 $individual,
85 'diseases',
86 _map_condition( $resource, $patient, $index ),
87 );
88 18 next;
89 }
90  
91 171 ▶ if ( $type eq 'Observation' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Observation") 90 81 171
92 90 ▶ if ( ref( $resource->{specimen} ) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $resource->{"specimen"} eq "HASH" and defined $resource->{"specimen"}{"reference"}) 22 68 90
Condition66%2/3
ref $resource->{"specimen"} eq "HASH" and defined $resource->{"specimen"}{"reference"}
!ll&&!rl&&r
68022
MC/DC50%1/2
ref $resource->{"specimen"} eq "HASH" and defined $resource->{"specimen"}{"reference"}
ref $resource->{"specimen"} eq "HASH" defined $resource->{"specimen"}{"reference"}
Truth table66%2/3
A and B
A= ref $resource->{"specimen"} eq "HASH"B= defined $resource->{"specimen"}{"reference"}
ABresult
0X0
100
111
93 && defined $resource->{specimen}{reference} )
94 {
95 22 push @specimen_observations, $resource;
96 22 next;
97 }
98  
99 68 my $feature = _map_hpo_observation( $resource, $patient );
100 68 ▶ if ($feature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feature) { } 17 51 68
101 17 _push_mapped( $individual, 'phenotypicFeatures', $feature );
102 }
103 else {
104 _push_mapped( $individual, 'measures', $_ )
105 51 for @{ _map_observation_measurements($resource) };
106 }
107 68 next;
108 }
109  
110 81 ▶ if ( $type eq 'Procedure' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Procedure") 21 60 81
111 21 _push_mapped(
112 $individual,
113 'interventionsOrProcedures',
114 _map_procedure($resource),
115 );
116 21 next;
117 }
118  
119 60 ▶ if ( $type eq 'MedicationRequest'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "MedicationRequest" or $type eq "MedicationAdministration" or $type eq "MedicationStatement") 21 39 60
Condition66%4/6
$type eq "MedicationRequest" or $type eq "MedicationAdministration" or $type eq "MedicationStatement"
l!l&&r!l&&!r
21039
$type eq "MedicationRequest" or $type eq "MedicationAdministration"
l!l&&r!l&&!r
21039
MC/DC33%1/3
$type eq "MedicationRequest" or $type eq "MedicationAdministration" or $type eq "MedicationStatement"
$type eq "MedicationRequest" $type eq "MedicationAdministration" $type eq "MedicationStatement"
Truth table50%2/4
A or B or C
A= $type eq "MedicationRequest"B= $type eq "MedicationAdministration"C= $type eq "MedicationStatement"
ABCresult
1XX1
01X1
0011
0000
120 || $type eq 'MedicationAdministration'
121 || $type eq 'MedicationStatement' )
122 {
123 21 _push_mapped(
124 $individual,
125 'treatments',
126 _map_medication( $resource, $index, $patient ),
127 );
128 21 next;
129 }
130  
131 39 ▶ push @specimens, $resource if $type eq 'Specimen';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Specimen" 18 21 39
132 }
133  
134 18 my @biosamples = grep { defined } map {
135 18 _map_specimen(
136 $self,
137 $_,
138 $individual->{id},
139 18 \@specimen_observations,
140 $index,
141 )
142 } @specimens;
143  
144 # The primary BFF view contains individuals only. Preserve a semantic
145 # Phenopackets biosample representation so the fhir2pxf pipeline does not
146 # lose specimens when the first-class Beacon biosamples collection is not
147 # carried between pipeline stages.
148 18 ▶ if (@biosamples) {
Branch: 1 branch
BranchTrueFalseTotal
if (@biosamples) 18 0 18
149 $individual->{info}{phenopacket}{biosamples} = [
150 18 map { biosample_to_phenopacket($_) } @biosamples
151 ];
152 }
153  
154 18 ▶ if ( $self->{source_info} // 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_info"} // 1) 17 1 18
Condition50%1/2
$self->{"source_info"} // 1
l!l
180
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
Aresult
11
00
155 17 my @unmapped_types = _unmapped_resource_types($resources);
156 $individual->{info}{fhir} = {
157 version => 'R4',
158 patient => dclone($patient),
159 resources => dclone($resources),
160 17 ▶ bundles => dclone( $record->{bundleMetadata} || [] ),
Condition50%1/2
$record->{'bundleMetadata'} || []
l!l
170
MC/DC0%0/1
$record->{'bundleMetadata'} || []
$record->{'bundleMetadata'}
Truth table50%1/2
A
A= $record->{'bundleMetadata'}
Aresult
11
00
161 };
162 $individual->{info}{fhir}{unmappedResourceTypes} = \@unmapped_types
163 17 ▶ if @unmapped_types;
Branch: 1 branch
BranchTrueFalseTotal
if @unmapped_types 17 0 17
164 my $mcode = detected_profile_metadata(
165 17 ▶ @{ $record->{bundleMetadata} || [] },
Condition50%1/2
$record->{'bundleMetadata'} || []
l!l
170
MC/DC0%0/1
$record->{'bundleMetadata'} || []
$record->{'bundleMetadata'}
Truth table50%1/2
A
A= $record->{'bundleMetadata'}
Aresult
11
00
166 $patient,
167 17 @{$resources},
168 );
169 17 ▶ $individual->{info}{fhir}{profiles}{mcode} = $mcode if $mcode;
Branch: 1 branch
BranchTrueFalseTotal
if $mcode 1 16 17
170 }
171  
172 18 ▶ unless ( $self->{test} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"}) 0 18 18
173 $individual->{info}{convertPheno} = $self->{convertPheno}
174 0 ▶ if defined $self->{convertPheno};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"convertPheno"} 0 0 0
175 }
176  
177 18 $bundle->add_entity( individuals => $individual );
178 18 ▶ if ( _context_requests_entity( $context, 'biosamples' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_context_requests_entity($context, "biosamples")) 2 16 18
179 2 $bundle->add_entity( biosamples => $_ ) for @biosamples;
180 }
181  
182 18 return $bundle;
183 }
184  
185 18 ▶sub _map_patient {
Subroutine _map_patient: called CC=13 SCAR=29.6
186 18 my ( $patient, $fallback_id ) = @_;
187 18 ▶ my $id = $patient->{id} // $fallback_id;
Condition33%1/3
$patient->{"id"} // $fallback_id
l!l&&r!l&&!r
1800
MC/DC0%0/2
$patient->{"id"} // $fallback_id
$patient->{"id"} $fallback_id
Truth table33%1/3
A // B
A= $patient->{"id"}B= $fallback_id
ABresult
1X1
011
000
188 18 ▶ die "FHIR Patient cannot be mapped without an identifier\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and not ref $id and length $id 0 18 18
Condition33%2/6
defined $id and not ref $id and length $id
!ll&&!rl&&r
0018
defined $id and not ref $id
!ll&&!rl&&r
0018
MC/DC0%0/3
defined $id and not ref $id and length $id
defined $id not ref $id length $id
Truth table25%1/4
A and not(B) and C
A= defined $idB= not ref $idC= length $id
ABCresult
0XX0
10X0
1100
1111
189 unless defined $id && !ref($id) && length $id;
190  
191 18 ▶ my $gender = lc( $patient->{gender} // 'unknown' );
Condition50%1/2
$patient->{"gender"} // "unknown"
l!l
180
MC/DC0%0/1
$patient->{"gender"} // "unknown"
$patient->{"gender"}
Truth table50%1/2
A
A= $patient->{"gender"}
Aresult
11
00
192 18 ▶ $gender = 'unknown' unless exists $DEFAULT->{sex}{$gender};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $DEFAULT->{"sex"}{$gender} 0 18 18
193 my $individual = {
194 id => $id,
195 18 sex => dclone( $DEFAULT->{sex}{$gender} ),
196 };
197  
198 18 ▶ if ( defined $patient->{birthDate} && !ref( $patient->{birthDate} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $patient->{"birthDate"} and not ref $patient->{"birthDate"}) 18 0 18
Condition33%1/3
defined $patient->{"birthDate"} and not ref $patient->{"birthDate"}
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $patient->{"birthDate"} and not ref $patient->{"birthDate"}
defined $patient->{"birthDate"} not ref $patient->{"birthDate"}
Truth table33%1/3
A and not(B)
A= defined $patient->{"birthDate"}B= not ref $patient->{"birthDate"}
ABresult
0X0
100
111
199 18 my $date_of_birth = $patient->{birthDate};
200 18 ▶ $date_of_birth .= 'T00:00:00Z'
Branch: 1 branch
BranchTrueFalseTotal
if $date_of_birth =~ /^\d{4}-\d{2}-\d{2}\z/ 18 0 18
201 if $date_of_birth =~ /^\d{4}-\d{2}-\d{2}\z/;
202 18 $individual->{info}{phenopacket}{dateOfBirth} = $date_of_birth;
203 }
204  
205 18 my $vital_status = _map_vital_status($patient);
206 18 ▶ $individual->{info}{phenopacket}{vitalStatus} = $vital_status
Branch: 1 branch
BranchTrueFalseTotal
if $vital_status 0 18 18
207 if $vital_status;
208  
209 18 my $ethnicity = _patient_ethnicity($patient);
210 18 ▶ $individual->{ethnicity} = $ethnicity if $ethnicity;
Branch: 1 branch
BranchTrueFalseTotal
if $ethnicity 18 0 18
211  
212 18 my $origin = _patient_geographic_origin($patient);
213 18 ▶ $individual->{geographicOrigin} = $origin if $origin;
Branch: 1 branch
BranchTrueFalseTotal
if $origin 17 1 18
214  
215 18 return $individual;
216 }
217  
218 18 ▶sub _map_vital_status {
Subroutine _map_vital_status: called CC=5 SCAR=21.7
219 18 my ($patient) = @_;
220  
221 18 ▶ if ( defined $patient->{deceasedDateTime}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $patient->{"deceasedDateTime"} and not ref $patient->{"deceasedDateTime"}) 0 18 18
Condition33%1/3
defined $patient->{"deceasedDateTime"} and not ref $patient->{"deceasedDateTime"}
!ll&&!rl&&r
1800
MC/DC0%0/2
defined $patient->{"deceasedDateTime"} and not ref $patient->{"deceasedDateTime"}
defined $patient->{"deceasedDateTime"} not ref $patient->{"deceasedDateTime"}
Truth table33%1/3
A and not(B)
A= defined $patient->{"deceasedDateTime"}B= not ref $patient->{"deceasedDateTime"}
ABresult
0X0
100
111
222 && !ref( $patient->{deceasedDateTime} ) )
223 {
224 return {
225 status => 'DECEASED',
226 timeOfDeath => { timestamp => $patient->{deceasedDateTime} },
227 0 };
228 }
229  
230 18 ▶ if ( exists $patient->{deceasedBoolean} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $patient->{"deceasedBoolean"}) 0 18 18
231 return {
232 0 ▶ status => $patient->{deceasedBoolean} ? 'DECEASED' : 'ALIVE',
Branch: 1 branch
BranchTrueFalseTotal
$patient->{'deceasedBoolean'} ? : 0 0 0
233 };
234 }
235  
236 18 return;
237 }
238  
239 18 ▶sub _patient_ethnicity {
Subroutine _patient_ethnicity: called CC=19 SCAR=35.8
240 18 my ($patient) = @_;
241  
242 18 ▶ for my $extension ( @{ $patient->{extension} || [] } ) {
Condition50%1/2
$patient->{'extension'} || []
l!l
180
MC/DC0%0/1
$patient->{'extension'} || []
$patient->{'extension'}
Truth table50%1/2
A
A= $patient->{'extension'}
Aresult
11
00
243 19 ▶ next unless ref($extension) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extension eq "HASH" 0 19 19
244 19 ▶ next unless ( $extension->{url} || q{} ) =~ /us-core-ethnicity\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless ($extension->{"url"} || "") =~ /us-core-ethnicity\z/ 1 18 19
Condition50%1/2
$extension->{'url'} || ''
l!l
190
MC/DC0%0/1
$extension->{'url'} || ''
$extension->{'url'}
Truth table50%1/2
A
A= $extension->{'url'}
Aresult
11
00
245  
246 18 my $label;
247 18 ▶ for my $part ( @{ $extension->{extension} || [] } ) {
Condition50%1/2
$extension->{'extension'} || []
l!l
180
MC/DC0%0/1
$extension->{'extension'} || []
$extension->{'extension'}
Truth table50%1/2
A
A= $extension->{'extension'}
Aresult
11
00
248 36 ▶ next unless ref($part) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $part eq "HASH" 0 36 36
249 $label = $part->{valueString}
250 if ( $part->{url} || q{} ) eq 'text'
251 36 ▶ && defined $part->{valueString};
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"url"} || "") eq "text" and defined $part->{"valueString"} 18 18 36
Condition60%3/5
($part->{"url"} || "") eq "text" and defined $part->{"valueString"}
!ll&&!rl&&r
18018
$part->{'url'} || ''
l!l
360
MC/DC0%0/2
($part->{"url"} || "") eq "text" and defined $part->{"valueString"}
$part->{'url'} defined $part->{"valueString"}
Truth table33%1/3
A and B
A= $part->{'url'}B= defined $part->{"valueString"}
ABresult
0X0
100
111
252 }
253  
254 18 ▶ for my $part ( @{ $extension->{extension} || [] } ) {
Condition50%1/2
$extension->{'extension'} || []
l!l
180
MC/DC0%0/1
$extension->{'extension'} || []
$extension->{'extension'}
Truth table50%1/2
A
A= $extension->{'extension'}
Aresult
11
00
255 18 ▶ next unless ref($part) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $part eq "HASH" 0 18 18
256 18 ▶ next unless ref( $part->{valueCoding} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $part->{"valueCoding"} eq "HASH" 0 18 18
257 my $term = codeable_concept_to_term(
258 {
259 18 coding => [ $part->{valueCoding} ],
260 text => $label,
261 },
262 'Ethnicity',
263 );
264 18 ▶ return $term if $term;
Branch: 1 branch
BranchTrueFalseTotal
if $term 18 0 18
265 }
266  
267 0 ▶ return source_term( 'Ethnicity', $label, $label )
Branch: 1 branch
BranchTrueFalseTotal
if defined $label and length $label 0 0 0
Condition0%0/3
defined $label and length $label
!ll&&!rl&&r
000
MC/DC0%0/2
defined $label and length $label
defined $label length $label
Truth table0%0/3
A and B
A= defined $labelB= length $label
ABresult
0X0
100
111
268 if defined $label && length $label;
269 }
270  
271 0 return;
272 }
273  
274 18 ▶sub _patient_geographic_origin {
Subroutine _patient_geographic_origin: called CC=13 SCAR=34.0
275 18 my ($patient) = @_;
276  
277 18 ▶ for my $extension ( @{ $patient->{extension} || [] } ) {
Condition50%1/2
$patient->{'extension'} || []
l!l
180
MC/DC0%0/1
$patient->{'extension'} || []
$patient->{'extension'}
Truth table50%1/2
A
A= $patient->{'extension'}
Aresult
11
00
278 37 ▶ next unless ref($extension) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extension eq "HASH" 0 37 37
279 37 ▶ next unless ( $extension->{url} || q{} ) =~ /patient-birthPlace\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless ($extension->{"url"} || "") =~ /patient-birthPlace\z/ 20 17 37
Condition50%1/2
$extension->{'url'} || ''
l!l
370
MC/DC0%0/1
$extension->{'url'} || ''
$extension->{'url'}
Truth table50%1/2
A
A= $extension->{'url'}
Aresult
11
00
280 17 ▶ next unless ref( $extension->{valueAddress} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extension->{"valueAddress"} eq "HASH" 0 17 17
281  
282 17 my $address = $extension->{valueAddress};
283 17 my $country = $address->{country};
284 17 ▶ if ( defined $country && !ref($country) && length $country ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $country and not ref $country and length $country) 17 0 17
Condition33%2/6
defined $country and not ref $country and length $country
!ll&&!rl&&r
0017
defined $country and not ref $country
!ll&&!rl&&r
0017
MC/DC0%0/3
defined $country and not ref $country and length $country
defined $country not ref $country length $country
Truth table25%1/4
A and not(B) and C
A= defined $countryB= not ref $countryC= length $country
ABCresult
0XX0
10X0
1100
1111
285 17 my $code = uc $country;
286 17 ▶ return $code =~ /^[A-Z]{2,3}\z/
Branch: 1 branch
BranchTrueFalseTotal
$code =~ /^[A-Z]{2,3}\z/ ? : 17 0 17
287 ? { id => "ISO3166-1:$code", label => $country }
288 : source_term( 'BirthPlace', $country, $country );
289 }
290  
291 0 ▶ my $label = join ', ', grep { defined && length }
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
292 0 map { $address->{$_} } qw(city state);
293 0 ▶ return source_term( 'BirthPlace', $label, $label ) if length $label;
Branch: 1 branch
BranchTrueFalseTotal
if length $label 0 0 0
294 }
295  
296 1 return;
297 }
298  
299 18 ▶sub _map_condition {
Subroutine _map_condition: called CC=7 SCAR=20.2
300 18 my ( $condition, $patient, $resource_index ) = @_;
301 18 my $code = codeable_concept_to_term( $condition->{code}, 'Condition' );
302 18 ▶ return unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 18 18
303  
304 18 my $disease = { diseaseCode => $code };
305 my $onset = _time_at_date(
306 $condition->{onsetDateTime},
307 $patient->{birthDate},
308 18 );
309 18 ▶ $disease->{ageOfOnset} = $onset if $onset;
Branch: 1 branch
BranchTrueFalseTotal
if $onset 18 0 18
310  
311 my $resolution = _time_at_date(
312 $condition->{abatementDateTime},
313 $patient->{birthDate},
314 18 );
315 18 ▶ $disease->{resolution} = $resolution if $resolution;
Branch: 1 branch
BranchTrueFalseTotal
if $resolution 17 1 18
316  
317 my $verification = codeable_concept_to_term(
318 $condition->{verificationStatus},
319 18 'ConditionVerificationStatus',
320 );
321 18 ▶ if ( $verification && $verification->{id} =~ /:(?:refuted|entered-in-error)\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verification and $verification->{"id"} =~ /:(?:refuted|entered-in-error)\z/i) 0 18 18
Condition33%1/3
$verification and $verification->{"id"} =~ /:(?:refuted|entered-in-error)\z/i
!ll&&!rl&&r
0180
MC/DC0%0/2
$verification and $verification->{"id"} =~ /:(?:refuted|entered-in-error)\z/i
$verification $verification->{"id"} =~ /:(?:refuted|entered-in-error)\z/i
Truth table33%1/3
A and B
A= $verificationB= $verification->{"id"} =~ /:(?:refuted|entered-in-error)\z/i
ABresult
0X0
100
111
322 0 $disease->{excluded} = JSON::PP::true();
323 }
324  
325 # mCODE identifies the cancer stage through an explicit profile contract.
326 # Generic FHIR Conditions remain unchanged because arbitrary stage content
327 # cannot be interpreted safely without knowing the governing profile.
328 18 my $stage = condition_stage( $condition, $resource_index );
329 18 ▶ $disease->{stage} = $stage if $stage;
Branch: 1 branch
BranchTrueFalseTotal
if $stage 1 17 18
330  
331 18 return $disease;
332 }
333  
334 68 ▶sub _map_hpo_observation {
Subroutine _map_hpo_observation: called CC=10 SCAR=24.4
335 68 my ( $observation, $patient ) = @_;
336 68 my $feature_type = codeable_concept_to_term( $observation->{code}, 'Observation' );
337  
338 68 ▶ if ( !$feature_type || $feature_type->{id} !~ /^HP:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($feature_type and $feature_type->{"id"} =~ /^HP:/) 51 17 68
Condition66%2/3
$feature_type and $feature_type->{"id"} =~ /^HP:/
!ll&&!rl&&r
05117
MC/DC50%1/2
$feature_type and $feature_type->{"id"} =~ /^HP:/
$feature_type $feature_type->{"id"} =~ /^HP:/
Truth table66%2/3
A and B
A= $feature_typeB= $feature_type->{"id"} =~ /^HP:/
ABresult
0X0
100
111
339 my $value = codeable_concept_to_term(
340 $observation->{valueCodeableConcept},
341 51 'ObservationValue',
342 );
343 51 ▶ $feature_type = $value if $value && $value->{id} =~ /^HP:/;
Branch: 1 branch
BranchTrueFalseTotal
if $value and $value->{"id"} =~ /^HP:/ 0 51 51
Condition66%2/3
$value and $value->{"id"} =~ /^HP:/
!ll&&!rl&&r
24270
MC/DC0%0/2
$value and $value->{"id"} =~ /^HP:/
$value $value->{"id"} =~ /^HP:/
Truth table66%2/3
A and B
A= $valueB= $value->{"id"} =~ /^HP:/
ABresult
0X0
100
111
344 }
345  
346 68 ▶ return unless $feature_type && $feature_type->{id} =~ /^HP:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $feature_type and $feature_type->{"id"} =~ /^HP:/ 51 17 68
Condition66%2/3
$feature_type and $feature_type->{"id"} =~ /^HP:/
!ll&&!rl&&r
05117
MC/DC50%1/2
$feature_type and $feature_type->{"id"} =~ /^HP:/
$feature_type $feature_type->{"id"} =~ /^HP:/
Truth table66%2/3
A and B
A= $feature_typeB= $feature_type->{"id"} =~ /^HP:/
ABresult
0X0
100
111
347  
348 my $excluded = exists $observation->{valueBoolean}
349 17 ▶ && !$observation->{valueBoolean};
Condition33%1/3
exists $observation->{'valueBoolean'} && !$observation->{'valueBoolean'}
!ll&&!rl&&r
0170
MC/DC0%0/2
exists $observation->{'valueBoolean'} && !$observation->{'valueBoolean'}
exists $observation->{'valueBoolean'} !$observation->{'valueBoolean'}
Truth table33%1/3
A && not(B)
A= exists $observation->{'valueBoolean'}B= !$observation->{'valueBoolean'}
ABresult
0X0
100
111
350 17 ▶ my $feature = {
Branch: 1 branch
BranchTrueFalseTotal
$excluded ? : 0 17 17
351 featureType => $feature_type,
352 excluded => $excluded ? JSON::PP::true() : JSON::PP::false(),
353 };
354  
355 my $onset = _time_at_date(
356 _observation_datetime($observation),
357 $patient->{birthDate},
358 17 );
359 17 ▶ $feature->{onset} = $onset if $onset;
Branch: 1 branch
BranchTrueFalseTotal
if $onset 17 0 17
360  
361 17 return $feature;
362 }
363  
364 68 ▶sub _map_observation_measurements {
Subroutine _map_observation_measurements: called CC=6 SCAR=18.0
365 68 my ($observation) = @_;
366 68 my @measurements;
367  
368 my $measure = _map_measurement_part(
369 $observation->{code},
370 68 $observation,
371 $observation,
372 );
373 68 ▶ push @measurements, $measure if $measure;
Branch: 1 branch
BranchTrueFalseTotal
if $measure 66 2 68
374  
375 68 ▶ for my $component ( @{ $observation->{component} || [] } ) {
Condition100%2/2
$observation->{'component'} || []
l!l
266
MC/DC100%1/1
$observation->{'component'} || []
$observation->{'component'}
Truth table100%2/2
A
A= $observation->{'component'}
Aresult
11
00
376 5 ▶ next unless ref($component) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $component eq "HASH" 0 5 5
377 my $component_measure = _map_measurement_part(
378 $component->{code},
379 5 $component,
380 $observation,
381 );
382 5 ▶ push @measurements, $component_measure if $component_measure;
Branch: 1 branch
BranchTrueFalseTotal
if $component_measure 5 0 5
383 }
384  
385 68 return \@measurements;
386 }
387  
388 73 ▶sub _map_measurement_part {
Subroutine _map_measurement_part: called CC=5 SCAR=16.2
389 73 my ( $codeable, $value_holder, $observation ) = @_;
390 73 my $assay = codeable_concept_to_term( $codeable, 'Observation' );
391 73 ▶ return unless $assay;
Branch: 1 branch
BranchTrueFalseTotal
unless $assay 0 73 73
392  
393 73 my $value = _measurement_value( $value_holder, $observation );
394 73 ▶ return unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 2 71 73
395  
396 71 my $measure = {
397 assayCode => $assay,
398 measurementValue => $value,
399 };
400  
401 71 my $date = _date( _observation_datetime($observation) );
402 71 ▶ $measure->{date} = $date if $date;
Branch: 1 branch
BranchTrueFalseTotal
if $date 71 0 71
403  
404 my $procedure = codeable_concept_to_term(
405 $observation->{method},
406 71 'ObservationMethod',
407 );
408 71 ▶ $measure->{procedure} = { procedureCode => $procedure }
Branch: 1 branch
BranchTrueFalseTotal
if $procedure 10 61 71
409 if $procedure;
410  
411 71 return $measure;
412 }
413  
414 73 ▶sub _measurement_value {
Subroutine _measurement_value: called CC=17 SCAR=32.4
415 73 my ( $holder, $observation ) = @_;
416  
417 73 ▶ if ( ref( $holder->{valueQuantity} ) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $holder->{"valueQuantity"} eq "HASH" and defined $holder->{"valueQuantity"}{"value"} and &looks_like_number($holder->{"valueQuantity"}{"value"})) 38 35 73
Condition66%4/6
ref $holder->{"valueQuantity"} eq "HASH" and defined $holder->{"valueQuantity"}{"value"} and &looks_like_number($holder->{"valueQuantity"}{"value"})
!ll&&!rl&&r
35038
ref $holder->{"valueQuantity"} eq "HASH" and defined $holder->{"valueQuantity"}{"value"}
!ll&&!rl&&r
35038
MC/DC33%1/3
ref $holder->{"valueQuantity"} eq "HASH" and defined $holder->{"valueQuantity"}{"value"} and &looks_like_number($holder->{"valueQuantity"}{"value"})
ref $holder->{"valueQuantity"} eq "HASH" defined $holder->{"valueQuantity"}{"value"} &looks_like_number($holder->{"valueQuantity"}{"value"})
Truth table50%2/4
A and B and C
A= ref $holder->{"valueQuantity"} eq "HASH"B= defined $holder->{"valueQuantity"}{"value"}C= &looks_like_number($holder->{"valueQuantity"}{"value"})
ABCresult
0XX0
10X0
1100
1111
418 && defined $holder->{valueQuantity}{value}
419 && looks_like_number( $holder->{valueQuantity}{value} ) )
420 {
421 38 my $source = $holder->{valueQuantity};
422 my $unit = quantity_unit_to_term($source)
423 38 ▶ || dclone( $DEFAULT->{ontology_term} );
Condition33%1/3
quantity_unit_to_term($source) || &dclone($DEFAULT->{'ontology_term'})
l!l&&r!l&&!r
3800
MC/DC0%0/2
quantity_unit_to_term($source) || &dclone($DEFAULT->{'ontology_term'})
quantity_unit_to_term($source) &dclone($DEFAULT->{'ontology_term'})
Truth table33%1/3
A || B
A= quantity_unit_to_term($source)B= &dclone($DEFAULT->{'ontology_term'})
ABresult
1X1
011
000
424 my $quantity = {
425 value => 0 + $source->{value},
426 38 unit => $unit,
427 };
428  
429 38 my $range = _measurement_reference_range( $observation, $unit );
430 38 ▶ $quantity->{referenceRange} = $range if $range;
Branch: 1 branch
BranchTrueFalseTotal
if $range 18 20 38
431 38 return { quantity => $quantity };
432 }
433  
434 my $categorical = codeable_concept_to_term(
435 $holder->{valueCodeableConcept},
436 35 'ObservationValue',
437 );
438 35 ▶ return $categorical if $categorical;
Branch: 1 branch
BranchTrueFalseTotal
if $categorical 32 3 35
439  
440 3 for my $field (qw(valueInteger valueDecimal)) {
441 next unless defined $holder->{$field}
442 && !ref( $holder->{$field} )
443 5 ▶ && looks_like_number( $holder->{$field} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $holder->{$field} and not ref $holder->{$field} and &looks_like_number($holder->{$field}) 4 1 5
Condition66%4/6
defined $holder->{$field} and not ref $holder->{$field} and &looks_like_number($holder->{$field})
!ll&&!rl&&r
401
defined $holder->{$field} and not ref $holder->{$field}
!ll&&!rl&&r
401
MC/DC33%1/3
defined $holder->{$field} and not ref $holder->{$field} and &looks_like_number($holder->{$field})
defined $holder->{$field} not ref $holder->{$field} &looks_like_number($holder->{$field})
Truth table50%2/4
A and not(B) and C
A= defined $holder->{$field}B= not ref $holder->{$field}C= &looks_like_number($holder->{$field})
ABCresult
0XX0
10X0
1100
1111
444 return {
445 quantity => {
446 value => 0 + $holder->{$field},
447 1 unit => dclone( $DEFAULT->{ontology_term} ),
448 }
449 };
450 }
451  
452 2 ▶ if ( exists $holder->{valueBoolean} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $holder->{"valueBoolean"}) 0 2 2
453 0 ▶ my $label = $holder->{valueBoolean} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$holder->{'valueBoolean'} ? : 0 0 0
454 0 return source_term( 'Boolean', $label, $label );
455 }
456  
457 2 for my $field (qw(valueString valueCode valueDateTime valueDate)) {
458 next unless defined $holder->{$field}
459 && !ref( $holder->{$field} )
460 8 ▶ && length $holder->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $holder->{$field} and not ref $holder->{$field} and length $holder->{$field} 8 0 8
Condition33%2/6
defined $holder->{$field} and not ref $holder->{$field} and length $holder->{$field}
!ll&&!rl&&r
800
defined $holder->{$field} and not ref $holder->{$field}
!ll&&!rl&&r
800
MC/DC0%0/3
defined $holder->{$field} and not ref $holder->{$field} and length $holder->{$field}
defined $holder->{$field} not ref $holder->{$field} length $holder->{$field}
Truth table25%1/4
A and not(B) and C
A= defined $holder->{$field}B= not ref $holder->{$field}C= length $holder->{$field}
ABCresult
0XX0
10X0
1100
1111
461 0 return source_term( 'ObservationValue', $holder->{$field}, $holder->{$field} );
462 }
463  
464 2 return;
465 }
466  
467 38 ▶sub _measurement_reference_range {
Subroutine _measurement_reference_range: called CC=12 SCAR=31.5
468 38 my ( $observation, $fallback_unit ) = @_;
469  
470 38 ▶ for my $range ( @{ $observation->{referenceRange} || [] } ) {
Condition100%2/2
$observation->{'referenceRange'} || []
l!l
1820
MC/DC100%1/1
$observation->{'referenceRange'} || []
$observation->{'referenceRange'}
Truth table100%2/2
A
A= $observation->{'referenceRange'}
Aresult
11
00
471 18 ▶ next unless ref($range) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $range eq "HASH" 0 18 18
472 next unless ref( $range->{low} ) eq 'HASH'
473 18 ▶ && ref( $range->{high} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $range->{"low"} eq "HASH" and ref $range->{"high"} eq "HASH" 0 18 18
Condition33%1/3
ref $range->{"low"} eq "HASH" and ref $range->{"high"} eq "HASH"
!ll&&!rl&&r
0018
MC/DC0%0/2
ref $range->{"low"} eq "HASH" and ref $range->{"high"} eq "HASH"
ref $range->{"low"} eq "HASH" ref $range->{"high"} eq "HASH"
Truth table33%1/3
A and B
A= ref $range->{"low"} eq "HASH"B= ref $range->{"high"} eq "HASH"
ABresult
0X0
100
111
474 next unless defined $range->{low}{value}
475 && defined $range->{high}{value}
476 && looks_like_number( $range->{low}{value} )
477 18 ▶ && looks_like_number( $range->{high}{value} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $range->{"low"}{"value"} and defined $range->{"high"}{"value"} and &looks_like_number($range->{"low"}{"value"}) and &looks_like_number($range->{"high"}{"value"}) 0 18 18
Condition33%3/9
defined $range->{"low"}{"value"} and defined $range->{"high"}{"value"} and &looks_like_number($range->{"low"}{"value"}) and &looks_like_number($range->{"high"}{"value"})
!ll&&!rl&&r
0018
defined $range->{"low"}{"value"} and defined $range->{"high"}{"value"} and &looks_like_number($range->{"low"}{"value"})
!ll&&!rl&&r
0018
defined $range->{"low"}{"value"} and defined $range->{"high"}{"value"}
!ll&&!rl&&r
0018
MC/DC0%0/4
defined $range->{"low"}{"value"} and defined $range->{"high"}{"value"} and &looks_like_number($range->{"low"}{"value"}) and &looks_like_number($range->{"high"}{"value"})
defined $range->{"low"}{"value"} defined $range->{"high"}{"value"} &looks_like_number($range->{"low"}{"value"}) &looks_like_number($range->{"high"}{"value"})
Truth table20%1/5
A and B and C and D
A= defined $range->{"low"}{"value"}B= defined $range->{"high"}{"value"}C= &looks_like_number($range->{"low"}{"value"})D= &looks_like_number($range->{"high"}{"value"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
478  
479 my $unit = quantity_unit_to_term( $range->{low} )
480 || quantity_unit_to_term( $range->{high} )
481 18 ▶ || dclone($fallback_unit);
Condition33%2/6
quantity_unit_to_term($range->{'low'}) || quantity_unit_to_term($range->{'high'}) || &dclone($fallback_unit)
l!l&&r!l&&!r
1800
quantity_unit_to_term($range->{"low"}) or quantity_unit_to_term($range->{"high"})
l!l&&r!l&&!r
1800
MC/DC0%0/3
quantity_unit_to_term($range->{'low'}) || quantity_unit_to_term($range->{'high'}) || &dclone($fallback_unit)
quantity_unit_to_term($range->{"low"}) quantity_unit_to_term($range->{"high"}) &dclone($fallback_unit)
Truth table25%1/4
A or B || C
A= quantity_unit_to_term($range->{"low"})B= quantity_unit_to_term($range->{"high"})C= &dclone($fallback_unit)
ABCresult
1XX1
01X1
0011
0000
482 return {
483 low => 0 + $range->{low}{value},
484 high => 0 + $range->{high}{value},
485 18 unit => $unit,
486 };
487 }
488  
489 20 return;
490 }
491  
492 21 ▶sub _map_procedure {
Subroutine _map_procedure: called CC=8 SCAR=21.2
493 21 my ($resource) = @_;
494 21 my $code = codeable_concept_to_term( $resource->{code}, 'Procedure' );
495 21 ▶ return unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 21 21
496  
497 21 my $procedure = { procedureCode => $code };
498 21 my $performed = $resource->{performedDateTime};
499 $performed = $resource->{performedPeriod}{start}
500 21 ▶ if !defined $performed && ref( $resource->{performedPeriod} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $performed and ref $resource->{"performedPeriod"} eq "HASH" 18 3 21
Condition66%2/3
not defined $performed and ref $resource->{"performedPeriod"} eq "HASH"
!ll&&!rl&&r
3018
MC/DC50%1/2
not defined $performed and ref $resource->{"performedPeriod"} eq "HASH"
not defined $performed ref $resource->{"performedPeriod"} eq "HASH"
Truth table66%2/3
not(A) and B
A= not defined $performedB= ref $resource->{"performedPeriod"} eq "HASH"
ABresult
0X0
100
111
501 21 my $date = _date($performed);
502 21 ▶ $procedure->{dateOfProcedure} = $date if $date;
Branch: 1 branch
BranchTrueFalseTotal
if $date 21 0 21
503  
504 21 ▶ if ( ref( $resource->{bodySite} ) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $resource->{"bodySite"} eq "ARRAY" and @{$resource->{"bodySite"};}) 3 18 21
Condition66%2/3
ref $resource->{"bodySite"} eq "ARRAY" and @{$resource->{"bodySite"};}
!ll&&!rl&&r
1803
MC/DC50%1/2
ref $resource->{"bodySite"} eq "ARRAY" and @{$resource->{"bodySite"};}
ref $resource->{"bodySite"} eq "ARRAY" @{$resource->{"bodySite"};}
Truth table66%2/3
A and B
A= ref $resource->{"bodySite"} eq "ARRAY"B= @{$resource->{"bodySite"};}
ABresult
0X0
100
111
505 3 && @{ $resource->{bodySite} } )
506 {
507 my $body_site = codeable_concept_to_term(
508 3 $resource->{bodySite}[0],
509 'BodySite',
510 );
511 3 ▶ $procedure->{bodySite} = $body_site if $body_site;
Branch: 1 branch
BranchTrueFalseTotal
if $body_site 3 0 3
512 }
513  
514 21 return $procedure;
515 }
516  
517 21 ▶sub _map_medication {
Subroutine _map_medication: called CC=12 SCAR=30.4
518 21 my ( $resource, $index, $patient ) = @_;
519 my $code = codeable_concept_to_term(
520 $resource->{medicationCodeableConcept},
521 21 'Medication',
522 );
523  
524 21 ▶ if ( !$code && ref( $resource->{medicationReference} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $code and ref $resource->{"medicationReference"} eq "HASH") 0 21 21
Condition33%1/3
not $code and ref $resource->{"medicationReference"} eq "HASH"
!ll&&!rl&&r
2100
MC/DC0%0/2
not $code and ref $resource->{"medicationReference"} eq "HASH"
not $code ref $resource->{"medicationReference"} eq "HASH"
Truth table33%1/3
not(A) and B
A= not $codeB= ref $resource->{"medicationReference"} eq "HASH"
ABresult
0X0
100
111
525 0 my $reference = $resource->{medicationReference}{reference};
526 0 my $medication = _resolve_local_or_bundle_reference(
527 $resource,
528 $index,
529 $reference,
530 );
531 0 ▶ $code = codeable_concept_to_term( $medication->{code}, 'Medication' )
Branch: 1 branch
BranchTrueFalseTotal
if $medication 0 0 0
532 if $medication;
533 }
534 21 ▶ return unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 21 21
535  
536 21 my $treatment = { treatmentCode => $code };
537 21 my $dosage = _first_dosage($resource);
538 21 ▶ if ($dosage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dosage) 21 0 21
539 my $route = codeable_concept_to_term(
540 $dosage->{route},
541 21 'RouteOfAdministration',
542 );
543 21 ▶ $treatment->{routeOfAdministration} = $route if $route;
Branch: 1 branch
BranchTrueFalseTotal
if $route 4 17 21
544 }
545  
546 21 my $start = $resource->{authoredOn};
547 $start = $resource->{effectiveDateTime}
548 21 ▶ if !defined $start && defined $resource->{effectiveDateTime};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $start and defined $resource->{"effectiveDateTime"} 0 21 21
Condition33%1/3
not defined $start and defined $resource->{"effectiveDateTime"}
!ll&&!rl&&r
2100
MC/DC0%0/2
not defined $start and defined $resource->{"effectiveDateTime"}
not defined $start defined $resource->{"effectiveDateTime"}
Truth table33%1/3
not(A) and B
A= not defined $startB= defined $resource->{"effectiveDateTime"}
ABresult
0X0
100
111
549 $start = $resource->{effectivePeriod}{start}
550 21 ▶ if !defined $start && ref( $resource->{effectivePeriod} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $start and ref $resource->{"effectivePeriod"} eq "HASH" 0 21 21
Condition33%1/3
not defined $start and ref $resource->{"effectivePeriod"} eq "HASH"
!ll&&!rl&&r
2100
MC/DC0%0/2
not defined $start and ref $resource->{"effectivePeriod"} eq "HASH"
not defined $start ref $resource->{"effectivePeriod"} eq "HASH"
Truth table33%1/3
not(A) and B
A= not defined $startB= ref $resource->{"effectivePeriod"} eq "HASH"
ABresult
0X0
100
111
551 21 my $age = _time_at_date( $start, $patient->{birthDate} );
552 21 ▶ $treatment->{ageOfOnset} = $age if $age;
Branch: 1 branch
BranchTrueFalseTotal
if $age 21 0 21
553  
554 21 return $treatment;
555 }
556  
557 21 ▶sub _first_dosage {
Subroutine _first_dosage: called CC=8 SCAR=28.3
558 21 my ($resource) = @_;
559  
560 return $resource->{dosage}
561 21 ▶ if ref( $resource->{dosage} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $resource->{"dosage"} eq "HASH" 0 21 21
562 return $resource->{dosage}[0]
563 if ref( $resource->{dosage} ) eq 'ARRAY'
564 0 && @{ $resource->{dosage} }
565 21 ▶ && ref( $resource->{dosage}[0] ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $resource->{"dosage"} eq "ARRAY" and @{$resource->{"dosage"};} and ref $resource->{"dosage"}[0] eq "HASH" 0 21 21
Condition33%2/6
ref $resource->{"dosage"} eq "ARRAY" and @{$resource->{"dosage"};} and ref $resource->{"dosage"}[0] eq "HASH"
!ll&&!rl&&r
2100
ref $resource->{"dosage"} eq "ARRAY" and @{$resource->{"dosage"};}
!ll&&!rl&&r
2100
MC/DC0%0/3
ref $resource->{"dosage"} eq "ARRAY" and @{$resource->{"dosage"};} and ref $resource->{"dosage"}[0] eq "HASH"
ref $resource->{"dosage"} eq "ARRAY" @{$resource->{"dosage"};} ref $resource->{"dosage"}[0] eq "HASH"
Truth table25%1/4
A and B and C
A= ref $resource->{"dosage"} eq "ARRAY"B= @{$resource->{"dosage"};}C= ref $resource->{"dosage"}[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
566 return $resource->{dosageInstruction}[0]
567 if ref( $resource->{dosageInstruction} ) eq 'ARRAY'
568 21 && @{ $resource->{dosageInstruction} }
569 21 ▶ && ref( $resource->{dosageInstruction}[0] ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $resource->{"dosageInstruction"} eq "ARRAY" and @{$resource->{"dosageInstruction"};} and ref $resource->{"dosageInstruction"}[0] eq "HASH" 21 0 21
Condition33%2/6
ref $resource->{"dosageInstruction"} eq "ARRAY" and @{$resource->{"dosageInstruction"};} and ref $resource->{"dosageInstruction"}[0] eq "HASH"
!ll&&!rl&&r
0021
ref $resource->{"dosageInstruction"} eq "ARRAY" and @{$resource->{"dosageInstruction"};}
!ll&&!rl&&r
0021
MC/DC0%0/3
ref $resource->{"dosageInstruction"} eq "ARRAY" and @{$resource->{"dosageInstruction"};} and ref $resource->{"dosageInstruction"}[0] eq "HASH"
ref $resource->{"dosageInstruction"} eq "ARRAY" @{$resource->{"dosageInstruction"};} ref $resource->{"dosageInstruction"}[0] eq "HASH"
Truth table25%1/4
A and B and C
A= ref $resource->{"dosageInstruction"} eq "ARRAY"B= @{$resource->{"dosageInstruction"};}C= ref $resource->{"dosageInstruction"}[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
570  
571 0 return;
572 }
573  
574 0 ▶sub _resolve_local_or_bundle_reference {
Subroutine _resolve_local_or_bundle_reference: not called CC=9 SCAR=45.0
575 0 my ( $owner, $index, $reference ) = @_;
576 0 ▶ return unless defined $reference && !ref($reference);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reference and not ref $reference 0 0 0
Condition0%0/3
defined $reference and not ref $reference
!ll&&!rl&&r
000
MC/DC0%0/2
defined $reference and not ref $reference
defined $reference not ref $reference
Truth table0%0/3
A and not(B)
A= defined $referenceB= not ref $reference
ABresult
0X0
100
111
577  
578 0 ▶ if ( $reference =~ /^#(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reference =~ /^#(.+)/) 0 0 0
579 0 my $id = $1;
580 0 ▶ for my $contained ( @{ $owner->{contained} || [] } ) {
Condition0%0/2
$owner->{'contained'} || []
l!l
00
MC/DC0%0/1
$owner->{'contained'} || []
$owner->{'contained'}
Truth table0%0/2
A
A= $owner->{'contained'}
Aresult
11
00
581 0 ▶ next unless ref($contained) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $contained eq "HASH" 0 0 0
582 return $contained
583 0 ▶ if defined $contained->{id} && $contained->{id} eq $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $contained->{"id"} and $contained->{"id"} eq $id 0 0 0
Condition0%0/3
defined $contained->{"id"} and $contained->{"id"} eq $id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $contained->{"id"} and $contained->{"id"} eq $id
defined $contained->{"id"} $contained->{"id"} eq $id
Truth table0%0/3
A and B
A= defined $contained->{"id"}B= $contained->{"id"} eq $id
ABresult
0X0
100
111
584 }
585 0 return;
586 }
587  
588 0 return resolve_reference( $index, $reference );
589 }
590  
591 18 ▶sub _map_specimen {
Subroutine _map_specimen: called CC=23 SCAR=36.2
592 18 my ( $self, $specimen, $individual_id, $observations, $index ) = @_;
593 18 my $id = $specimen->{id};
594 18 ▶ return unless defined $id && !ref($id) && length $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and not ref $id and length $id 0 18 18
Condition33%2/6
defined $id and not ref $id and length $id
!ll&&!rl&&r
0018
defined $id and not ref $id
!ll&&!rl&&r
0018
MC/DC0%0/3
defined $id and not ref $id and length $id
defined $id not ref $id length $id
Truth table25%1/4
A and not(B) and C
A= defined $idB= not ref $idC= length $id
ABCresult
0XX0
10X0
1100
1111
595  
596 18 ▶ my $status_code = lc( $specimen->{status} // 'unknown' );
Condition50%1/2
$specimen->{"status"} // "unknown"
l!l
180
MC/DC0%0/1
$specimen->{"status"} // "unknown"
$specimen->{"status"}
Truth table50%1/2
A
A= $specimen->{"status"}
Aresult
11
00
597 # Specimen.status is a required FHIR code: preserve that source identity
598 # instead of inferring a cross-ontology term, but use its canonical display.
599 my $status = source_term(
600 'SpecimenStatus',
601 $status_code,
602 18 ▶ $SPECIMEN_STATUS_DISPLAY{$status_code} // $status_code,
Condition33%1/3
$SPECIMEN_STATUS_DISPLAY{$status_code} // $status_code
l!l&&r!l&&!r
1800
MC/DC0%0/2
$SPECIMEN_STATUS_DISPLAY{$status_code} // $status_code
$SPECIMEN_STATUS_DISPLAY{$status_code} $status_code
Truth table33%1/3
A // B
A= $SPECIMEN_STATUS_DISPLAY{$status_code}B= $status_code
ABresult
1X1
011
000
603 );
604 my $origin = codeable_concept_to_term( $specimen->{type}, 'SpecimenType' )
605 18 ▶ || dclone( $DEFAULT->{ontology_term} );
Condition33%1/3
codeable_concept_to_term($specimen->{'type'}, 'SpecimenType') || &dclone($DEFAULT->{'ontology_term'})
l!l&&r!l&&!r
1800
MC/DC0%0/2
codeable_concept_to_term($specimen->{'type'}, 'SpecimenType') || &dclone($DEFAULT->{'ontology_term'})
codeable_concept_to_term($specimen->{'type'}, 'SpecimenType') &dclone($DEFAULT->{'ontology_term'})
Truth table33%1/3
A || B
A= codeable_concept_to_term($specimen->{'type'}, 'SpecimenType')B= &dclone($DEFAULT->{'ontology_term'})
ABresult
1X1
011
000
606  
607 18 my $biosample = {
608 id => $id,
609 individualId => $individual_id,
610 biosampleStatus => $status,
611 sampleOriginType => $origin,
612 };
613  
614 18 ▶ if ( ref( $specimen->{collection} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $specimen->{"collection"} eq "HASH") 18 0 18
615 18 my $collection = $specimen->{collection};
616 18 my $date = _date( $collection->{collectedDateTime} );
617 18 ▶ $biosample->{collectionDate} = $date if $date;
Branch: 1 branch
BranchTrueFalseTotal
if $date 17 1 18
618  
619 my $body_site = codeable_concept_to_term(
620 $collection->{bodySite},
621 18 'BodySite',
622 );
623 18 ▶ $biosample->{sampleOriginDetail} = $body_site if $body_site;
Branch: 1 branch
BranchTrueFalseTotal
if $body_site 18 0 18
624  
625 my $method = codeable_concept_to_term(
626 $collection->{method},
627 18 'SpecimenCollectionMethod',
628 );
629 18 ▶ $biosample->{obtentionProcedure} = { procedureCode => $method }
Branch: 1 branch
BranchTrueFalseTotal
if $method 0 18 18
630 if $method;
631 }
632  
633 0 my @notes = map { $_->{text} }
634 0 ▶ grep { ref($_) eq 'HASH' && defined $_->{text} && !ref( $_->{text} ) }
Condition0%0/6
ref $_ eq 'HASH' && defined $_->{'text'} && !ref($_->{'text'})
!ll&&!rl&&r
000
ref $_ eq "HASH" and defined $_->{"text"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_ eq 'HASH' && defined $_->{'text'} && !ref($_->{'text'})
ref $_ eq "HASH" defined $_->{"text"} !ref($_->{'text'})
Truth table0%0/4
A and B && not(C)
A= ref $_ eq "HASH"B= defined $_->{"text"}C= !ref($_->{'text'})
ABCresult
0XX0
10X0
1100
1111
635 18 ▶ @{ $specimen->{note} || [] };
Condition50%1/2
$specimen->{'note'} || []
l!l
018
MC/DC0%0/1
$specimen->{'note'} || []
$specimen->{'note'}
Truth table50%1/2
A
A= $specimen->{'note'}
Aresult
11
00
636 18 ▶ $biosample->{notes} = join( "\n", @notes ) if @notes;
Branch: 1 branch
BranchTrueFalseTotal
if @notes 0 18 18
637  
638 18 my @measurements;
639 my @source_observations;
640 18 for my $observation ( @{$observations} ) {
641 22 my $reference = $observation->{specimen}{reference};
642 22 my $resolved = resolve_reference( $index, $reference );
643 22 ▶ my $matches = $resolved
Branch: 1 branch
BranchTrueFalseTotal
$resolved ? : 17 5 22
Condition50%1/2
canonical_reference($reference) || ''
l!l
50
MC/DC0%0/1
canonical_reference($reference) || ''
canonical_reference($reference)
Truth table50%1/2
A
A= canonical_reference($reference)
Aresult
11
00
644 ? refaddr($resolved) == refaddr($specimen)
645 : ( canonical_reference($reference) || q{} ) eq "Specimen/$id";
646 22 ▶ next unless $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless $matches 5 17 22
647  
648 17 push @source_observations, $observation;
649 17 push @measurements, @{ _map_observation_measurements($observation) };
650 }
651 18 ▶ $biosample->{measurements} = \@measurements if @measurements;
Branch: 1 branch
BranchTrueFalseTotal
if @measurements 17 1 18
652  
653 18 ▶ if ( $self->{source_info} // 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"source_info"} // 1) 17 1 18
Condition50%1/2
$self->{"source_info"} // 1
l!l
180
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
Aresult
11
00
654 # FHIR Observation.specimen is the provenance for deciding that these
655 # measurements belong to this biosample rather than to the individual.
656 $biosample->{info}{fhir} = {
657 17 version => 'R4',
658 specimen => dclone($specimen),
659 };
660 17 ▶ $biosample->{info}{fhir}{observations} = dclone(\@source_observations)
Branch: 1 branch
BranchTrueFalseTotal
if @source_observations 16 1 17
661 if @source_observations;
662 }
663  
664 18 return $biosample;
665 }
666  
667 88 ▶sub _observation_datetime {
Subroutine _observation_datetime: called CC=5 SCAR=28.4
668 88 my ($observation) = @_;
669 return $observation->{effectiveDateTime}
670 88 ▶ if defined $observation->{effectiveDateTime};
Branch: 1 branch
BranchTrueFalseTotal
if defined $observation->{"effectiveDateTime"} 88 0 88
671 return $observation->{effectivePeriod}{start}
672 if ref( $observation->{effectivePeriod} ) eq 'HASH'
673 0 ▶ && defined $observation->{effectivePeriod}{start};
Branch: 1 branch
BranchTrueFalseTotal
if ref $observation->{"effectivePeriod"} eq "HASH" and defined $observation->{"effectivePeriod"}{"start"} 0 0 0
Condition0%0/3
ref $observation->{"effectivePeriod"} eq "HASH" and defined $observation->{"effectivePeriod"}{"start"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $observation->{"effectivePeriod"} eq "HASH" and defined $observation->{"effectivePeriod"}{"start"}
ref $observation->{"effectivePeriod"} eq "HASH" defined $observation->{"effectivePeriod"}{"start"}
Truth table0%0/3
A and B
A= ref $observation->{"effectivePeriod"} eq "HASH"B= defined $observation->{"effectivePeriod"}{"start"}
ABresult
0X0
100
111
674 0 ▶ return $observation->{issued} if defined $observation->{issued};
Branch: 1 branch
BranchTrueFalseTotal
if defined $observation->{"issued"} 0 0 0
675 0 return;
676 }
677  
678 74 ▶sub _time_at_date {
Subroutine _time_at_date: called CC=9 SCAR=26.7
679 74 my ( $timestamp, $birth_date ) = @_;
680 74 ▶ return unless defined $timestamp && !ref($timestamp);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timestamp and not ref $timestamp 1 73 74
Condition66%2/3
defined $timestamp and not ref $timestamp
!ll&&!rl&&r
1073
MC/DC50%1/2
defined $timestamp and not ref $timestamp
defined $timestamp not ref $timestamp
Truth table66%2/3
A and not(B)
A= defined $timestampB= not ref $timestamp
ABresult
0X0
100
111
681  
682 73 my $date = _date($timestamp);
683 73 ▶ return unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 73 73
684  
685 73 ▶ if ( defined $birth_date && !ref($birth_date) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $birth_date and not ref $birth_date) 73 0 73
Condition33%1/3
defined $birth_date and not ref $birth_date
!ll&&!rl&&r
0073
MC/DC0%0/2
defined $birth_date and not ref $birth_date
defined $birth_date not ref $birth_date
Truth table33%1/3
A and not(B)
A= defined $birth_dateB= not ref $birth_date
ABresult
0X0
100
111
686 73 my $duration = get_age_from_date_and_birthday(
687 {
688 date => $date,
689 birth_day => $birth_date,
690 }
691 );
692 73 ▶ return { age => { iso8601duration => $duration } }
Branch: 1 branch
BranchTrueFalseTotal
if defined $duration and $duration =~ /^P\d+Y\z/ 73 0 73
Condition33%1/3
defined $duration and $duration =~ /^P\d+Y\z/
!ll&&!rl&&r
0073
MC/DC0%0/2
defined $duration and $duration =~ /^P\d+Y\z/
defined $duration $duration =~ /^P\d+Y\z/
Truth table33%1/3
A and B
A= defined $durationB= $duration =~ /^P\d+Y\z/
ABresult
0X0
100
111
693 if defined $duration && $duration =~ /^P\d+Y\z/;
694 }
695  
696 0 ▶ return $timestamp =~ /^\d{4}-\d{2}-\d{2}T/
Branch: 1 branch
BranchTrueFalseTotal
$timestamp =~ /^\d{4}-\d{2}-\d{2}T/ ? : 0 0 0
697 ? $timestamp
698 : $date . 'T00:00:00Z';
699 }
700  
701 183 ▶sub _date {
Subroutine _date: called CC=4 SCAR=14.6
702 183 my ($value) = @_;
703 183 ▶ return unless defined $value && !ref($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 1 182 183
Condition66%2/3
defined $value and not ref $value
!ll&&!rl&&r
10182
MC/DC50%1/2
defined $value and not ref $value
defined $value not ref $value
Truth table66%2/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
704 182 ▶ return $1 if $value =~ /^(\d{4}-\d{2}-\d{2})/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(\d{4}-\d{2}-\d{2})/ 182 0 182
705 0 return;
706 }
707  
708 131 ▶sub _push_mapped {
Subroutine _push_mapped: called CC=2 SCAR=7.0
709 131 my ( $target, $field, $value ) = @_;
710 131 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 131 131
711 131 push @{ $target->{$field} }, $value;
712 131 return 1;
713 }
714  
715 17 ▶sub _unmapped_resource_types {
Subroutine _unmapped_resource_types: called CC=4 SCAR=14.0
716 17 my ($resources) = @_;
717 17 my %seen;
718 180 ▶ return sort grep { !$MAPPED_RESOURCE{$_} && !$seen{$_}++ }
Condition100%3/3
$MAPPED_RESOURCE{$_} || $seen{$_}++
l!l&&r!l&&!r
160218
MC/DC100%2/2
$MAPPED_RESOURCE{$_} || $seen{$_}++
$MAPPED_RESOURCE{$_} $seen{$_}++
Truth table100%3/3
A || B
A= $MAPPED_RESOURCE{$_}B= $seen{$_}++
ABresult
1X1
011
000
719 180 ▶ map { ref($_) eq 'HASH' ? ( $_->{resourceType} || 'Unknown' ) : 'Unknown' }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 180 0 180
Condition50%1/2
$_->{"resourceType"} or "Unknown"
l!l
1800
MC/DC0%0/1
$_->{"resourceType"} or "Unknown"
$_->{"resourceType"}
Truth table50%1/2
A
A= $_->{"resourceType"}
Aresult
11
00
720 17 @{$resources};
721 }
722  
723 18 ▶sub _context_requests_entity {
Subroutine _context_requests_entity: called CC=1 SCAR=0.0
724 18 my ( $context, $entity ) = @_;
725 18 return scalar grep { $_ eq $entity } @{ $context->entities };
726 }
727  
728 136 1;
« lib/Convert/Pheno/Source/CDISC/DatasetXML.pm ↑ Summary lib/Convert/Pheno/CDISC/SDTM/Normalizer.pm »