Skip to content

Commit

Permalink
Merge pull request #35 from maslick/transformer-base-class
Browse files Browse the repository at this point in the history
add Transformer base class
  • Loading branch information
maslick authored Jan 12, 2022
2 parents 78255a4 + 28f8c9a commit b4b0155
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/components/scan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import PropTypes from 'prop-types';
import {beep, CODE_TYPE, WORKER_TYPE} from "../helpers";
import {beep, WORKER_TYPE} from "../helpers";
import {CODE_TYPE} from "../transformers/base";
import {Upnqr} from "../transformers/upnqr";
import {Covid19} from "../transformers/covid19";
import "../css/scan.css";
Expand Down
8 changes: 1 addition & 7 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@ const WORKER_TYPE = {
JS: "jsQr"
};

const CODE_TYPE = {
UPNQR: "UPNQR",
COVID19: "COVID",
RAW: "RAW"
};

export {beep, WORKER_TYPE, CODE_TYPE};
export {beep, WORKER_TYPE};
25 changes: 25 additions & 0 deletions src/transformers/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Transformer {
codeType() {
return "TODO";
}

identified(raw) {
return false;
}

transform(raw) {
return "TODO";
}

static buttonCaption() {
return "TODO";
}
}

const CODE_TYPE = {
UPNQR: "UPNQR",
COVID19: "COVID",
RAW: "RAW"
};

export {Transformer, CODE_TYPE};
45 changes: 23 additions & 22 deletions src/transformers/covid19.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {addCachedCerts, unpackAndVerify} from "@pathcheck/dcc-sdk";
import {CODE_TYPE} from "../helpers";
import {cachedCerts} from "./certs";
import {CODE_TYPE, Transformer} from "./base";
import {addCachedCerts, unpackAndVerify} from "@pathcheck/dcc-sdk";

class Covid19 {
class Covid19 extends Transformer {
recognizer = "HC1:";

constructor() {
super();
addCachedCerts(cachedCerts);
}

Expand All @@ -31,8 +32,8 @@ class Covid19 {
const record = cwtPayload.get(-260).get(1);

const dob = record.dob;
const name = record.nam.fnt + "<<" + record.nam.gnt;
const national_name = record.nam.fn + " " + record.nam.gn;
const name = record["nam"]["fnt"] + "<<" + record["nam"]["gnt"];
const national_name = record["nam"]["fn"] + " " + record["nam"]["gn"];

const vaccination = this.extractVaccine(record);
const test = this.extractTest(record);
Expand All @@ -42,25 +43,25 @@ class Covid19 {

extractTest(record) {
if (!record.t) return null;
const unique_cert_id = record.t[0].ci;
const issued_on = record.t[0].sc;
const issuer = record.t[0].is;
const test_type = record.t[0].tt;
const test_result = record.t[0].tr;
const country = record.t[0].co;
const unique_cert_id = record.t[0]["ci"];
const issued_on = record.t[0]["sc"];
const issuer = record.t[0]["is"];
const test_type = record.t[0]["tt"];
const test_result = record.t[0]["tr"];
const country = record.t[0]["co"];

return {unique_cert_id, issued_on, issuer, test_type, test_result, country};
};

extractVaccine(record) {
if (!record.v) return null;
const unique_cert_id = record.v[0].ci;
const issued_on = record.v[0].dt;
const issuer = record.v[0].is;
const vaccine_type = record.v[0].mp;
const doses = record.v[0].dn;
const dose_series = record.v[0].sd;
const country = record.v[0].co;
if (!record["v"]) return null;
const unique_cert_id = record["v"][0]["ci"];
const issued_on = record["v"][0]["dt"];
const issuer = record["v"][0]["is"];
const vaccine_type = record["v"][0]["mp"];
const doses = record["v"][0]["dn"];
const dose_series = record["v"][0]["sd"];
const country = record["v"][0]["co"];

return {unique_cert_id, issued_on, issuer, vaccine_type, doses, dose_series, country};
};
Expand All @@ -84,7 +85,7 @@ class Covid19 {
res += `Born: ${formatISO8601Date(json.dob)}\n`;

if (json.vaccination) {
let vaccine_type = "";
let vaccine_type;
switch (json.vaccination.vaccine_type) {
case "EU/1/20/1528":
vaccine_type = "Comirnaty (Pfizer)";
Expand All @@ -110,7 +111,7 @@ class Covid19 {
}

if (json.test) {
let test_type = "";
let test_type;
switch (json.test.test_type) {
case "LP217198-3":
test_type = "Rapid immunoassay";
Expand All @@ -122,7 +123,7 @@ class Covid19 {
test_type = json.test.test_type;
}

let test_result = "";
let test_result;
switch (json.test.test_result) {
case "260415000":
test_result = "Negative";
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/upnqr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CODE_TYPE} from "../helpers";
import {CODE_TYPE, Transformer} from "./base";
import {decode} from "upnqr";

class Upnqr {
class Upnqr extends Transformer {
recognizer = "UPNQR";

codeType() {
Expand Down

0 comments on commit b4b0155

Please sign in to comment.