Skip to content

Commit

Permalink
feat: medical rules changes dl 4 feb
Browse files Browse the repository at this point in the history
Co-authored-by: eapuzzo <[email protected]>
Co-authored-by: Johnny Bueti <[email protected]>
Co-authored-by: Ludovico Girolimini <[email protected]>
  • Loading branch information
4 people authored Feb 14, 2022
1 parent 1d331c6 commit 3cf0198
Show file tree
Hide file tree
Showing 29 changed files with 1,542 additions and 242 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* 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.
Expand Down
55 changes: 39 additions & 16 deletions DGCAVerifier/BusinessRules/Internal/Validators/DGCValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ protocol DCGValidatorFactory {
}

protocol DGCValidator {
static func validate(_ current: Date, from validityStart: Date) -> Status
func validate(_ current: Date, from validityStart: Date) -> Status

static func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status

static func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status

func validate(hcert: HCert) -> Status
}

extension DGCValidator {

static func validate(_ current: Date, from validityStart: Date) -> Status {
func validate(_ current: Date, from validityStart: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
Expand All @@ -52,27 +52,27 @@ extension DGCValidator {
}
}

static func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
default:
return .notValid
return .expired
}
}

static func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
switch current {
case ..<validityStart:
return .notValidYet
case validityStart...validityEnd:
return .valid
case validityEnd...validityEndExtension:
return .valid
return .verificationIsNeeded
default:
return .notValid
return .expired
}
}

Expand Down Expand Up @@ -100,6 +100,8 @@ struct ValidatorProducer {
return SchoolValidatorFactory()
case .work:
return WorkValidatorFactory()
case .italyEntry:
return ItalyEntryValidatorFactory()
}
}

Expand Down Expand Up @@ -129,11 +131,12 @@ struct BaseValidatorFactory: DCGValidatorFactory {
struct ReinforcedValidatorFactory: DCGValidatorFactory {

func getValidator(hcert: HCert) -> DGCValidator? {
let isIT = hcert.countryCode == Constants.ItalyCountryCode
switch hcert.extendedType {
case .unknown:
return UnknownValidator()
case .vaccine:
return VaccineReinforcedValidator()
return isIT ? VaccineReinforcedValidator() : VaccineReinforcedValidatorNotItaly()
case .recovery:
return RecoveryReinforcedValidator()
case .test:
Expand All @@ -148,11 +151,12 @@ struct ReinforcedValidatorFactory: DCGValidatorFactory {
struct BoosterValidatorFactory: DCGValidatorFactory {

func getValidator(hcert: HCert) -> DGCValidator? {
let isIT = hcert.countryCode == Constants.ItalyCountryCode
switch hcert.extendedType {
case .unknown:
return UnknownValidator()
case .vaccine:
return VaccineBoosterValidator()
return isIT ? VaccineBoosterValidator() : VaccineBoosterValidatorNotItaly()
case .recovery:
return RecoveryBoosterValidator()
case .test:
Expand All @@ -167,11 +171,13 @@ struct BoosterValidatorFactory: DCGValidatorFactory {
struct SchoolValidatorFactory: DCGValidatorFactory {

func getValidator(hcert: HCert) -> DGCValidator? {
let isIT = hcert.countryCode == Constants.ItalyCountryCode

switch hcert.extendedType {
case .unknown:
return UnknownValidator()
case .vaccine:
return VaccineSchoolValidator()
return isIT ? VaccineSchoolValidator() : VaccineSchoolValidatorNotItaly()
case .recovery:
return RecoverySchoolValidator()
case .test:
Expand All @@ -186,11 +192,13 @@ struct SchoolValidatorFactory: DCGValidatorFactory {
struct WorkValidatorFactory: DCGValidatorFactory {

func getValidator(hcert: HCert) -> DGCValidator? {
let isIT = hcert.countryCode == Constants.ItalyCountryCode

switch hcert.extendedType {
case .unknown:
return UnknownValidator()
case .vaccine:
return VaccineWorkValidator()
return isIT ? VaccineWorkValidator() : VaccineWorkValidatorNotIt()
case .recovery:
return RecoveryWorkValidator()
case .test:
Expand All @@ -202,6 +210,21 @@ struct WorkValidatorFactory: DCGValidatorFactory {

}




struct ItalyEntryValidatorFactory: DCGValidatorFactory {

func getValidator(hcert: HCert) -> DGCValidator? {
switch hcert.extendedType {
case .unknown:
return UnknownValidator()
case .vaccine:
return VaccineItalyEntryValidator()
case .recovery:
return RecoveryItalyEntryValidator()
case .test:
return TestItalyEntryValidator()
case .vaccineExemption:
return VaccineExemptionItalyEntryValidator()
}
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* 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.
Expand Down
Loading

0 comments on commit 3cf0198

Please sign in to comment.