| 1 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | package Health::SHC; | ||||||||||||
| 5 | |||||||||||||
| 6 | # ABSTRACT: Extract and verify Smart Health Card information | ||||||||||||
| 7 | |||||||||||||
| 8 | 2 | our $VERSION = '0.006'; | |||||||||||
| 9 | |||||||||||||
| 10 | =head1 NAME | ||||||||||||
| 11 | |||||||||||||
| 12 | Health::SHC - Verify Smart Health Card Signature and Extract data. | ||||||||||||
| 13 | |||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||
| 15 | |||||||||||||
| 16 | use Health::SHC::Validate; | ||||||||||||
| 17 | my $shc_valid = Health::SHC::Validate->new(); | ||||||||||||
| 18 | |||||||||||||
| 19 | # Use builtin trusted keys | ||||||||||||
| 20 | my $data = $shc_valid->get_valid_data($qr); | ||||||||||||
| 21 | |||||||||||||
| 22 | # Use your own keys to validate - you may trust them | ||||||||||||
| 23 | my $data = $shc_valid->get_valid_data($qr, $keys_json); | ||||||||||||
| 24 | |||||||||||||
| 25 | use Health::SHC; | ||||||||||||
| 26 | my $sh = Health::SHC->new(); | ||||||||||||
| 27 | my @patients = $sh->get_patients($data); | ||||||||||||
| 28 | |||||||||||||
| 29 | foreach (@patients) { | ||||||||||||
| 30 | print "Patient: ", $_->{given}, " ", $_->{middle}, " ", $_->{family}, "\n"; | ||||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | my @immunizations = $sh->get_immunizations($data); | ||||||||||||
| 34 | |||||||||||||
| 35 | print "Vacination Provider", "\t", "Date", "\n"; | ||||||||||||
| 36 | foreach (@immunizations) { | ||||||||||||
| 37 | print $_->{provider}, "\t", $_->{date}, "\n"; | ||||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | my @vaccines = $sh->get_vaccines($data); | ||||||||||||
| 41 | |||||||||||||
| 42 | print "Manufacturer\tLot Number\tCode\tCode System\n"; | ||||||||||||
| 43 | foreach (@vaccines) { | ||||||||||||
| 44 | print $_->{manufacturer}, "\t\t", $_->{lotNumber}, "\t\t"; | ||||||||||||
| 45 | my $codes = $_->{codes}; | ||||||||||||
| 46 | foreach my $tmp (@$codes) { | ||||||||||||
| 47 | print $tmp->{code}, "\t", | ||||||||||||
| 48 | $tmp->{system}, "\t"; | ||||||||||||
| 49 | } | ||||||||||||
| 50 | print "\n"; | ||||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||
| 54 | |||||||||||||
| 55 | =encoding utf-8 | ||||||||||||
| 56 | |||||||||||||
| 57 | This perl module can extract a Smart Health Card's data from PDFs or image file. | ||||||||||||
| 58 | The extracted shc:/ Smart Health Card URI is decoded and the signature checked. | ||||||||||||
| 59 | The module provide several methods to retrieve the data in a more usable format. | ||||||||||||
| 60 | |||||||||||||
| 61 | Health::SHC supports QR codes for the following regions: | ||||||||||||
| 62 | |||||||||||||
| 63 | * Québec | ||||||||||||
| 64 | * British Columbia | ||||||||||||
| 65 | * Saskatchewan | ||||||||||||
| 66 | * Alberta | ||||||||||||
| 67 | * Newfoundland and Labrador | ||||||||||||
| 68 | * Nova Scotia | ||||||||||||
| 69 | * Ontario | ||||||||||||
| 70 | * Northwest Territories | ||||||||||||
| 71 | * Yukon | ||||||||||||
| 72 | * New Brunswick/Nouveau-Brunswick | ||||||||||||
| 73 | * Japan | ||||||||||||
| 74 | |||||||||||||
| 75 | The keys in share/keys.json (and supported regions) are based on the keys | ||||||||||||
| 76 | included with https://github.com/obrassard/shc-extractor. | ||||||||||||
| 77 | |||||||||||||
| 78 | Additional regions can be added with a pull request or by logging an issue | ||||||||||||
| 79 | at https://github.com/timlegge/perl-Health-SHC/issues. | ||||||||||||
| 80 | |||||||||||||
| 81 | =cut | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 COPYRIGHT | ||||||||||||
| 84 | |||||||||||||
| 85 | The following copyright notice applies to all the files provided in | ||||||||||||
| 86 | this distribution, including binary files, unless explicitly noted | ||||||||||||
| 87 | otherwise. | ||||||||||||
| 88 | |||||||||||||
| 89 | Copyright 2021 - 2024 Timothy Legge <timlegge@gmail.com> | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 LICENCE | ||||||||||||
| 92 | |||||||||||||
| 93 | This library is free software; you can redistribute it and/or modify | ||||||||||||
| 94 | it under the same terms as Perl itself. | ||||||||||||
| 95 | |||||||||||||
| 96 | =cut | ||||||||||||
| 97 | |||||||||||||
| 98 | =head2 METHODS | ||||||||||||
| 99 | |||||||||||||
| 100 | =head3 B<new(...)> | ||||||||||||
| 101 | |||||||||||||
| 102 | Constructor; see OPTIONS above. | ||||||||||||
| 103 | |||||||||||||
| 104 | =cut | ||||||||||||
| 105 | |||||||||||||
| 106 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 107 | 0 | my $class = shift; | |||||||||||
| 108 | |||||||||||||
| 109 | 0 | my $self = {}; | |||||||||||
| 110 | 0 | bless $self, $class; | |||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | =head3 B<get_patients($data)> | ||||||||||||
| 114 | |||||||||||||
| 115 | Arguments: | ||||||||||||
| 116 | $data: string Smart Health Card data without the "shc:/" prefix | ||||||||||||
| 117 | |||||||||||||
| 118 | Returns: hash containing the Patient information | ||||||||||||
| 119 | |||||||||||||
| 120 | =cut | ||||||||||||
| 121 | |||||||||||||
| 122 | 0 | ▶ | sub get_patients { | ||||||||||
|
Subroutine
get_patients: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||
| 124 | 0 | my $data = shift; | |||||||||||
| 125 | |||||||||||||
| 126 | 0 | my $entrys = $data->{vc}{credentialSubject}{fhirBundle}{entry}; | |||||||||||
| 127 | 0 | my %lookup = map { $_->{fullUrl} => $_ } @$entrys; | |||||||||||
| 128 | |||||||||||||
| 129 | 0 | my (@p) = grep { 'Patient' eq $lookup{$_}->{resource}{resourceType} } keys %lookup; | |||||||||||
| 130 | |||||||||||||
| 131 | 0 | my @patients; | |||||||||||
| 132 | 0 | foreach (@p) { | |||||||||||
| 133 | 0 | my %patient; | |||||||||||
| 134 | 0 | ▶ | $patient{family} = $lookup{$_}->{resource}{name}[0]{family} || ""; | ||||||||||
|
Condition0%0/2
$lookup{$_}{'resource'}{'name'}[0]{'family'} || ''
MC/DC0%0/1
$lookup{$_}{'resource'}{'name'}[0]{'family'} || ''
$lookup{$_}{'resource'}{'name'}[0]{'family'}
Truth table0%0/2
A
A= $lookup{$_}{'resource'}{'name'}[0]{'family'}
| |||||||||||||
| 135 | 0 | ▶ | $patient{given} = $lookup{$_}->{resource}{name}[0]{given}[0] || ""; | ||||||||||
|
Condition0%0/2
$lookup{$_}{'resource'}{'name'}[0]{'given'}[0] || ''
MC/DC0%0/1
$lookup{$_}{'resource'}{'name'}[0]{'given'}[0] || ''
$lookup{$_}{'resource'}{'name'}[0]{'given'}[0]
Truth table0%0/2
A
A= $lookup{$_}{'resource'}{'name'}[0]{'given'}[0]
| |||||||||||||
| 136 | 0 | ▶ | $patient{middle} = $lookup{$_}->{resource}{name}[0]{given}[1] || ""; | ||||||||||
|
Condition0%0/2
$lookup{$_}{'resource'}{'name'}[0]{'given'}[1] || ''
MC/DC0%0/1
$lookup{$_}{'resource'}{'name'}[0]{'given'}[1] || ''
$lookup{$_}{'resource'}{'name'}[0]{'given'}[1]
Truth table0%0/2
A
A= $lookup{$_}{'resource'}{'name'}[0]{'given'}[1]
| |||||||||||||
| 137 | 0 | push (@patients, {%patient}); | |||||||||||
| 138 | } | ||||||||||||
| 139 | 0 | return @patients; | |||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | =head3 B<get_immunizations($data)> | ||||||||||||
| 143 | |||||||||||||
| 144 | Arguments: | ||||||||||||
| 145 | $data: string Smart Health Card data without the "shc:/" prefix | ||||||||||||
| 146 | |||||||||||||
| 147 | Returns: hash containing the Immunization data | ||||||||||||
| 148 | |||||||||||||
| 149 | =cut | ||||||||||||
| 150 | |||||||||||||
| 151 | 0 | ▶ | sub get_immunizations { | ||||||||||
|
Subroutine
get_immunizations: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 152 | 0 | my $self = shift; | |||||||||||
| 153 | 0 | my $data = shift; | |||||||||||
| 154 | |||||||||||||
| 155 | 0 | my $entrys = $data->{vc}{credentialSubject}{fhirBundle}{entry}; | |||||||||||
| 156 | 0 | my %lookup = map { $_->{fullUrl} => $_ } @$entrys; | |||||||||||
| 157 | |||||||||||||
| 158 | 0 | my (@i) = grep { 'Immunization' eq $lookup{$_}->{resource}{resourceType} } keys %lookup; | |||||||||||
| 159 | |||||||||||||
| 160 | 0 | my @immunizations; | |||||||||||
| 161 | 0 | foreach (@i) { | |||||||||||
| 162 | 0 | my %immunization; | |||||||||||
| 163 | 0 | ▶ | $immunization{provider} = $lookup{$_}->{resource}{performer}[0]{actor}{display} || ""; | ||||||||||
|
Condition0%0/2
$lookup{$_}{'resource'}{'performer'}[0]{'actor'}{'display'} || ''
MC/DC0%0/1
$lookup{$_}{'resource'}{'performer'}[0]{'actor'}{'display'} || ''
$lookup{$_}{'resource'}{'performer'}[0]{'actor'}{'display'}
Truth table0%0/2
A
A= $lookup{$_}{'resource'}{'performer'}[0]{'actor'}{'display'}
| |||||||||||||
| 164 | 0 | ▶ | $immunization{date} = $lookup{$_}->{resource}{occurrenceDateTime} || ""; | ||||||||||
|
Condition0%0/2
$lookup{$_}{'resource'}{'occurrenceDateTime'} || ''
MC/DC0%0/1
$lookup{$_}{'resource'}{'occurrenceDateTime'} || ''
$lookup{$_}{'resource'}{'occurrenceDateTime'}
Truth table0%0/2
A
A= $lookup{$_}{'resource'}{'occurrenceDateTime'}
| |||||||||||||
| 165 | 0 | push (@immunizations, {%immunization}); | |||||||||||
| 166 | } | ||||||||||||
| 167 | 0 | return @immunizations; | |||||||||||
| 168 | } | ||||||||||||
| 169 | |||||||||||||
| 170 | =head3 B<get_vaccines($data)> | ||||||||||||
| 171 | |||||||||||||
| 172 | Arguments: | ||||||||||||
| 173 | $data: string Smart Health Card data without the "shc:/" prefix | ||||||||||||
| 174 | |||||||||||||
| 175 | Returns: hash containing the Vaccine data | ||||||||||||
| 176 | |||||||||||||
| 177 | =cut | ||||||||||||
| 178 | |||||||||||||
| 179 | 0 | ▶ | sub get_vaccines { | ||||||||||
|
Subroutine
get_vaccines: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 180 | 0 | my $self = shift; | |||||||||||
| 181 | 0 | my $data = shift; | |||||||||||
| 182 | |||||||||||||
| 183 | 0 | my $entrys = $data->{vc}{credentialSubject}{fhirBundle}{entry}; | |||||||||||
| 184 | 0 | my %lookup = map { $_->{fullUrl} => $_ } @$entrys; | |||||||||||
| 185 | |||||||||||||
| 186 | 0 | my (@i) = grep { $lookup{$_}->{resource}{lotNumber} } keys %lookup; | |||||||||||
| 187 | |||||||||||||
| 188 | 0 | my @vaccines; | |||||||||||
| 189 | 0 | foreach (@i) { | |||||||||||
| 190 | 0 | my $resource = $lookup{$_}->{resource}; | |||||||||||
| 191 | 0 | my %vaccine; | |||||||||||
| 192 | 0 | ▶ | $vaccine{lotNumber} = $resource->{lotNumber} || ""; | ||||||||||
|
Condition0%0/2
$resource->{'lotNumber'} || ''
MC/DC0%0/1
$resource->{'lotNumber'} || ''
$resource->{'lotNumber'}
Truth table0%0/2
A
A= $resource->{'lotNumber'}
| |||||||||||||
| 193 | 0 | ▶ | $vaccine{manufacturer} = $resource->{manufacturer}{identifier}{value} || ""; | ||||||||||
|
Condition0%0/2
$resource->{'manufacturer'}{'identifier'}{'value'} || ''
MC/DC0%0/1
$resource->{'manufacturer'}{'identifier'}{'value'} || ''
$resource->{'manufacturer'}{'identifier'}{'value'}
Truth table0%0/2
A
A= $resource->{'manufacturer'}{'identifier'}{'value'}
| |||||||||||||
| 194 | 0 | my $codes = $resource->{vaccineCode}{coding}; | |||||||||||
| 195 | 0 | my @retcodes; | |||||||||||
| 196 | 0 | foreach my $code (@$codes) { | |||||||||||
| 197 | my %tmp = ( | ||||||||||||
| 198 | code => $code->{code}, | ||||||||||||
| 199 | system => $code->{system}, | ||||||||||||
| 200 | 0 | ); | |||||||||||
| 201 | 0 | push (@retcodes, {%tmp}); | |||||||||||
| 202 | } | ||||||||||||
| 203 | 0 | $vaccine{codes} = [@retcodes]; | |||||||||||
| 204 | 0 | push (@vaccines, {%vaccine}); | |||||||||||
| 205 | } | ||||||||||||
| 206 | 0 | return @vaccines; | |||||||||||
| 207 | } | ||||||||||||
| 208 | |||||||||||||
| 209 | 2 | 1; | |||||||||||