-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new Hcert type for vaccine exemption and relative Hcert extension * New way to get Hcer uvci property Added getUVCI() method in HCert+UVCI extension to return uvci information based on the new added HCert type (VaccineExemption) * Added business rules for vaccine exemption validation * feature: vaccine exemption - Fix condition in isExemptionValid function * feature: vaccine exemption - Fix condition in isExemptionValid function * code refactoring * feat: vaccine exemption remove comment Co-authored-by: Ludovico Girolimini <[email protected]> Co-authored-by: eapuzzo <[email protected]>
- Loading branch information
1 parent
8d8a301
commit 3d9a2ba
Showing
12 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
DGCAVerifier/BusinessRules/Internal/VaccineExemptionValidityCheck.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* license-start | ||
* | ||
* Copyright (C) 2021 Ministero della Salute and all other contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// | ||
// VaccineExemptionValidityCheck.swift | ||
// Verifier | ||
// | ||
// Created by Ludovico Girolimini on 12/01/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftDGC | ||
|
||
struct VaccineExemptionValidityCheck { | ||
|
||
typealias Validator = MedicalRulesValidator | ||
|
||
func isExemptionValid(_ hcert: HCert) -> Status { | ||
guard let exemption = hcert.vaccineExemptionStatements.last else { return .notValid } | ||
guard let dateFrom = exemption.dateFrom else { return .notValid } | ||
guard let currentDate = Date.startOfDay else { return .notValid } | ||
guard let dateUntil = exemption.dateUntil else { | ||
let validity = Validator.validate(currentDate, from: dateFrom) | ||
return isBoosterScanModeActive ? checkValidityOnBoosterScanMode(validity) : validity | ||
} | ||
let validity = Validator.validate(currentDate, from: dateFrom, to: dateUntil) | ||
return isBoosterScanModeActive ? checkValidityOnBoosterScanMode(validity) : validity | ||
} | ||
|
||
private var isBoosterScanModeActive: Bool { | ||
return Store.get(key: .scanMode) == Constants.scanModeBooster | ||
} | ||
|
||
private func checkValidityOnBoosterScanMode(_ certStatus: Status) -> Status { | ||
guard isBoosterScanModeActive, certStatus == .valid else { return certStatus } | ||
return .verificationIsNeeded | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// HCert+Type.swift | ||
// Verifier | ||
// | ||
// Created by Ludovico Girolimini on 10/01/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftDGC | ||
|
||
|
||
public enum HCertExtensionTypes: String { | ||
case test | ||
case vaccine | ||
case recovery | ||
case vaccineExemption | ||
case unknown | ||
} | ||
|
||
extension HCert { | ||
|
||
var extendedType: HCertExtensionTypes { | ||
switch self.type { | ||
case .recovery: | ||
return .recovery | ||
case .vaccine: | ||
return .vaccine | ||
case .test: | ||
return .test | ||
case .unknown: | ||
if self.vaccineExemptionStatements.isEmpty { | ||
return .unknown | ||
} | ||
return .vaccineExemption | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// HCert+UVCI.swift | ||
// Verifier | ||
// | ||
// Created by Ludovico Girolimini on 11/01/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftDGC | ||
|
||
|
||
extension HCert { | ||
|
||
func getUVCI() -> String { | ||
lastStatement?.uvci ?? "empty" | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
DGCAVerifier/Utils/HCert/HCert+VaccineExemptionStatement.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// HCert+Statement.swift | ||
// Verifier | ||
// | ||
// Created by Ludovico Girolimini on 10/01/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftDGC | ||
|
||
|
||
extension HCert { | ||
|
||
var vaccineExemptionStatements: [VaccineExemptionEntry] { | ||
return self.body["e"] | ||
.array? | ||
.compactMap { | ||
VaccineExemptionEntry(body: $0) | ||
} ?? [] | ||
} | ||
|
||
var lastStatement: HCertEntry? { | ||
guard self.statement == nil else { return self.statement } | ||
guard !vaccineExemptionStatements.isEmpty else { return nil } | ||
return vaccineExemptionStatements.last | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// VaccineExemptionEntry.swift | ||
// Verifier | ||
// | ||
// Created by Ludovico Girolimini on 10/01/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftDGC | ||
import SwiftyJSON | ||
|
||
|
||
struct VaccineExemptionEntry : HCertEntry { | ||
|
||
var info: [InfoSection] { | ||
return [] | ||
} | ||
|
||
var typeAddon: String { | ||
return "" | ||
} | ||
|
||
var validityFailures: [String] { | ||
return [] | ||
} | ||
|
||
let diseaseTargeted: String | ||
let issuer: String | ||
let countryCode: String | ||
let uvci: String | ||
let dateFrom: Date? | ||
let dateUntil: Date? | ||
|
||
|
||
enum Fields: String { | ||
case diseaseTargeted = "tg" | ||
case countryCode = "co" | ||
case issuer = "is" | ||
case uvci = "ci" | ||
case dateFrom = "df" | ||
case dateUntil = "du" | ||
} | ||
|
||
init?(body: JSON) { | ||
guard | ||
let diseaseTargeted = body[Fields.diseaseTargeted.rawValue].string, | ||
let country = body[Fields.countryCode.rawValue].string, | ||
let issuer = body[Fields.issuer.rawValue].string, | ||
let uvci = body[Fields.uvci.rawValue].string, | ||
let df = body[Fields.dateFrom.rawValue].string | ||
else { | ||
return nil | ||
} | ||
self.diseaseTargeted = diseaseTargeted | ||
self.countryCode = country | ||
self.issuer = issuer | ||
self.uvci = uvci | ||
self.dateFrom = Date(dateString: df) | ||
let du = body[Fields.dateUntil.rawValue].string | ||
self.dateUntil = du != nil ? Date(dateString: du!) : nil | ||
} | ||
|
||
} |
Oops, something went wrong.