stapelberg / coronaqr

Go decoder and verifier for EU Digital COVID Certificate (EUDCC) QR code data
Apache License 2.0
169 stars 15 forks source link

Display names instead of ID for fields like TestResult, TestType, etc. #8

Open francoismdj opened 3 years ago

francoismdj commented 3 years ago

Enhancement proposal in the idea of submitting a pull request:

Some fields in the certificate are identifiers that refer to elements declared at https://github.com/ehn-dcc-development/ehn-dcc-schema/blob/release/1.3.0/valuesets/. These elements have a display name in a human readable sentence.

With the certificate decoded, it would be nice to print display names instead of (or in addition to) identifiers. For example, display :

TestType:   Nucleic acid amplification with probe detection
TestResult: Not detected

Instead of:

TestType: (string) (len=8) "LP6464-4",
TestResult: (string) (len=9) "260415000",
francoismdj commented 3 years ago

I wrote an implemention but I’m not confident with the method or the code quality.

The ID -> Name translation is called in cmd/coronadecode/coronadecode.go:

func printCertificate(decoded *coronaqr.Decoded) {
        fmt.Printf("\n")
        fmt.Printf("COVID certificate:\n")
        fmt.Printf("Issued:     %v\n", decoded.IssuedAt)
        fmt.Printf("Expiration: %v\n", decoded.Expiration)
        fmt.Printf("Contents:   ")
-       spew.Dump(decoded.Cert)
+       fmt.Printf("Tests:          \n")
+       for _, test := range decoded.Cert.TestRecords {
+               fmt.Printf(" - Target:         %v\n", test.GetTargetName())
+               fmt.Printf("   Type:           %v\n", test.GetTypeName())
+               fmt.Printf("   Name:           %v\n", test.Name)
+               fmt.Printf("   Manufacturer:   %v\n", test.Manufacturer)
[…]

Because of removing the spew.Dump(…) line, we have to code the printing of each field, now and each time a field is added to the certificate structure…

The ID -> Name mapping is implemented in coronaqr.go:

+func (tr *TestRecord) GetTypeName() string {
+       if tr.TestType == "LP6464-4" {
+               return "Nucleic acid amplification with probe detection"
+       } else if tr.TestType == "LP217198-3" {
+               return "Rapid immunoassay"
+       } else {
+               return "Unknown type ID: " + tr.TestType
+       }
+}

ID->Name is hardcoded in the file, in functions attached to the Test/Vaccine/RecoveryRecord structures. It would be nice to load the JSON files from the official source. ID tables may be big! Unfortunately it’s out of my skills at this time.

stapelberg commented 3 years ago

Because of removing the spew.Dump(…) line, we have to code the printing of each field, now and each time a field is added to the certificate structure…

An alternative would be to implement a function, say convertToHumanReadable, which takes a certificate, replaces the field contents, and returns the modified certificate. Then, just spew.Dump() that new certificate with its human-readable fields.

ID->Name is hardcoded in the file, in functions attached to the Test/Vaccine/RecoveryRecord structures. It would be nice to load the JSON files from the official source. ID tables may be big! Unfortunately it’s out of my skills at this time.

Are the official sources the GitHub repository releases, or is there another data source for these mappings?