Skip to content

Commit 3cf0198

Browse files
Light2288eapuzzoFehniixludovicoIBM
authored
feat: medical rules changes dl 4 feb
Co-authored-by: eapuzzo <emilio.apuzzo.ea@outlook.it> Co-authored-by: Johnny Bueti <29045904+Fehniix@users.noreply.github.com> Co-authored-by: Ludovico Girolimini <ludovico.girolimini2@ibm.com>
1 parent 1d331c6 commit 3cf0198

29 files changed

+1542
-242
lines changed

DGCAVerifier/BusinessRules/Internal/Validators/BlackListValidator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* license-start
3-
*
3+
*
44
* Copyright (C) 2021 Ministero della Salute and all other contributors
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

DGCAVerifier/BusinessRules/Internal/Validators/ChainValidator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* license-start
3-
*
3+
*
44
* Copyright (C) 2021 Ministero della Salute and all other contributors
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

DGCAVerifier/BusinessRules/Internal/Validators/DGCValidator.swift

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ protocol DCGValidatorFactory {
3232
}
3333

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

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

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

4141
func validate(hcert: HCert) -> Status
4242
}
4343

4444
extension DGCValidator {
4545

46-
static func validate(_ current: Date, from validityStart: Date) -> Status {
46+
func validate(_ current: Date, from validityStart: Date) -> Status {
4747
switch current {
4848
case ..<validityStart:
4949
return .notValidYet
@@ -52,27 +52,27 @@ extension DGCValidator {
5252
}
5353
}
5454

55-
static func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
55+
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date) -> Status {
5656
switch current {
5757
case ..<validityStart:
5858
return .notValidYet
5959
case validityStart...validityEnd:
6060
return .valid
6161
default:
62-
return .notValid
62+
return .expired
6363
}
6464
}
6565

66-
static func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
66+
func validate(_ current: Date, from validityStart: Date, to validityEnd: Date, extendedTo validityEndExtension: Date) -> Status {
6767
switch current {
6868
case ..<validityStart:
6969
return .notValidYet
7070
case validityStart...validityEnd:
7171
return .valid
7272
case validityEnd...validityEndExtension:
73-
return .valid
73+
return .verificationIsNeeded
7474
default:
75-
return .notValid
75+
return .expired
7676
}
7777
}
7878

@@ -100,6 +100,8 @@ struct ValidatorProducer {
100100
return SchoolValidatorFactory()
101101
case .work:
102102
return WorkValidatorFactory()
103+
case .italyEntry:
104+
return ItalyEntryValidatorFactory()
103105
}
104106
}
105107

@@ -129,11 +131,12 @@ struct BaseValidatorFactory: DCGValidatorFactory {
129131
struct ReinforcedValidatorFactory: DCGValidatorFactory {
130132

131133
func getValidator(hcert: HCert) -> DGCValidator? {
134+
let isIT = hcert.countryCode == Constants.ItalyCountryCode
132135
switch hcert.extendedType {
133136
case .unknown:
134137
return UnknownValidator()
135138
case .vaccine:
136-
return VaccineReinforcedValidator()
139+
return isIT ? VaccineReinforcedValidator() : VaccineReinforcedValidatorNotItaly()
137140
case .recovery:
138141
return RecoveryReinforcedValidator()
139142
case .test:
@@ -148,11 +151,12 @@ struct ReinforcedValidatorFactory: DCGValidatorFactory {
148151
struct BoosterValidatorFactory: DCGValidatorFactory {
149152

150153
func getValidator(hcert: HCert) -> DGCValidator? {
154+
let isIT = hcert.countryCode == Constants.ItalyCountryCode
151155
switch hcert.extendedType {
152156
case .unknown:
153157
return UnknownValidator()
154158
case .vaccine:
155-
return VaccineBoosterValidator()
159+
return isIT ? VaccineBoosterValidator() : VaccineBoosterValidatorNotItaly()
156160
case .recovery:
157161
return RecoveryBoosterValidator()
158162
case .test:
@@ -167,11 +171,13 @@ struct BoosterValidatorFactory: DCGValidatorFactory {
167171
struct SchoolValidatorFactory: DCGValidatorFactory {
168172

169173
func getValidator(hcert: HCert) -> DGCValidator? {
174+
let isIT = hcert.countryCode == Constants.ItalyCountryCode
175+
170176
switch hcert.extendedType {
171177
case .unknown:
172178
return UnknownValidator()
173179
case .vaccine:
174-
return VaccineSchoolValidator()
180+
return isIT ? VaccineSchoolValidator() : VaccineSchoolValidatorNotItaly()
175181
case .recovery:
176182
return RecoverySchoolValidator()
177183
case .test:
@@ -186,11 +192,13 @@ struct SchoolValidatorFactory: DCGValidatorFactory {
186192
struct WorkValidatorFactory: DCGValidatorFactory {
187193

188194
func getValidator(hcert: HCert) -> DGCValidator? {
195+
let isIT = hcert.countryCode == Constants.ItalyCountryCode
196+
189197
switch hcert.extendedType {
190198
case .unknown:
191199
return UnknownValidator()
192200
case .vaccine:
193-
return VaccineWorkValidator()
201+
return isIT ? VaccineWorkValidator() : VaccineWorkValidatorNotIt()
194202
case .recovery:
195203
return RecoveryWorkValidator()
196204
case .test:
@@ -202,6 +210,21 @@ struct WorkValidatorFactory: DCGValidatorFactory {
202210

203211
}
204212

205-
206-
207-
213+
struct ItalyEntryValidatorFactory: DCGValidatorFactory {
214+
215+
func getValidator(hcert: HCert) -> DGCValidator? {
216+
switch hcert.extendedType {
217+
case .unknown:
218+
return UnknownValidator()
219+
case .vaccine:
220+
return VaccineItalyEntryValidator()
221+
case .recovery:
222+
return RecoveryItalyEntryValidator()
223+
case .test:
224+
return TestItalyEntryValidator()
225+
case .vaccineExemption:
226+
return VaccineExemptionItalyEntryValidator()
227+
}
228+
}
229+
230+
}

DGCAVerifier/BusinessRules/Internal/Validators/DGCValidatorBuilder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* license-start
3-
*
3+
*
44
* Copyright (C) 2021 Ministero della Salute and all other contributors
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

DGCAVerifier/BusinessRules/Internal/Validators/HCertValidator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* license-start
3-
*
3+
*
44
* Copyright (C) 2021 Ministero della Salute and all other contributors
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

0 commit comments

Comments
 (0)