pre-merge with main updates

This commit is contained in:
Billy Lo 2021-10-01 03:23:02 -04:00
parent d2c824f129
commit 32ea1edbae
5 changed files with 96 additions and 65 deletions

View File

@ -255,9 +255,18 @@ function Form(): JSX.Element {
try { try {
if (payloadBody) { if (payloadBody) {
const passName = payloadBody.receipts[selectedDose].name.replace(' ', '-');
const vaxName = payloadBody.receipts[selectedDose].vaccineName.replace(' ', '-'); let selectedReceipt;
const passDose = payloadBody.receipts[selectedDose].numDoses; if (payloadBody.rawData.length > 0) { // shc stuff
const sortedKeys = Object.keys(payloadBody.receipts).sort(); // pickup the last key in the receipt table
const lastKey = sortedKeys[sortedKeys.length - 1];
selectedReceipt = payloadBody.receipts[lastKey];
} else {
selectedReceipt = payloadBody.receipts[selectedDose];
}
const passName = selectedReceipt.name.replace(' ', '-');
const vaxName = selectedReceipt.vaccineName.replace(' ', '-');
const passDose = selectedReceipt.numDoses;
const covidPassFilename = `grassroots-receipt-${passName}-${vaxName}-${passDose}.pkpass`; const covidPassFilename = `grassroots-receipt-${passName}-${vaxName}-${passDose}.pkpass`;
//console.log('> increment count'); //console.log('> increment count');
@ -310,13 +319,24 @@ function Form(): JSX.Element {
} }
try { try {
const passName = payloadBody.receipts[selectedDose].name.replace(' ', '-');
const vaxName = payloadBody.receipts[selectedDose].vaccineName.replace(' ', '-'); let selectedReceipt;
const passDose = payloadBody.receipts[selectedDose].numDoses; if (payloadBody.rawData.length > 0) { // shc stuff
const sortedKeys = Object.keys(payloadBody.receipts).sort(); // pickup the last key in the receipt table
const lastKey = sortedKeys[sortedKeys.length - 1];
selectedReceipt = payloadBody.receipts[lastKey];
setSelectedDose(Number(lastKey));
} else {
selectedReceipt = payloadBody.receipts[selectedDose];
}
const passName = selectedReceipt.name.replace(' ', '-');
const vaxName = selectedReceipt.vaccineName.replace(' ', '-');
const passDose = selectedReceipt.numDoses;
const covidPassFilename = `grassroots-receipt-${passName}-${vaxName}-${passDose}.png`; const covidPassFilename = `grassroots-receipt-${passName}-${vaxName}-${passDose}.png`;
await incrementCount(); await incrementCount();
let photoBlob = await Photo.generatePass(payloadBody, selectedDose);
let photoBlob = await Photo.generatePass(payloadBody, passDose);
saveAs(photoBlob, covidPassFilename); saveAs(photoBlob, covidPassFilename);
// need to clean up // need to clean up

View File

@ -20,10 +20,17 @@ export function getQRFromImage(imageData) {
export function decodedStringToReceipt(decoded: object) : HashTable<Receipt> { export function decodedStringToReceipt(decoded: object) : HashTable<Receipt> {
const codeToVaccineName = { const codeToVaccineName = {
'28581000087106': 'Pfizer-BioNTech', '28581000087106': 'PFIZER',
'28951000087107': 'Johnson & Johnson / Janssen', '28951000087107': 'JANSSEN',
'28761000087108': 'AstraZeneca', '28761000087108': 'ASTRAZENECA',
'28571000087109': 'Moderna' '28571000087109': 'MODERNA'
}
const cvxCodeToVaccineName = { // https://www2a.cdc.gov/vaccines/iis/iisstandards/vaccines.asp?rpt=cvx
'208': 'PFIZER',
'212': 'JANSSEN',
'210': 'ASTRAZENECA',
'207': 'MODERNA'
} }
console.log(decoded); console.log(decoded);
@ -35,7 +42,7 @@ export function decodedStringToReceipt(decoded: object) : HashTable<Receipt> {
if (decoded['iss'].includes('ontariohealth.ca')) { if (decoded['iss'].includes('ontariohealth.ca')) {
issuer = 'on'; issuer = 'on';
} }
if (decoded['iss'].includes('bchealth.ca')) { if (decoded['iss'] == "https://smarthealthcard.phsa.ca/v1/issuer") {
issuer = 'bc'; issuer = 'bc';
} }
@ -62,12 +69,15 @@ export function decodedStringToReceipt(decoded: object) : HashTable<Receipt> {
let vaccineName : string; let vaccineName : string;
let organizationName : string; let organizationName : string;
let vaccinationDate : string; let vaccinationDate : string;
for (const vaccineCodes of resource.vaccineCode.coding) { for (const vaccineCodes of resource.vaccineCode.coding) {
if (vaccineCodes.system.includes("snomed.info")) { if (vaccineCodes.system.includes("snomed.info")) { //bc
vaccineName = codeToVaccineName[vaccineCodes.code]; vaccineName = codeToVaccineName[vaccineCodes.code];
if (vaccineName == undefined) if (vaccineName == undefined)
vaccineName = 'Unknown - ' + vaccineCodes.code; vaccineName = 'Unknown - ' + vaccineCodes.code;
} else if (vaccineCodes.system == "http://hl7.org/fhir/sid/cvx") { //qc
vaccineName = cvxCodeToVaccineName[vaccineCodes.code];
if (vaccineName == undefined)
vaccineName = 'Unknown - ' + vaccineCodes.code;
} }
} }

View File

@ -72,8 +72,8 @@ export class PassData {
const results = await PassPhotoCommon.preparePayload(payloadBody, numDose); const results = await PassPhotoCommon.preparePayload(payloadBody, numDose);
const payload = results.payload; const payload = results.payload;
// Create pass data // Create pass data
const pass: PassData = new PassData(results.payload, results.qrCode); const pass: PassData = new PassData(results.payload, results.qrCode);
// Create new zip // Create new zip

View File

@ -36,6 +36,13 @@ export class PassPhotoCommon {
const payload: Payload = new Payload(payloadBody, numDose); const payload: Payload = new Payload(payloadBody, numDose);
payload.serialNumber = uuid4(); payload.serialNumber = uuid4();
let qrCodeMessage;
if (payloadBody.rawData.startsWith('shc:/')) {
qrCodeMessage = payloadBody.rawData;
} else {
// register record // register record
@ -80,12 +87,9 @@ export class PassPhotoCommon {
const encodedUri = `serialNumber=${encodeURIComponent(payload.serialNumber)}&vaccineName=${encodeURIComponent(payloadBody.receipts[numDose].vaccineName)}&vaccinationDate=${encodeURIComponent(payloadBody.receipts[numDose].vaccinationDate)}&organization=${encodeURIComponent(payloadBody.receipts[numDose].organization)}&dose=${encodeURIComponent(payloadBody.receipts[numDose].numDoses)}`; const encodedUri = `serialNumber=${encodeURIComponent(payload.serialNumber)}&vaccineName=${encodeURIComponent(payloadBody.receipts[numDose].vaccineName)}&vaccinationDate=${encodeURIComponent(payloadBody.receipts[numDose].vaccinationDate)}&organization=${encodeURIComponent(payloadBody.receipts[numDose].organization)}&dose=${encodeURIComponent(payloadBody.receipts[numDose].numDoses)}`;
const qrCodeUrl = `${verifierHost}/verify?${encodedUri}`; const qrCodeUrl = `${verifierHost}/verify?${encodedUri}`;
qrCodeMessage = qrCodeUrl;
// console.log(qrCodeUrl); // console.log(qrCodeUrl);
}
let qrCodeMessage = payloadBody.rawData.startsWith('shc:/')
? payloadBody.rawData
: qrCodeUrl;
// Create QR Code Object // Create QR Code Object
const qrCode: QrCode = { const qrCode: QrCode = {

View File

@ -23,16 +23,13 @@ export class Photo {
// Create Payload // Create Payload
try { try {
console.log('generatePass'); console.log('generatePass');
const results = await PassPhotoCommon.preparePayload(payloadBody, numDose); const results = await PassPhotoCommon.preparePayload(payloadBody, numDose);
const payload = results.payload; const payload = results.payload;
const qrCode = results.qrCode; const qrCode = results.qrCode;
let receipt; let receipt;
if (results.payload.rawData.length == 0) { if (results.payload.rawData.length == 0) {
receipt = results.payload.receipts[numDose]; receipt = results.payload.receipts[numDose];
} else { } else {
@ -68,7 +65,7 @@ export class Photo {
} }
const codeWriter = new BrowserQRCodeSvgWriter(); const codeWriter = new BrowserQRCodeSvgWriter();
const hints : Map<EncodeHintType,any> = new Map().set(EncodeHintType.ERROR_CORRECTION,'M'); const hints : Map<EncodeHintType,any> = new Map().set(EncodeHintType.ERROR_CORRECTION,'L');
const svg = codeWriter.write(qrCode.message,200,200, hints); const svg = codeWriter.write(qrCode.message,200,200, hints);
svg.setAttribute('style','background-color: white'); svg.setAttribute('style','background-color: white');
document.getElementById('qrcode').appendChild(svg); document.getElementById('qrcode').appendChild(svg);