| 1 | package Convert::Pheno::FHIR::Profile::MCode; | ||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||
| 8 | 136 | ▶ | use Convert::Pheno::FHIR::Util qw( | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | codeable_concept_to_term | ||||||||||||||||||||||||||||||||
| 10 | resolve_reference | ||||||||||||||||||||||||||||||||
| 11 | 136 | ); | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 136 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||
| 14 | condition_stage | ||||||||||||||||||||||||||||||||
| 15 | detected_profile_metadata | ||||||||||||||||||||||||||||||||
| 16 | has_profile | ||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 136 | my $CANONICAL = 'http://hl7.org/fhir/us/mcode'; | |||||||||||||||||||||||||||||||
| 20 | 136 | my $VERSION = '4.0.0'; | |||||||||||||||||||||||||||||||
| 21 | 136 | my $PROFILE_PREFIX = "$CANONICAL/StructureDefinition/"; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 20 | ▶ | sub has_profile { | ||||||||||||||||||||||||||||||
|
Subroutine
has_profile: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 24 | 20 | my ( $resource, $profile_name ) = @_; | |||||||||||||||||||||||||||||||
| 25 | 20 | ▶ | return 0 unless ref($resource) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 20 | my $wanted = $PROFILE_PREFIX . $profile_name; | |||||||||||||||||||||||||||||||
| 28 | 20 | for my $profile ( @{ _profile_urls($resource) } ) { | |||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | next if ref($profile); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | 3 | my ($canonical) = _supported_profile_identity($profile); | |||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | next unless defined $canonical; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | return 1 if $canonical eq $wanted; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 18 | return 0; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 18 | ▶ | sub condition_stage { | ||||||||||||||||||||||||||||||
|
Subroutine
condition_stage: called CC=14 SCAR=43.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 39 | 18 | my ( $condition, $resource_index ) = @_; | |||||||||||||||||||||||||||||||
| 40 | 18 | ▶ | return unless has_profile( $condition, 'mcode-primary-cancer-condition' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | for my $stage ( @{ $condition->{stage} || [] } ) { | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$condition->{'stage'} || []
MC/DC0%0/1
$condition->{'stage'} || []
$condition->{'stage'}
Truth table50%1/2
A
A= $condition->{'stage'}
| |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | next unless ref($stage) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | my $summary = codeable_concept_to_term( | ||||||||||||||||||||||||||||||||
| 46 | $stage->{summary}, | ||||||||||||||||||||||||||||||||
| 47 | 1 | 'CancerStage', | |||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | return $summary if $summary; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | for my $assessment ( @{ $stage->{assessment} || [] } ) { | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$stage->{'assessment'} || []
MC/DC0%0/1
$stage->{'assessment'} || []
$stage->{'assessment'}
Truth table0%0/2
A
A= $stage->{'assessment'}
| |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | next unless ref($assessment) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | my $observation = resolve_reference( | ||||||||||||||||||||||||||||||||
| 54 | $resource_index || {}, | ||||||||||||||||||||||||||||||||
| 55 | $assessment->{reference}, | ||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$resource_index || {}
MC/DC0%0/1
$resource_index || {}
$resource_index
Truth table0%0/2
A
A= $resource_index
| |||||||||||||||||||||||||||||||||
| 57 | next unless ref($observation) eq 'HASH' | ||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | && ( $observation->{resourceType} || q{} ) eq 'Observation'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
ref $observation eq "HASH" and ($observation->{"resourceType"} || "") eq "Observation"
$observation->{'resourceType'} || ''
MC/DC0%0/2
ref $observation eq "HASH" and ($observation->{"resourceType"} || "") eq "Observation"
ref $observation eq "HASH"
$observation->{'resourceType'}
Truth table0%0/3
A and B
A= ref $observation eq "HASH"B= $observation->{'resourceType'}
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | my $value = codeable_concept_to_term( | ||||||||||||||||||||||||||||||||
| 61 | $observation->{valueCodeableConcept}, | ||||||||||||||||||||||||||||||||
| 62 | 0 | 'CancerStage', | |||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return $value if $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 17 | ▶ | sub detected_profile_metadata { | ||||||||||||||||||||||||||||||
|
Subroutine
detected_profile_metadata: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 72 | 17 | my (@resources) = @_; | |||||||||||||||||||||||||||||||
| 73 | 17 | my %profiles; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 17 | for my $resource (@resources) { | |||||||||||||||||||||||||||||||
| 76 | 214 | ▶ | next unless ref($resource) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 214 | for my $profile ( @{ _profile_urls($resource) } ) { | |||||||||||||||||||||||||||||||
| 78 | 51 | ▶ | next if ref($profile); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 51 | my ($canonical) = _supported_profile_identity($profile); | |||||||||||||||||||||||||||||||
| 80 | 51 | ▶ | next unless defined $canonical; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | 51 | ▶ | next unless index( $canonical, $PROFILE_PREFIX ) == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 25 | my $name = substr $canonical, length $PROFILE_PREFIX; | |||||||||||||||||||||||||||||||
| 84 | 25 | ▶ | next unless length $name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 25 | $profiles{$name} = 1; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 17 | ▶ | return unless keys %profiles; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | return { | ||||||||||||||||||||||||||||||||
| 91 | 1 | canonical => $CANONICAL, | |||||||||||||||||||||||||||||||
| 92 | supportedVersion => $VERSION, | ||||||||||||||||||||||||||||||||
| 93 | detectedProfiles => [ sort keys %profiles ], | ||||||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 54 | ▶ | sub _supported_profile_identity { | ||||||||||||||||||||||||||||||
|
Subroutine
_supported_profile_identity: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||
| 98 | 54 | my ($profile) = @_; | |||||||||||||||||||||||||||||||
| 99 | 54 | ▶ | return if !defined $profile || ref($profile); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $profile or ref $profile
MC/DC0%0/2
not defined $profile or ref $profile
not defined $profile
ref $profile
Truth table33%1/3
not(A) or B
A= not defined $profileB= ref $profile
| |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 54 | my ( $canonical, $version ) = split /\|/, $profile, 2; | |||||||||||||||||||||||||||||||
| 102 | 54 | ▶ | return if defined $version && $version ne $VERSION; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $version and $version ne $VERSION
MC/DC100%2/2
defined $version and $version ne $VERSION
defined $version
$version ne $VERSION
Truth table100%3/3
A and B
A= defined $versionB= $version ne $VERSION
| |||||||||||||||||||||||||||||||||
| 103 | 53 | return $canonical; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 234 | ▶ | sub _profile_urls { | ||||||||||||||||||||||||||||||
|
Subroutine
_profile_urls: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 107 | 234 | my ($resource) = @_; | |||||||||||||||||||||||||||||||
| 108 | 234 | ▶ | return [] unless ref( $resource->{meta} ) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | 54 | ▶ | return [] unless ref( $resource->{meta}{profile} ) eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 54 | return $resource->{meta}{profile}; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 136 | 1; | |||||||||||||||||||||||||||||||