Skip to content

Commit

Permalink
r - Oppdaterer getBirthDate() til å håndtere Npid
Browse files Browse the repository at this point in the history
Co-authored-by: [email protected]
  • Loading branch information
MariamPervez committed Jan 19, 2024
1 parent a19f5a6 commit 1758423
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue
import no.nav.eessi.pensjon.shared.person.Fodselsnummer.Companion.tabeller.kontrollsiffer1
import no.nav.eessi.pensjon.shared.person.Fodselsnummer.Companion.tabeller.kontrollsiffer2
import org.slf4j.LoggerFactory
import java.time.LocalDate
import java.time.temporal.ChronoUnit

Expand All @@ -17,14 +18,15 @@ import java.time.temporal.ChronoUnit
* @see <a href="https://github.com/navikt/nav-foedselsnummer">nav-foedselsnummer</a>
*/
class Fodselsnummer private constructor(@JsonValue val value: String) {
private val logger = LoggerFactory.getLogger(Fodselsnummer::class.java)
init {
require("""\d{11}""".toRegex().matches(value)) { "Ikke et gyldig fødselsnummer: $value" }
require(!erFnr) { "Impelemntasjonen støtter ikke H-nummer og FH-nummer" }
require(gyldigeKontrollsiffer) { "Ugyldig kontrollnummer" }
}

fun getAge(): Int = ChronoUnit.YEARS.between(getBirthDate(), LocalDate.now()).toInt()
fun getBirthDate(): LocalDate = foedselsdato
fun getBirthDate(): LocalDate? = foedselsdato
fun isUnder18Year(): Boolean {
val resultAge = ChronoUnit.YEARS.between(foedselsdato, LocalDate.now()).toInt()
return resultAge < 18
Expand Down Expand Up @@ -69,8 +71,12 @@ class Fodselsnummer private constructor(@JsonValue val value: String) {
}
}

private val foedselsdato: LocalDate
private val foedselsdato: LocalDate?
get() {
if (erNpid) {
logger.warn("Ugyldig fødselsnummer, fnr er Npid: ${vaskFnr(value)}")
return null
}
val fnrMonth = value.slice(2 until 4).toInt()

val dayFelt = value.slice(0 until 2).toInt()
Expand Down

0 comments on commit 1758423

Please sign in to comment.