Skip to content

[Backend] Complete Vaccination Certificate PDF Generation and Download Endpoint #506

@llinsss

Description

@llinsss

⚠️ This is a backend issue — work is done inside the backend/ folder

Description

backend/src/modules/certificates/certificates.service.ts imports PDFDocument from pdfkit and defines a VaccinationCertificate interface, but the PDF generation method is incomplete — it builds the document structure but never writes the pet owner section, vet clinic stamp, or QR code verification link. The resulting PDF is missing critical information.

Current State

  • CertificatesService — partial PDF generation, missing owner/clinic/QR sections
  • VaccinationCertificate interface — fully defined with all required fields
  • No GET /certificates/:id/download endpoint exists
  • No certificate storage — PDFs are generated on-the-fly but not cached

What Needs to Be Built

1. Complete PDF Layout

The generated PDF must include:

  • Header: PetChain logo, certificate title, issue date
  • Pet Section: name, species, breed, DOB, microchip number
  • Vaccination Section: vaccine name, administered date, expiry date, batch number, manufacturer
  • Veterinarian Section: vet name, clinic name, address, phone
  • Owner Section: owner name, email (currently missing)
  • QR Code: scannable link to /verify/{certificateCode} for tamper-proof verification
  • Footer: certificate code, blockchain anchor hash (if available)

2. QR Code Embedding

  • Use qrcode package (already used in MedicalRecordsService) to generate QR as PNG buffer
  • Embed QR image into PDF using pdfkit's image() method

3. Download Endpoint

GET /certificates/:vaccinationId/download
  • Generate or retrieve cached PDF
  • Stream response with headers:
    Content-Type: application/pdf
    Content-Disposition: attachment; filename=certificate-{code}.pdf

4. Caching

  • Cache generated PDFs in S3/CDN via StorageModule
  • Invalidate cache if vaccination record is updated

Acceptance Criteria

  • PDF contains all sections: pet, vaccination, vet, owner, QR code, footer
  • QR code links to a valid verification URL
  • GET /certificates/:vaccinationId/download streams the PDF correctly
  • Generated PDFs are cached and reused on subsequent requests
  • Cache is invalidated when the vaccination record changes
  • Integration test verifies PDF is non-empty and contains expected text

Files to Modify

  • backend/src/modules/certificates/certificates.service.ts
  • backend/src/modules/certificates/certificates.controller.ts (add download endpoint)
  • backend/src/modules/certificates/certificates.module.ts (import StorageModule)

Priority

Medium — certificates are a key trust feature for vet visits and travel

Estimated Effort

2 days

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions