File indexing completed on 2024-11-24 04:44:41

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  */
0005 
0006 #include "kvaccinationcertificate.h"
0007 #include "khealthcertificatetypes_p.h"
0008 
0009 class KVaccinationCertificatePrivate : public QSharedData
0010 {
0011 public:
0012     QString name;
0013     QDate dateOfBirth;
0014     QDate date;
0015     QString disease;
0016     QString vaccineType;
0017     QString vaccine;
0018     QUrl vaccineUrl;
0019     QString manufacturer;
0020     int dose = 0;
0021     int totalDoses = 0;
0022     QString country;
0023     QString certificateIssuer;
0024     QString certificateId;
0025     QDateTime certificateIssueDate;
0026     QDateTime certificateExpiryDate;
0027     QByteArray rawData;
0028     KHealthCertificate::SignatureValidation signatureState = KHealthCertificate::UnknownSignature;
0029 };
0030 
0031 KHEALTHCERTIFICATE_MAKE_GADGET(Vaccination)
0032 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, name, setName)
0033 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QDate, dateOfBirth, setDateOfBirth)
0034 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QDate, date, setDate)
0035 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, disease, setDisease)
0036 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, vaccineType, setVaccineType)
0037 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, vaccine, setVaccine)
0038 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QUrl, vaccineUrl, setVaccineUrl)
0039 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, manufacturer, setManufacturer)
0040 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, int, dose, setDose)
0041 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, int, totalDoses, setTotalDoses)
0042 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, country, setCountry)
0043 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, certificateIssuer, setCertificateIssuer)
0044 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QString, certificateId, setCertificateId)
0045 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QDateTime, certificateIssueDate, setCertificateIssueDate)
0046 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QDateTime, certificateExpiryDate, setCertificateExpiryDate)
0047 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, QByteArray, rawData, setRawData)
0048 KHEALTHCERTIFICATE_MAKE_PROPERTY(Vaccination, KHealthCertificate::SignatureValidation, signatureState, setSignatureState)
0049 
0050 KHealthCertificate::CertificateValidation KVaccinationCertificate::validationState() const
0051 {
0052     const auto vacState = vaccinationState();
0053     if (vacState == KVaccinationCertificate::Invalid || d->signatureState == KHealthCertificate::InvalidSignature) {
0054         return KHealthCertificate::Invalid;
0055     }
0056 
0057     if ((vacState != KVaccinationCertificate::FullyVaccinated && vacState != KVaccinationCertificate::Vaccinated)
0058         || d->signatureState == KHealthCertificate::UnknownSignature) {
0059         return KHealthCertificate::Partial;
0060     }
0061 
0062     return KHealthCertificate::Valid;
0063 }
0064 
0065 KVaccinationCertificate::VaccinationState KVaccinationCertificate::vaccinationState() const
0066 {
0067     if (d->certificateIssueDate > QDateTime::currentDateTime() || (d->certificateExpiryDate.isValid() && d->certificateExpiryDate < QDateTime::currentDateTime())) {
0068         return KVaccinationCertificate::Invalid;
0069     }
0070     if (d->date > QDate::currentDate() || (d->dose == 0 && d->totalDoses)) {
0071         return KVaccinationCertificate::Invalid;
0072     }
0073 
0074     if (d->date.addDays(14) >= QDate::currentDate() && (d->dose == 1 || (d->dose == 2 && d->totalDoses == 2))) {
0075         return KVaccinationCertificate::VaccinationTooRecent;
0076     }
0077     if (d->dose < d->totalDoses) {
0078         return KVaccinationCertificate::PartiallyVaccinated;
0079     }
0080 
0081     return d->totalDoses ? KVaccinationCertificate::FullyVaccinated : KVaccinationCertificate::Vaccinated;
0082 }
0083 
0084 #include "moc_kvaccinationcertificate.cpp"