Skip to content

Commit

Permalink
Merge pull request #70 from navikt/master
Browse files Browse the repository at this point in the history
Legger til mulighet for å bruke testidenter fra NAV (+40)
  • Loading branch information
eivinhb authored Dec 15, 2023
2 parents 87d0019 + 49fc8af commit b05bb24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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"));
}
}

0 comments on commit b05bb24

Please sign in to comment.