Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legger til mulighet for å bruke testidenter fra NAV (+40) #70

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/main/java/no/bekk/bekkopen/person/Fodselsnummer.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,32 +199,35 @@ static String parseSyntheticNumber(String fodselsnummer) {
if (!isSynthetic(fodselsnummer)) {
return fodselsnummer;
} else {

int monthNumber = Integer.parseInt(fodselsnummer.substring(2, 4));

//Skatteetaten - synthetic numbers
if (monthNumber >= 81 && monthNumber <= 92){

if (monthNumber >= 81 && monthNumber <= 92) {
return fodselsnummer.substring(0, 2) + (getThirdDigit(fodselsnummer) - 8) + fodselsnummer.substring(3);
}

//Norsk helsenett - synthetic numbers
if (monthNumber >= 66 && monthNumber <= 77 ) {
if (monthNumber >= 66 && monthNumber <= 77) {
String month = Integer.toString(monthNumber - 65);
if (month.length() == 1){
if (month.length() == 1) {
month = "0" + month;
}
return fodselsnummer.substring(0, 2) + month + fodselsnummer.substring(4);
}

//Norwegian Labour and Welfare Administration (NAV) - synthetic numbers
if (monthNumber >= 41 && monthNumber <= 52) {
return fodselsnummer.substring(0, 2) + (getThirdDigit(fodselsnummer) - 4) + fodselsnummer.substring(3);
}

throw new IllegalArgumentException(fodselsnummer + " is not a valid synthethic number");
}
}

static boolean isSynthetic(String fodselsnummer) {
try {
int monthNumber = Integer.parseInt(fodselsnummer.substring(2, 4));
if ((monthNumber >= 81 && monthNumber <= 92) || (monthNumber >= 66 && monthNumber <= 77)) {
if ((monthNumber >= 81 && monthNumber <= 92) || (monthNumber >= 66 && monthNumber <= 77) || (monthNumber >= 41 && monthNumber <= 52)) {
return true;
}
} catch (IllegalArgumentException e) {
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/no/bekk/bekkopen/person/FodselsnummerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public void testParseSyntheticNumber() {

//+65 on birth month 10-12
assertEquals("07116303651", Fodselsnummer.parseSyntheticNumber("07766303651"));

//+40 on birth month 1-12
assertEquals("10119120173", Fodselsnummer.parseSyntheticNumber("10519120173"));
}

@Test
Expand All @@ -186,5 +189,6 @@ public void testIsSyntheticNumber() {
assertTrue(Fodselsnummer.isSynthetic("07916303651"));
assertTrue(Fodselsnummer.isSynthetic("07666303651"));
assertTrue(Fodselsnummer.isSynthetic("07766303651"));
assertTrue(Fodselsnummer.isSynthetic("16499923264"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@ void testSyntheticDNumberIsWithinValidRange() {

assertTrue(FodselsnummerValidator.isValid("41774061388"));
assertFalse(FodselsnummerValidator.isValid("41784061882"));

//+40 (41-52)
assertTrue(FodselsnummerValidator.isValid("24417138435"));
assertFalse(FodselsnummerValidator.isValid("15407300685"));

assertTrue(FodselsnummerValidator.isValid("16526295130"));
assertFalse(FodselsnummerValidator.isValid("18535547706"));
}
}
Loading