Skip to content

Commit

Permalink
Merge pull request #1373 from navikt/feature/add_fom_tom_til_ytelse_api
Browse files Browse the repository at this point in the history
[KAIZEN-0] legg til fom og tom dato for ytelse api
  • Loading branch information
LudvigHz authored Sep 13, 2024
2 parents 338f872 + 20095ad commit 975d55e
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SykepengerRequest implements Serializable {
public SykepengerRequest() {
}

public SykepengerRequest(LocalDate from, String ident, LocalDate to) {
public SykepengerRequest(String ident, LocalDate from, LocalDate to) {
this.from = from;
this.ident = ident;
this.to = to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ import no.nav.modiapersonoversiktproxy.consumer.infotrygd.foreldrepenger.Foreldr
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.foreldrepenger.mapping.to.ForeldrepengerListeRequest
import no.nav.modiapersonoversiktproxy.rest.JODA_DATOFORMAT
import org.joda.time.LocalDate
import org.joda.time.Years

class ForeldrepengerUttrekk constructor(private val forelderpengerService: ForeldrepengerServiceBi) {
fun hent(fodselsnummer: String): Map<String, Any?> {
fun hent(
fnr: String,
start: LocalDate?,
slutt: LocalDate?,
): Map<String, Any?> {
val from = start ?: LocalDate.now().minusYears(2)
val to = slutt ?: LocalDate.now()
val diff = Years.yearsBetween(from, to)
val period =
if (diff.years > 2) {
Periode(to.minusYears(2), to)
} else {
Periode(from, to)
}

val foreldrepenger =
forelderpengerService.hentForeldrepengerListe(
ForeldrepengerListeRequest(
fodselsnummer,
Periode(LocalDate.now().minusYears(2), LocalDate.now()),
),
)
forelderpengerService.hentForeldrepengerListe(ForeldrepengerListeRequest(fnr, period))

return mapOf(
"foreldrepenger" to
Expand Down Expand Up @@ -102,8 +112,18 @@ class ForeldrepengerUttrekk constructor(private val forelderpengerService: Forel
"rettTilFedrekvote" to it.rettTilFedrekvote?.termnavn,
"rettTilMødrekvote" to it.isRettTilModrekvote?.termnavn,
"stansårsak" to it.stansaarsak?.termnavn,
"historiskeUtbetalinger" to it.historiskeUtbetalinger?.let { utbetalinger -> hentHistoriskeUtbetalinger(utbetalinger) },
"kommendeUtbetalinger" to it.kommendeUtbetalinger?.let { utbetalinger -> hentKommendeUtbetalinger(utbetalinger) },
"historiskeUtbetalinger" to
it.historiskeUtbetalinger?.let { utbetalinger ->
hentHistoriskeUtbetalinger(
utbetalinger,
)
},
"kommendeUtbetalinger" to
it.kommendeUtbetalinger?.let { utbetalinger ->
hentKommendeUtbetalinger(
utbetalinger,
)
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.modiapersonoversiktproxy.rest.ytelse

import no.nav.modiapersonoversiktproxy.commondomain.Periode
import no.nav.modiapersonoversiktproxy.consumer.ereg.OrganisasjonService
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.domain.pleiepenger.Arbeidsforhold
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.domain.pleiepenger.Pleiepengeperiode
Expand All @@ -8,13 +9,34 @@ import no.nav.modiapersonoversiktproxy.consumer.infotrygd.domain.pleiepenger.Ved
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.pleiepenger.PleiepengerService
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.pleiepenger.mapping.to.PleiepengerListeRequest
import no.nav.modiapersonoversiktproxy.rest.DATOFORMAT
import org.joda.time.LocalDate
import org.joda.time.Years

class PleiepengerUttrekk constructor(
private val pleiepengerService: PleiepengerService,
private val organisasjonService: OrganisasjonService,
) {
fun hent(fodselsnummer: String): Map<String, Any?> {
val pleiepenger = pleiepengerService.hentPleiepengerListe(PleiepengerListeRequest(fodselsnummer))
fun hent(
fnr: String,
start: LocalDate?,
slutt: LocalDate?,
): Map<String, Any?> {
val from = start ?: LocalDate.now().minusYears(2)
val to = slutt ?: LocalDate.now()
val diff = Years.yearsBetween(from, to)
val period =
if (diff.years > 2) {
Periode(to.minusYears(2), to)
} else {
Periode(from, to)
}
val pleiepenger =
pleiepengerService.hentPleiepengerListe(
PleiepengerListeRequest(
fnr,
period,
),
)

return mapOf(
"pleiepenger" to
Expand Down Expand Up @@ -57,7 +79,13 @@ class PleiepengerUttrekk constructor(
private fun hentArbeidsforhold(arbeidsforhold: List<Arbeidsforhold>): List<Map<String, Any?>> {
return arbeidsforhold.map {
mapOf(
"arbeidsgiverNavn" to it.arbeidsgiverOrgnr?.let { orgnr -> hentArbeidsgiverNavn(organisasjonService, orgnr) },
"arbeidsgiverNavn" to
it.arbeidsgiverOrgnr?.let { orgnr ->
hentArbeidsgiverNavn(
organisasjonService,
orgnr,
)
},
"arbeidsgiverKontonr" to it.arbeidsgiverKontonr,
"inntektsperiode" to it.inntektsperiode,
"inntektForPerioden" to it.inntektForPerioden,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.modiapersonoversiktproxy.rest.ytelse

import no.nav.modiapersonoversiktproxy.commondomain.Periode
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.domain.Arbeidsforhold
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.domain.UtbetalingPaVent
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.domain.sykepenger.Gradering
Expand All @@ -9,12 +10,26 @@ import no.nav.modiapersonoversiktproxy.consumer.infotrygd.sykepenger.SykepengerS
import no.nav.modiapersonoversiktproxy.consumer.infotrygd.sykepenger.mapping.to.SykepengerRequest
import no.nav.modiapersonoversiktproxy.rest.JODA_DATOFORMAT
import org.joda.time.LocalDate
import org.joda.time.Years

class SykepengerUttrekk constructor(private val sykepengerService: SykepengerServiceBi) {
fun hent(fodselsnummer: String): Map<String, Any?> {
fun hent(
fnr: String,
start: LocalDate?,
slutt: LocalDate?,
): Map<String, Any?> {
val from = start ?: LocalDate.now().minusYears(2)
val to = slutt ?: LocalDate.now()
val diff = Years.yearsBetween(from, to)
val period =
if (diff.years > 2) {
Periode(to.minusYears(2), to)
} else {
Periode(from, to)
}
val sykepenger =
sykepengerService.hentSykmeldingsperioder(
SykepengerRequest(LocalDate.now().minusYears(2).plusDays(1), fodselsnummer, LocalDate.now()),
SykepengerRequest(fnr, period.from, period.to),
)

return mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,33 @@ class YtelseController

@PostMapping("sykepenger")
fun hentSykepenger(
@RequestBody fnr: String,
): Map<String, Any?> = SykepengerUttrekk(sykepengerService).hent(fnr)
@RequestBody body: RequestBodyContent,
): Map<String, Any?> =
SykepengerUttrekk(sykepengerService).hent(
body.fnr,
body.start?.let { lagRiktigDato(it) },
body.slutt?.let { lagRiktigDato(it) },
)

@PostMapping("foreldrepenger")
fun hentForeldrepenger(
@RequestBody fnr: String,
): Map<String, Any?> = ForeldrepengerUttrekk(getForeldrepengerService()).hent(fnr)
@RequestBody body: RequestBodyContent,
): Map<String, Any?> =
ForeldrepengerUttrekk(getForeldrepengerService()).hent(
body.fnr,
body.start?.let { lagRiktigDato(it) },
body.slutt?.let { lagRiktigDato(it) },
)

@PostMapping("pleiepenger")
fun hentPleiepenger(
@RequestBody fnr: String,
): Map<String, Any?> = PleiepengerUttrekk(pleiepengerService, organisasjonService).hent(fnr)
@RequestBody body: RequestBodyContent,
): Map<String, Any?> =
PleiepengerUttrekk(pleiepengerService, organisasjonService).hent(
body.fnr,
body.start?.let { lagRiktigDato(it) },
body.slutt?.let { lagRiktigDato(it) },
)

private fun getForeldrepengerService(): ForeldrepengerServiceBi {
return ForeldrepengerServiceBi { request ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DefaultSykepengerServiceTest {
@BeforeClass
public static void setUpOnce() {
mapper = SykepengerMapper.getInstance();
request = new SykepengerRequest(from, IDENT, to);
request = new SykepengerRequest(IDENT, from, to);
rawResponse = SykepengerMockFactory.createFimHentSykepengerResponse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import no.nav.tjeneste.virksomhet.foreldrepenger.v2.ForeldrepengerV2
import no.nav.tjeneste.virksomhet.foreldrepenger.v2.HentForeldrepengerettighetSikkerhetsbegrensning
import no.nav.tjeneste.virksomhet.foreldrepenger.v2.informasjon.FimFoedsel
import no.nav.tjeneste.virksomhet.foreldrepenger.v2.meldinger.FimHentForeldrepengerettighetResponse
import org.joda.time.LocalDate
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.math.BigInteger
Expand All @@ -16,6 +17,8 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

private const val FNR = "10108000398"
private val from = LocalDate.now().minusMonths(2)
private val to = LocalDate.now()

internal class ForeldrepengerUttrekkTest {
private val foreldrepengerServiceV2: ForeldrepengerV2 = mockk()
Expand All @@ -34,14 +37,14 @@ internal class ForeldrepengerUttrekkTest {
fun `Kaster Auth exception`() {
every { foreldrepengerServiceV2.hentForeldrepengerettighet(any()) } throws HentForeldrepengerettighetSikkerhetsbegrensning()

assertFailsWith<RuntimeException> { uttrekk.hent(FNR) }
assertFailsWith<RuntimeException> { uttrekk.hent(FNR, from, to) }
}

@Test
fun `Test på om felter blir satt`() {
every { foreldrepengerServiceV2.hentForeldrepengerettighet(any()) } returns mockResponse()

val response = uttrekk.hent(FNR)
val response = uttrekk.hent(FNR, from, to)
val foreldrepengerListe = response["foreldrepenger"] as List<*>
val foreldrepenger = foreldrepengerListe[0] as Map<*, *>

Expand All @@ -52,7 +55,7 @@ internal class ForeldrepengerUttrekkTest {
fun `Tester datosetting`() {
every { foreldrepengerServiceV2.hentForeldrepengerettighet(any()) } returns mockResponse()

val response = uttrekk.hent(FNR)
val response = uttrekk.hent(FNR, from, to)
val foreldrepengerListe = response["foreldrepenger"] as List<*>
val foreldrepenger = foreldrepengerListe[0] as Map<*, *>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import no.nav.tjeneste.virksomhet.pleiepenger.v1.PleiepengerV1
import no.nav.tjeneste.virksomhet.pleiepenger.v1.informasjon.WSPerson
import no.nav.tjeneste.virksomhet.pleiepenger.v1.informasjon.WSPleiepengerettighet
import no.nav.tjeneste.virksomhet.pleiepenger.v1.meldinger.WSHentPleiepengerettighetResponse
import org.joda.time.LocalDate
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNull

private const val FNR = "10108000398"
private const val BARNETS_FNR = "01010012345"
private val from = LocalDate.now().minusMonths(2)
private val to = LocalDate.now()

internal class PleiepengerUttrekkTest {
private val pleiepengerV1: PleiepengerV1 = mockk()
Expand All @@ -29,14 +32,14 @@ internal class PleiepengerUttrekkTest {
fun `Kaster Auth exception`() {
every { pleiepengerV1.hentPleiepengerettighet(any()) } throws HentPleiepengerettighetSikkerhetsbegrensning()

assertFailsWith<RuntimeException> { uttrekk.hent(FNR) }
assertFailsWith<RuntimeException> { uttrekk.hent(FNR, from, to) }
}

@Test
fun `Tom liste returnerer null`() {
every { pleiepengerV1.hentPleiepengerettighet(any()) } returns WSHentPleiepengerettighetResponse()

val response = uttrekk.hent(FNR)
val response = uttrekk.hent(FNR, from, to)
val pleiepenger = response["pleiepenger"]

assertNull(pleiepenger)
Expand All @@ -46,7 +49,7 @@ internal class PleiepengerUttrekkTest {
fun `Test på om felter blir satt`() {
every { pleiepengerV1.hentPleiepengerettighet(any()) } returns mockResponse()

val response = uttrekk.hent(FNR)
val response = uttrekk.hent(FNR, from, to)
val pleiepengerListe = response["pleiepenger"] as List<*>
val pleiepenger = pleiepengerListe[0] as Map<*, *>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import no.nav.tjeneste.virksomhet.sykepenger.v2.informasjon.FimsykBruker
import no.nav.tjeneste.virksomhet.sykepenger.v2.informasjon.FimsykStansaarsak
import no.nav.tjeneste.virksomhet.sykepenger.v2.informasjon.FimsykSykmeldingsperiode
import no.nav.tjeneste.virksomhet.sykepenger.v2.meldinger.FimHentSykepengerListeResponse
import org.joda.time.LocalDate
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import javax.xml.datatype.DatatypeFactory
Expand All @@ -19,6 +20,8 @@ import kotlin.test.assertFailsWith

private const val FNR = "10108000398"
private const val STANS = "STANS"
private val from = LocalDate.now().minusMonths(2)
private val to = LocalDate.now()

internal class SykepengerUttrekkTest {
private val sykepengerV2: SykepengerV2 = mockk()
Expand All @@ -37,7 +40,7 @@ internal class SykepengerUttrekkTest {
fun`Kaster Auth exception`() {
every { sykepengerV2.hentSykepengerListe(any()) } throws HentSykepengerListeSikkerhetsbegrensning()

assertFailsWith<RuntimeException> { uttrekk.hent(FNR) }
assertFailsWith<RuntimeException> { uttrekk.hent(FNR, from, to) }
}

@Test
Expand All @@ -59,7 +62,7 @@ internal class SykepengerUttrekkTest {
}

private fun unwrapResponse(): Map<String, Any?> {
val response = uttrekk.hent(FNR)
val response = uttrekk.hent(FNR, from, to)
val perioderListe = response["sykepenger"] as List<*>
return perioderListe[0] as Map<String, Any?>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ interface ArenaInfotrygdApi {
slutt: String?,
): OppfolgingskontraktResponse

fun hentSykepenger(fnr: String): Map<String, Any?>
fun hentSykepenger(
fnr: String,
fom: String,
tom: String,
): Map<String, Any?>

fun hentForeldrepenger(fnr: String): Map<String, Any?>
fun hentForeldrepenger(
fnr: String,
fom: String,
tom: String,
): Map<String, Any?>

fun hentPleiepenger(fnr: String): Map<String, Any?>
fun hentPleiepenger(
fnr: String,
fom: String,
tom: String,
): Map<String, Any?>

fun hentOppfolgingssakFraArena(fnr: String): JournalforingSak?
}
Expand Down Expand Up @@ -73,18 +85,33 @@ open class ArenaInfotrygdApiImpl(
}

@Cacheable(value = ["sykePengerCache"])
override fun hentSykepenger(fnr: String): Map<String, Any?> {
return sendRequest("sykepenger", fnr) ?: mapOf()
override fun hentSykepenger(
fnr: String,
fom: String,
tom: String,
): Map<String, Any?> {
val requestContent = Json.encodeToString(RequestBodyContent(fnr, fom, tom))
return sendRequest("sykepenger", requestContent) ?: mapOf()
}

@Cacheable(value = ["foreldrePengerCache"])
override fun hentForeldrepenger(fnr: String): Map<String, Any?> {
return sendRequest("foreldrepenger", fnr) ?: mapOf()
override fun hentForeldrepenger(
fnr: String,
fom: String,
tom: String,
): Map<String, Any?> {
val requestContent = Json.encodeToString(RequestBodyContent(fnr, fom, tom))
return sendRequest("foreldrepenger", requestContent) ?: mapOf()
}

@Cacheable(value = ["pleiePengerCache"])
override fun hentPleiepenger(fnr: String): Map<String, Any?> {
return sendRequest("pleiepenger", fnr) ?: mapOf()
override fun hentPleiepenger(
fnr: String,
fom: String,
tom: String,
): Map<String, Any?> {
val requestContent = Json.encodeToString(RequestBodyContent(fnr, fom, tom))
return sendRequest("pleiepenger", requestContent) ?: mapOf()
}

private inline fun <reified T> sendRequest(
Expand Down
Loading

0 comments on commit 975d55e

Please sign in to comment.