-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12897 from SORMAS-Foundation/feature-12841-Add-va…
…lidation-to-the-national-health-ID-field #12841 Add validation to the national health ID field
- Loading branch information
Showing
14 changed files
with
220 additions
and
188 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
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
67 changes: 67 additions & 0 deletions
67
.../main/java/de/symeda/sormas/api/utils/luxembourg/LuxembourgNationalHealthIdValidator.java
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,67 @@ | ||
/* | ||
* SORMAS® - Surveillance Outbreak Response Management & Analysis System | ||
* Copyright © 2016-2024 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI) | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.symeda.sormas.api.utils.luxembourg; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class LuxembourgNationalHealthIdValidator { | ||
|
||
/** | ||
* - AAAA = année de naissance | ||
* - MM = mois de naissance | ||
* - JJ = jour de naissance | ||
* - XXX = numéro aléatoire unique par date de naissance | ||
* - C1 = numéro de contrôle calculé sur AAAAMMJJXXX suivant l’algorithme LUHN 10 | ||
* - C2 = numéro de contrôle calculé sur AAAAMMJJXXX suivant l’algorithme VERHOEFF | ||
*/ | ||
private static final Pattern NATIONAL_HEALTH_ID_PATTERN = Pattern.compile("(\\d{4})(\\d{2})(\\d{2})(\\d{3})(\\d)(\\d)"); | ||
|
||
public static boolean isValid(String nationalHealthId, Integer birthdateYYYY, Integer birthdateMM, Integer birthdateDD) { | ||
if (nationalHealthId == null) { | ||
return false; | ||
} | ||
|
||
Matcher patternMatcher = NATIONAL_HEALTH_ID_PATTERN.matcher(nationalHealthId); | ||
if (!patternMatcher.matches()) { | ||
return false; | ||
} | ||
|
||
String yyyy = patternMatcher.group(1); | ||
String mm = patternMatcher.group(2); | ||
String dd = patternMatcher.group(3); | ||
String xxx = patternMatcher.group(4); | ||
String c1 = patternMatcher.group(5); | ||
String c2 = patternMatcher.group(6); | ||
|
||
if (isNullOrEquals(birthdateYYYY, Integer.parseInt(yyyy)) | ||
&& isNullOrEquals(birthdateMM, Integer.parseInt(mm)) | ||
&& isNullOrEquals(birthdateDD, Integer.parseInt(dd))) { | ||
String iNumber = yyyy + mm + dd + xxx; | ||
|
||
if (CheckDigitLuhn.checkDigit(iNumber + c1) && CheckDigitVerhoeff.checkDigit(iNumber + c2)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static boolean isNullOrEquals(Integer personBirthdateFieldValue, int yyyy) { | ||
return personBirthdateFieldValue == null || personBirthdateFieldValue == yyyy; | ||
} | ||
|
||
} |
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
72 changes: 0 additions & 72 deletions
72
...ain/java/de/symeda/sormas/backend/externalemail/luxembourg/NationalHealthIdValidator.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.