Skip to content

Commit

Permalink
Merge pull request #67 from landswellsong/ukraine_fields_mishap
Browse files Browse the repository at this point in the history
Alertes pour les fautes dans les certificats
  • Loading branch information
lovasoa authored Aug 27, 2021
2 parents a7f755e + fe8190a commit fab38c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/lib/digital_green_certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export class InvalidCertificateError extends Error {
}
}

// Flags indicating known certificate mistakes
export interface DGCMistakes {
name_reversed: boolean;
latin_not_icao: boolean;
dob_not_iso: boolean;
}

// As per https://ec.europa.eu/health/sites/default/files/ehealth/docs/digital-green-certificates_v3_en.pdf
// Section 2.6.3
const CWT_CLAIMS = Object.freeze({
Expand Down Expand Up @@ -259,3 +266,23 @@ export async function parse(code: string): Promise<CommonCertificateInfo> {
const dgc = await parseDGCFromCoseData(rawCoseData);
return getCertificateInfo({ ...dgc, code });
}

/**
* Function to correct known mistakes in the certificates
* Currently used for Ukraine and for name substructure only
* Add more exceptions if they appear
*
* Ukrainian certificates had several mistakes to them:
- issued before 2021-08-26 had a mistake with name and surname fields reversed
- issued before 2021-08-25 had latin name versions not capitalized
- issued before 2021-08-25 had dd.mm.yyyy DOB date format
*/
export function certificateMistakes(dcg: RawDGC): DGCMistakes {
return {
latin_not_icao:
(dcg.hcert.nam.fnt && dcg.hcert.nam.fnt.search(/^[A-Z<]*$/) == -1) ||
(dcg.hcert.nam.gnt && dcg.hcert.nam.gnt.search(/^[A-Z<]*$/) == -1),
dob_not_iso: dcg.hcert.dob.search(/^((19|20)\d\d(-\d\d){0,2}){0,1}$/) == -1,
name_reversed: dcg.issuer == 'UA' && new Date(dcg.issuedAt * 1000) < new Date(2021, 7, 26)
};
}
19 changes: 18 additions & 1 deletion src/routes/_CertificateDGCDetails.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<script type="ts">
import { Table, Card, CardHeader, CardTitle } from 'sveltestrap';
import type { DGC } from '$lib/digital_green_certificate';
import { certificateMistakes } from '$lib/digital_green_certificate';
import { sha256 } from '$lib/sha256';
export let certificate: DGC;
const { hcert } = certificate;
const mistakes = certificateMistakes(certificate);
function showTimestamp(time_seconds: number | string, options: { include_time?: boolean } = {}) {
const source = typeof time_seconds === 'number' ? time_seconds * 1000 : time_seconds;
const date = new Date(source);
Expand Down Expand Up @@ -86,6 +89,7 @@
name: string;
value: Promise<string> | string | number;
link?: string;
mistakes?: string;
}
interface Card {
title: string;
Expand All @@ -97,21 +101,33 @@
lines: [
...lineIf(hcert.nam.fn, (value) => ({
name: 'Nom',
mistakes: mistakes.name_reversed ? 'Nom et prénom intervertis' : undefined,
value
})),
...lineIfDifferent(hcert.nam.fnt, hcert.nam.fn, (value) => ({
name: 'Translittération latine du nom',
mistakes: mistakes.latin_not_icao
? 'Les translittérations ne sont pas au format ICAO 9303'
: undefined,
value
})),
...lineIf(hcert.nam.gn, (value) => ({
name: 'Prénom',
mistakes: mistakes.name_reversed ? 'Nom et prénom intervertis' : undefined,
value
})),
...lineIfDifferent(hcert.nam.gnt, hcert.nam.gn, (value) => ({
name: 'Translittération latine du prénom',
mistakes: mistakes.latin_not_icao
? 'Les translittérations ne sont pas au format ICAO 9303'
: undefined,
value
})),
{ name: 'Date de naissance', value: hcert.dob }
{
name: 'Date de naissance',
mistakes: mistakes.dob_not_iso ? "La date n'est pas au format ISO 8601" : undefined,
value: hcert.dob
}
]
},
...(hcert.v || []).map((vaccine) => ({
Expand Down Expand Up @@ -241,6 +257,7 @@
{#await line.value}
chargement...
{:then value}
{#if line.mistakes}<abbr title={line.mistakes}>⚠️</abbr>{/if}
{value}
{:catch e}
<pre class="bg-warning">{e}</pre>
Expand Down

0 comments on commit fab38c4

Please sign in to comment.