lib/Convert/Pheno/Source/FHIR.pm

filter: Statementstmt 94.0% 175 / 186 Branchbran 69.3% 61 / 88 Conditioncond 41.4% 46 / 111 MC/DCmcdc 11.6% 7 / 60 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 3 totaltotal 65.8% 306 / 465 CC 98 SCAR 34.3
CC
98
Cov
73%
_resource_identifier
64.1
_normalize_bundles
52.2
_derived_entity_overrides
27.9
CRAP 30.9
« lib/Convert/Pheno/CDISC/SDTM/Terminology.pm ↑ Summary lib/Convert/Pheno/FHIR/Profile/MCode.pm »
1 package Convert::Pheno::Source::FHIR;
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 Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 136 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 136 ▶use Convert::Pheno::FHIR::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 canonical_reference
11 reference_aliases
12 resolve_reference
13 136 );
14 136 ▶use Convert::Pheno::IO::FileIO qw(read_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 136 ▶use Convert::Pheno::Mapping::Shared qw(get_info);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 136 ▶use Convert::Pheno::Source::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 136 my %BUNDLE_TYPE = map { $_ => 1 } qw(
19 batch
20 batch-response
21 collection
22 document
23 history
24 message
25 searchset
26 transaction
27 transaction-response
28 );
29  
30 22 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
31 22 my ( $class, $converter ) = @_;
32 22 return bless { converter => $converter }, $class;
33 }
34  
35 22 ▶sub load {
Subroutine load: called CC=8 SCAR=21.1
Pod undocumented
36 22 my ($self) = @_;
37 22 my $converter = $self->{converter};
38  
39 22 my ( @bundles, @labels );
40 22 ▶ if ( exists $converter->{data} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $converter->{'data'}) { } 11 11 22
41 11 my $data = $converter->{data};
42 11 ▶ my @documents = ref($data) eq 'ARRAY' ? @{$data} : ($data);
Branch: 1 branch
BranchTrueFalseTotal
ref $data eq 'ARRAY' ? : 1 10 11
43 11 @bundles = map { dclone($_) } @documents;
44 11 @labels = map { 'in-memory FHIR Bundle ' . ( $_ + 1 ) }
45 0 .. $#bundles;
46 }
47 else {
48 11 ▶ my @files = @{ $converter->{in_files} || [] };
Condition50%1/2
$converter->{'in_files'} || []
l!l
110
MC/DC0%0/1
$converter->{'in_files'} || []
$converter->{'in_files'}
Truth table50%1/2
A
A= $converter->{'in_files'}
Aresult
11
00
49 push @files, $converter->{in_file}
50 11 ▶ if !@files && defined $converter->{in_file};
Branch: 1 branch
BranchTrueFalseTotal
if not @files and defined $converter->{"in_file"} 0 11 11
Condition33%1/3
not @files and defined $converter->{"in_file"}
!ll&&!rl&&r
1100
MC/DC0%0/2
not @files and defined $converter->{"in_file"}
not @files defined $converter->{"in_file"}
Truth table33%1/3
not(A) and B
A= not @filesB= defined $converter->{"in_file"}
ABresult
0X0
100
111
51 11 ▶ die "FHIR input requires at least one JSON Bundle file\n" unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 11 11
52  
53 11 for my $file (@files) {
54 11 push @bundles, read_json($file);
55 11 push @labels, $file;
56 }
57 }
58  
59 22 my $normalized = _normalize_bundles( \@bundles, \@labels );
60  
61 return Convert::Pheno::Source::Result->new(
62 {
63 data => $normalized->{patients},
64 owned => 1,
65 artifacts => {
66 bundle_metadata => $normalized->{bundle_metadata},
67 unassigned_resources => $normalized->{unassigned_resources},
68 20 derived_entity_overrides => _derived_entity_overrides(
69 $converter,
70 $normalized,
71 ),
72 },
73 }
74 );
75 }
76  
77 22 ▶sub _normalize_bundles {
Subroutine _normalize_bundles: called CC=36 SCAR=39.5
78 22 my ( $bundles, $labels ) = @_;
79 22 ▶ die "FHIR input does not contain any Bundle documents\n" unless @{$bundles};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$bundles;} 0 22 22
80  
81 22 my ( @records, @bundle_metadata );
82 22 for my $index ( 0 .. $#{$bundles} ) {
83 23 my $bundle = $bundles->[$index];
84 23 my $label = $labels->[$index];
85  
86 23 ▶ die "FHIR input <$label> must contain a JSON object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $bundle eq "HASH" 0 23 23
87 unless ref($bundle) eq 'HASH';
88 die "FHIR input <$label> must contain a FHIR Bundle resource\n"
89 23 ▶ unless ( $bundle->{resourceType} || q{} ) eq 'Bundle';
Branch: 1 branch
BranchTrueFalseTotal
unless ($bundle->{"resourceType"} || "") eq "Bundle" 0 23 23
Condition50%1/2
$bundle->{'resourceType'} || ''
l!l
230
MC/DC0%0/1
$bundle->{'resourceType'} || ''
$bundle->{'resourceType'}
Truth table50%1/2
A
A= $bundle->{'resourceType'}
Aresult
11
00
90 die "FHIR Bundle <$label> has an invalid or missing type\n"
91 unless defined $bundle->{type}
92 && !ref( $bundle->{type} )
93 23 ▶ && $BUNDLE_TYPE{ $bundle->{type} };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bundle->{"type"} and not ref $bundle->{"type"} and $BUNDLE_TYPE{$bundle->{"type"}} 1 22 23
Condition50%3/6
defined $bundle->{"type"} and not ref $bundle->{"type"} and $BUNDLE_TYPE{$bundle->{"type"}}
!ll&&!rl&&r
0122
defined $bundle->{"type"} and not ref $bundle->{"type"}
!ll&&!rl&&r
0023
MC/DC33%1/3
defined $bundle->{"type"} and not ref $bundle->{"type"} and $BUNDLE_TYPE{$bundle->{"type"}}
defined $bundle->{"type"} not ref $bundle->{"type"} $BUNDLE_TYPE{$bundle->{"type"}}
Truth table50%2/4
A and not(B) and C
A= defined $bundle->{"type"}B= not ref $bundle->{"type"}C= $BUNDLE_TYPE{$bundle->{"type"}}
ABCresult
0XX0
10X0
1100
1111
94 die "FHIR Bundle <$label> must contain an entry array\n"
95 22 ▶ unless ref( $bundle->{entry} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $bundle->{"entry"} eq "ARRAY" 0 22 22
96  
97 22 push @bundle_metadata, _bundle_metadata( $bundle, $label );
98  
99 22 for my $entry_index ( 0 .. $#{ $bundle->{entry} } ) {
100 271 my $entry = $bundle->{entry}[$entry_index];
101 271 my $number = $entry_index + 1;
102 271 ▶ die "FHIR Bundle <$label> entry $number must contain an object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry eq "HASH" 0 271 271
103 unless ref($entry) eq 'HASH';
104 die "FHIR Bundle <$label> entry $number is missing its resource object\n"
105 271 ▶ unless ref( $entry->{resource} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry->{"resource"} eq "HASH" 0 271 271
106  
107 271 my $resource = $entry->{resource};
108 die "FHIR Bundle <$label> entry $number is missing resourceType\n"
109 unless defined $resource->{resourceType}
110 && !ref( $resource->{resourceType} )
111 271 ▶ && length $resource->{resourceType};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $resource->{"resourceType"} and not ref $resource->{"resourceType"} and length $resource->{"resourceType"} 0 271 271
Condition33%2/6
defined $resource->{"resourceType"} and not ref $resource->{"resourceType"} and length $resource->{"resourceType"}
!ll&&!rl&&r
00271
defined $resource->{"resourceType"} and not ref $resource->{"resourceType"}
!ll&&!rl&&r
00271
MC/DC0%0/3
defined $resource->{"resourceType"} and not ref $resource->{"resourceType"} and length $resource->{"resourceType"}
defined $resource->{"resourceType"} not ref $resource->{"resourceType"} length $resource->{"resourceType"}
Truth table25%1/4
A and not(B) and C
A= defined $resource->{"resourceType"}B= not ref $resource->{"resourceType"}C= length $resource->{"resourceType"}
ABCresult
0XX0
10X0
1100
1111
112  
113 push @records,
114 {
115 resource => $resource,
116 fullUrl => $entry->{fullUrl},
117 271 bundleIndex => $index,
118 label => "$label entry $number",
119 };
120 }
121 }
122  
123 21 my %index;
124 21 for my $record (@records) {
125 271 for my $alias (
126 271 @{ reference_aliases( $record->{resource}, $record->{fullUrl} ) }
127 )
128 {
129 540 ▶ if ( exists $index{$alias}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index{$alias} and builtin::refaddr($index{$alias}) != builtin::refaddr($record->{"resource"})) 2 538 540
Condition66%2/3
exists $index{$alias} and builtin::refaddr($index{$alias}) != builtin::refaddr($record->{"resource"})
!ll&&!rl&&r
53802
MC/DC50%1/2
exists $index{$alias} and builtin::refaddr($index{$alias}) != builtin::refaddr($record->{"resource"})
exists $index{$alias} builtin::refaddr($index{$alias}) != builtin::refaddr($record->{"resource"})
Truth table66%2/3
A and B
A= exists $index{$alias}B= builtin::refaddr($index{$alias}) != builtin::refaddr($record->{"resource"})
ABresult
0X0
100
111
130 && refaddr( $index{$alias} ) != refaddr( $record->{resource} ) )
131 {
132 2 my $previous = $index{$alias};
133 next
134 if $previous->{resourceType} eq 'Patient'
135 && $record->{resource}{resourceType} eq 'Patient'
136 && defined $previous->{id}
137 && defined $record->{resource}{id}
138 2 ▶ && $previous->{id} eq $record->{resource}{id};
Branch: 1 branch
BranchTrueFalseTotal
if $previous->{"resourceType"} eq "Patient" and $record->{"resource"}{"resourceType"} eq "Patient" and defined $previous->{"id"} and defined $record->{"resource"}{"id"} and $previous->{"id"} eq $record->{"resource"}{"id"} 2 0 2
Condition33%4/12
$previous->{"resourceType"} eq "Patient" and $record->{"resource"}{"resourceType"} eq "Patient" and defined $previous->{"id"} and defined $record->{"resource"}{"id"} and $previous->{"id"} eq $record->{"resource"}{"id"}
!ll&&!rl&&r
002
$previous->{"resourceType"} eq "Patient" and $record->{"resource"}{"resourceType"} eq "Patient" and defined $previous->{"id"} and defined $record->{"resource"}{"id"}
!ll&&!rl&&r
002
$previous->{"resourceType"} eq "Patient" and $record->{"resource"}{"resourceType"} eq "Patient" and defined $previous->{"id"}
!ll&&!rl&&r
002
$previous->{"resourceType"} eq "Patient" and $record->{"resource"}{"resourceType"} eq "Patient"
!ll&&!rl&&r
002
MC/DC0%0/5
$previous->{"resourceType"} eq "Patient" and $record->{"resource"}{"resourceType"} eq "Patient" and defined $previous->{"id"} and defined $record->{"resource"}{"id"} and $previous->{"id"} eq $record->{"resource"}{"id"}
$previous->{"resourceType"} eq "Patient" $record->{"resource"}{"resourceType"} eq "Patient" defined $previous->{"id"} defined $record->{"resource"}{"id"} $previous->{"id"} eq $record->{"resource"}{"id"}
Truth table16%1/6
A and B and C and D and E
A= $previous->{"resourceType"} eq "Patient"B= $record->{"resource"}{"resourceType"} eq "Patient"C= defined $previous->{"id"}D= defined $record->{"resource"}{"id"}E= $previous->{"id"} eq $record->{"resource"}{"id"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
139 0 die "FHIR input contains duplicate resource reference <$alias>\n";
140 }
141 538 $index{$alias} = $record->{resource};
142 }
143 }
144  
145 21 my ( %patients, @patient_order, %patient_alias, %patient_refaddr );
146 21 for my $record (@records) {
147 271 my $patient = $record->{resource};
148 271 ▶ next unless $patient->{resourceType} eq 'Patient';
Branch: 1 branch
BranchTrueFalseTotal
unless $patient->{"resourceType"} eq "Patient" 250 21 271
149  
150 21 my $patient_id = _resource_identifier($patient);
151 21 ▶ die "FHIR Patient in <$record->{label}> has neither id nor identifier.value\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $patient_id and length $patient_id 0 21 21
Condition33%1/3
defined $patient_id and length $patient_id
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $patient_id and length $patient_id
defined $patient_id length $patient_id
Truth table33%1/3
A and B
A= defined $patient_idB= length $patient_id
ABresult
0X0
100
111
152 unless defined $patient_id && length $patient_id;
153 21 ▶ if ( exists $patients{$patient_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $patients{$patient_id}) 1 20 21
154 1 $patient_refaddr{ refaddr($patient) } = $patient_id;
155 1 for my $alias (
156 1 @{ reference_aliases( $patient, $record->{fullUrl} ) }
157 )
158 {
159 2 $patient_alias{$alias} = $patient_id;
160 }
161 1 next;
162 }
163  
164 20 $patients{$patient_id} = {
165 id => $patient_id,
166 patient => $patient,
167 resources => [],
168 resourceIndex => \%index,
169 bundleMetadata => \@bundle_metadata,
170 };
171 20 $patient_refaddr{ refaddr($patient) } = $patient_id;
172 20 for my $alias (
173 20 @{ reference_aliases( $patient, $record->{fullUrl} ) }
174 )
175 {
176 40 $patient_alias{$alias} = $patient_id;
177 }
178 20 push @patient_order, $patient_id;
179 }
180  
181 21 ▶ die "FHIR Bundle input must contain at least one Patient resource\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @patient_order 1 20 21
182 unless @patient_order;
183  
184 20 my @unassigned;
185 20 for my $record (@records) {
186 260 my $resource = $record->{resource};
187 260 ▶ next if $resource->{resourceType} eq 'Patient';
Branch: 1 branch
BranchTrueFalseTotal
if $resource->{"resourceType"} eq "Patient" 21 239 260
188  
189 239 my $patient_id = _resource_patient_id(
190 $resource,
191 \%index,
192 \%patient_alias,
193 \%patient_refaddr,
194 );
195  
196 239 ▶ if ( defined $patient_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $patient_id) { } 200 39 239
197 200 push @{ $patients{$patient_id}{resources} }, $resource;
198 }
199 else {
200 39 push @unassigned, $resource;
201 }
202 }
203  
204 return {
205 20 patients => [ map { $patients{$_} } @patient_order ],
206 records => \@records,
207 resource_index => \%index,
208 bundle_metadata => \@bundle_metadata,
209 unassigned_resources => \@unassigned,
210 };
211 }
212  
213 239 ▶sub _resource_patient_id {
Subroutine _resource_patient_id: called CC=7 SCAR=26.4
214 239 my ( $resource, $index, $patient_alias, $patient_refaddr ) = @_;
215  
216 239 for my $reference ( _patient_references($resource) ) {
217 return $patient_alias->{$reference}
218 200 ▶ if exists $patient_alias->{$reference};
Branch: 1 branch
BranchTrueFalseTotal
if exists $patient_alias->{$reference} 181 19 200
219  
220 19 my $canonical = canonical_reference($reference);
221 return $patient_alias->{$canonical}
222 19 ▶ if defined $canonical && exists $patient_alias->{$canonical};
Branch: 1 branch
BranchTrueFalseTotal
if defined $canonical and exists $patient_alias->{$canonical} 19 0 19
Condition33%1/3
defined $canonical and exists $patient_alias->{$canonical}
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $canonical and exists $patient_alias->{$canonical}
defined $canonical exists $patient_alias->{$canonical}
Truth table33%1/3
A and B
A= defined $canonicalB= exists $patient_alias->{$canonical}
ABresult
0X0
100
111
223  
224 0 my $resolved = resolve_reference( $index, $reference );
225 0 ▶ next unless defined $resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $resolved 0 0 0
226 0 my $address = refaddr($resolved);
227 return $patient_refaddr->{$address}
228 0 ▶ if exists $patient_refaddr->{$address};
Branch: 1 branch
BranchTrueFalseTotal
if exists $patient_refaddr->{$address} 0 0 0
229 }
230  
231 39 return;
232 }
233  
234 239 ▶sub _patient_references {
Subroutine _patient_references: called CC=11 SCAR=27.4
235 239 my ($resource) = @_;
236 239 my @references;
237  
238 239 for my $field (qw(subject patient beneficiary)) {
239 717 ▶ next unless ref( $resource->{$field} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $resource->{$field} eq "HASH" 535 182 717
240 182 my $reference = $resource->{$field}{reference};
241 182 ▶ push @references, $reference
Branch: 1 branch
BranchTrueFalseTotal
if defined $reference and not ref $reference and length $reference 182 0 182
Condition33%2/6
defined $reference and not ref $reference and length $reference
!ll&&!rl&&r
00182
defined $reference and not ref $reference
!ll&&!rl&&r
00182
MC/DC0%0/3
defined $reference and not ref $reference and length $reference
defined $reference not ref $reference length $reference
Truth table25%1/4
A and not(B) and C
A= defined $referenceB= not ref $referenceC= length $reference
ABCresult
0XX0
10X0
1100
1111
242 if defined $reference && !ref($reference) && length $reference;
243 }
244  
245 239 ▶ if ( $resource->{resourceType} eq 'ResearchSubject'
Branch: 1 branch
BranchTrueFalseTotal
if ($resource->{"resourceType"} eq "ResearchSubject" and ref $resource->{"individual"} eq "HASH") 18 221 239
Condition66%2/3
$resource->{"resourceType"} eq "ResearchSubject" and ref $resource->{"individual"} eq "HASH"
!ll&&!rl&&r
221018
MC/DC50%1/2
$resource->{"resourceType"} eq "ResearchSubject" and ref $resource->{"individual"} eq "HASH"
$resource->{"resourceType"} eq "ResearchSubject" ref $resource->{"individual"} eq "HASH"
Truth table66%2/3
A and B
A= $resource->{"resourceType"} eq "ResearchSubject"B= ref $resource->{"individual"} eq "HASH"
ABresult
0X0
100
111
246 && ref( $resource->{individual} ) eq 'HASH' )
247 {
248 18 my $reference = $resource->{individual}{reference};
249 18 ▶ push @references, $reference
Branch: 1 branch
BranchTrueFalseTotal
if defined $reference and not ref $reference and length $reference 18 0 18
Condition33%2/6
defined $reference and not ref $reference and length $reference
!ll&&!rl&&r
0018
defined $reference and not ref $reference
!ll&&!rl&&r
0018
MC/DC0%0/3
defined $reference and not ref $reference and length $reference
defined $reference not ref $reference length $reference
Truth table25%1/4
A and not(B) and C
A= defined $referenceB= not ref $referenceC= length $reference
ABCresult
0XX0
10X0
1100
1111
250 if defined $reference && !ref($reference) && length $reference;
251 }
252  
253 239 return @references;
254 }
255  
256 57 ▶sub _resource_identifier {
Subroutine _resource_identifier: called CC=10 SCAR=41.6
257 57 my ($resource) = @_;
258 return $resource->{id}
259 57 ▶ if defined $resource->{id} && !ref( $resource->{id} ) && length $resource->{id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $resource->{"id"} and not ref $resource->{"id"} and length $resource->{"id"} 57 0 57
Condition33%2/6
defined $resource->{"id"} and not ref $resource->{"id"} and length $resource->{"id"}
!ll&&!rl&&r
0057
defined $resource->{"id"} and not ref $resource->{"id"}
!ll&&!rl&&r
0057
MC/DC0%0/3
defined $resource->{"id"} and not ref $resource->{"id"} and length $resource->{"id"}
defined $resource->{"id"} not ref $resource->{"id"} length $resource->{"id"}
Truth table25%1/4
A and not(B) and C
A= defined $resource->{"id"}B= not ref $resource->{"id"}C= length $resource->{"id"}
ABCresult
0XX0
10X0
1100
1111
260  
261 0 ▶ for my $identifier ( @{ $resource->{identifier} || [] } ) {
Condition0%0/2
$resource->{'identifier'} || []
l!l
00
MC/DC0%0/1
$resource->{'identifier'} || []
$resource->{'identifier'}
Truth table0%0/2
A
A= $resource->{'identifier'}
Aresult
11
00
262 0 ▶ next unless ref($identifier) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $identifier eq "HASH" 0 0 0
263 return $identifier->{value}
264 if defined $identifier->{value}
265 && !ref( $identifier->{value} )
266 0 ▶ && length $identifier->{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $identifier->{"value"} and not ref $identifier->{"value"} and length $identifier->{"value"} 0 0 0
Condition0%0/6
defined $identifier->{"value"} and not ref $identifier->{"value"} and length $identifier->{"value"}
!ll&&!rl&&r
000
defined $identifier->{"value"} and not ref $identifier->{"value"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $identifier->{"value"} and not ref $identifier->{"value"} and length $identifier->{"value"}
defined $identifier->{"value"} not ref $identifier->{"value"} length $identifier->{"value"}
Truth table0%0/4
A and not(B) and C
A= defined $identifier->{"value"}B= not ref $identifier->{"value"}C= length $identifier->{"value"}
ABCresult
0XX0
10X0
1100
1111
267 }
268  
269 0 return;
270 }
271  
272 22 ▶sub _bundle_metadata {
Subroutine _bundle_metadata: called CC=4 SCAR=13.9
273 22 my ( $bundle, $label ) = @_;
274 my $metadata = {
275 source => $label,
276 type => $bundle->{type},
277 22 };
278  
279 22 for my $field (qw(id identifier meta timestamp total)) {
280 110 ▶ next unless exists $bundle->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $bundle->{$field} 70 40 110
281 $metadata->{$field} = ref( $bundle->{$field} )
282 ? dclone( $bundle->{$field} )
283 40 ▶ : $bundle->{$field};
Branch: 1 branch
BranchTrueFalseTotal
ref $bundle->{$field} ? : 1 39 40
284 }
285  
286 22 return $metadata;
287 }
288  
289 20 ▶sub _derived_entity_overrides {
Subroutine _derived_entity_overrides: called CC=20 SCAR=33.3
290 20 my ( $converter, $normalized ) = @_;
291 18 my ($study) = map { $_->{resource} }
292 260 grep { $_->{resource}{resourceType} eq 'ResearchStudy' }
293 20 @{ $normalized->{records} };
294 18 my ($group) = map { $_->{resource} }
295 260 grep { $_->{resource}{resourceType} eq 'Group' }
296 20 @{ $normalized->{records} };
297  
298 20 my $overrides = {};
299 20 ▶ if ($study) {
Branch: 2 branches
BranchTrueFalseTotal
if ($study) { } 18 2 20
elsif (@{$normalized->{'bundle_metadata'};}) { } 2 0 2
300 18 ▶ my $id = _resource_identifier($study) // 'fhir-study-1';
Condition50%1/2
_resource_identifier($study) // "fhir-study-1"
l!l
180
MC/DC0%0/1
_resource_identifier($study) // "fhir-study-1"
_resource_identifier($study)
Truth table50%1/2
A
A= _resource_identifier($study)
Aresult
11
00
301 $overrides->{datasets} = {
302 id => $id,
303 18 ▶ name => $study->{title} // $study->{name} // $id,
Condition33%2/6
($study->{"title"} // $study->{"name"}) // $id
l!l&&r!l&&!r
1800
$study->{"title"} // $study->{"name"}
l!l&&r!l&&!r
1800
MC/DC0%0/3
($study->{"title"} // $study->{"name"}) // $id
$study->{"title"} $study->{"name"} $id
Truth table25%1/4
A // B // C
A= $study->{"title"}B= $study->{"name"}C= $id
ABCresult
1XX1
01X1
0011
0000
304 };
305 $overrides->{datasets}{description} = $study->{description}
306 18 ▶ if defined $study->{description} && !ref( $study->{description} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $study->{"description"} and not ref $study->{"description"} 18 0 18
Condition33%1/3
defined $study->{"description"} and not ref $study->{"description"}
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $study->{"description"} and not ref $study->{"description"}
defined $study->{"description"} not ref $study->{"description"}
Truth table33%1/3
A and not(B)
A= defined $study->{"description"}B= not ref $study->{"description"}
ABresult
0X0
100
111
307 }
308 2 elsif ( @{ $normalized->{bundle_metadata} } ) {
309 2 my $metadata = $normalized->{bundle_metadata}[0];
310 2 ▶ my $id = $metadata->{id} // 'fhir-bundle-1';
Condition100%2/2
$metadata->{"id"} // "fhir-bundle-1"
l!l
11
MC/DC100%1/1
$metadata->{"id"} // "fhir-bundle-1"
$metadata->{"id"}
Truth table100%2/2
A
A= $metadata->{"id"}
Aresult
11
00
311 $overrides->{datasets} = {
312 2 id => $id,
313 name => "FHIR Bundle $id",
314 description => 'Dataset synthesized from FHIR R4 Bundle input.',
315 };
316 }
317  
318 20 ▶ if ($group) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group) 18 2 20
319 18 ▶ my $id = _resource_identifier($group) // 'fhir-group-1';
Condition50%1/2
_resource_identifier($group) // "fhir-group-1"
l!l
180
MC/DC0%0/1
_resource_identifier($group) // "fhir-group-1"
_resource_identifier($group)
Truth table50%1/2
A
A= _resource_identifier($group)
Aresult
11
00
320 18 my $size = $group->{quantity};
321 0 ▶ $size = scalar @{ $group->{member} || [] }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size and not ref $size 0 18 18
Condition20%1/5
defined $size and not ref $size
!ll&&!rl&&r
0018
$group->{'member'} || []
l!l
00
MC/DC0%0/2
defined $size and not ref $size
defined $size not ref $size
MC/DC0%0/1
$group->{'member'} || []
$group->{'member'}
Truth table33%1/3
A and not(B)
A= defined $sizeB= not ref $size
ABresult
0X0
100
111
Truth table0%0/2
A
A= $group->{'member'}
Aresult
11
00
322 unless defined $size && !ref($size);
323  
324 $overrides->{cohorts} = {
325 id => $id,
326 18 ▶ name => $group->{name} // $id,
Condition33%1/3
$group->{"name"} // $id
l!l&&r!l&&!r
1800
MC/DC0%0/2
$group->{"name"} // $id
$group->{"name"} $id
Truth table33%1/3
A // B
A= $group->{"name"}B= $id
ABresult
1X1
011
000
327 cohortType => 'study-defined',
328 cohortSize => 0 + $size,
329 };
330 }
331  
332 20 ▶ if ( ( $converter->{source_info} // 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($converter->{"source_info"} // 1 and exists $overrides->{"datasets"}) 19 1 20
Condition60%3/5
$converter->{"source_info"} // 1 and exists $overrides->{"datasets"}
!ll&&!rl&&r
1019
$converter->{"source_info"} // 1
l!l
200
MC/DC0%0/2
$converter->{"source_info"} // 1 and exists $overrides->{"datasets"}
$converter->{"source_info"} exists $overrides->{"datasets"}
Truth table33%1/3
A and B
A= $converter->{"source_info"}B= exists $overrides->{"datasets"}
ABresult
0X0
100
111
333 && exists $overrides->{datasets} )
334 {
335 $overrides->{datasets}{info}{fhir} = {
336 version => 'R4',
337 19 bundles => dclone( $normalized->{bundle_metadata} ),
338 };
339 19 ▶ $overrides->{datasets}{info}{fhir}{researchStudy} = dclone($study)
Branch: 1 branch
BranchTrueFalseTotal
if $study 17 2 19
340 if $study;
341 $overrides->{datasets}{info}{fhir}{unassignedResources} =
342 dclone( $normalized->{unassigned_resources} )
343 19 ▶ if @{ $normalized->{unassigned_resources} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$normalized->{"unassigned_resources"};} 18 1 19
344 }
345  
346 20 return $overrides;
347 }
348  
349 18 ▶sub prepare {
Subroutine prepare: called CC=9 SCAR=22.3
Pod undocumented
350 18 my ($self) = @_;
351 18 my $converter = $self->{converter};
352 return 1 if $converter->{fhir_input_prepared}
353 18 ▶ && exists $converter->{data};
Branch: 1 branch
BranchTrueFalseTotal
if $converter->{"fhir_input_prepared"} and exists $converter->{"data"} 0 18 18
Condition66%2/3
$converter->{"fhir_input_prepared"} and exists $converter->{"data"}
!ll&&!rl&&r
1710
MC/DC0%0/2
$converter->{"fhir_input_prepared"} and exists $converter->{"data"}
$converter->{"fhir_input_prepared"} exists $converter->{"data"}
Truth table66%2/3
A and B
A= $converter->{"fhir_input_prepared"}B= exists $converter->{"data"}
ABresult
0X0
100
111
354  
355 $converter->{_fhir_source_data} = $converter->{data}
356 if exists $converter->{data}
357 18 ▶ && !exists $converter->{_fhir_source_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $converter->{"data"} and not exists $converter->{"_fhir_source_data"} 7 11 18
Condition66%2/3
exists $converter->{"data"} and not exists $converter->{"_fhir_source_data"}
!ll&&!rl&&r
1107
MC/DC50%1/2
exists $converter->{"data"} and not exists $converter->{"_fhir_source_data"}
exists $converter->{"data"} not exists $converter->{"_fhir_source_data"}
Truth table66%2/3
A and not(B)
A= exists $converter->{"data"}B= not exists $converter->{"_fhir_source_data"}
ABresult
0X0
100
111
358 $converter->{data} = $converter->{_fhir_source_data}
359 if !exists $converter->{data}
360 18 ▶ && exists $converter->{_fhir_source_data};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $converter->{"data"} and exists $converter->{"_fhir_source_data"} 1 17 18
Condition100%3/3
not exists $converter->{"data"} and exists $converter->{"_fhir_source_data"}
!ll&&!rl&&r
7101
MC/DC100%2/2
not exists $converter->{"data"} and exists $converter->{"_fhir_source_data"}
not exists $converter->{"data"} exists $converter->{"_fhir_source_data"}
Truth table100%3/3
not(A) and B
A= not exists $converter->{"data"}B= exists $converter->{"_fhir_source_data"}
ABresult
0X0
100
111
361  
362 18 my $source = $self->load;
363 18 $source->apply_to($converter);
364 $converter->{fhir_bundle_metadata} =
365 18 $source->artifact('bundle_metadata');
366 $converter->{fhir_unassigned_resources} =
367 18 $source->artifact('unassigned_resources');
368 $converter->{source_derived_entity_overrides} =
369 18 ▶ $source->artifact('derived_entity_overrides') || {};
Condition50%1/2
$source->artifact('derived_entity_overrides') || {}
l!l
180
MC/DC0%0/1
$source->artifact('derived_entity_overrides') || {}
$source->artifact('derived_entity_overrides')
Truth table50%1/2
A
A= $source->artifact('derived_entity_overrides')
Aresult
11
00
370 18 ▶ $converter->{convertPheno} ||= get_info($converter);
Condition66%2/3
$converter->{"convertPheno"} ||= get_info($converter)
l!l&&r!l&&!r
1170
MC/DC0%0/2
$converter->{"convertPheno"} ||= get_info($converter)
$converter->{"convertPheno"} get_info($converter)
Truth table66%2/3
A ||= B
A= $converter->{"convertPheno"}B= get_info($converter)
ABresult
1X1
011
000
371 18 $converter->{fhir_input_prepared} = 1;
372 18 return 1;
373 }
374  
375 136 1;
« lib/Convert/Pheno/CDISC/SDTM/Terminology.pm ↑ Summary lib/Convert/Pheno/FHIR/Profile/MCode.pm »