-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Støtte for håndtering av utenlandsopphold i uttak. (#364)
* Støtte for håndtering av utenlandsopphold i uttak. * Flere tester for utenlandsopphold + bugfix. * Ny test og feilretting ifm telling av utenlandsperioder. * Lagt på feature toggle
- Loading branch information
Showing
16 changed files
with
285 additions
and
14 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
7 changes: 7 additions & 0 deletions
7
kontrakter/src/main/kotlin/no/nav/pleiepengerbarn/uttak/kontrakter/UtenlandsoppholdÅrsak.kt
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,7 @@ | ||
package no.nav.pleiepengerbarn.uttak.kontrakter | ||
|
||
enum class UtenlandsoppholdÅrsak { | ||
BARNET_INNLAGT_I_HELSEINSTITUSJON_FOR_NORSK_OFFENTLIG_REGNING, | ||
BARNET_INNLAGT_I_HELSEINSTITUSJON_DEKKET_ETTER_AVTALE_MED_ET_ANNET_LAND_OM_TRYGD, | ||
INGEN | ||
} |
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
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
105 changes: 105 additions & 0 deletions
105
...er/src/main/kotlin/no/nav/pleiepengerbarn/uttak/regler/delregler/UtenlandsoppholdRegel.kt
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,105 @@ | ||
package no.nav.pleiepengerbarn.uttak.regler.delregler | ||
|
||
import no.nav.fpsak.tidsserie.LocalDateSegment | ||
import no.nav.fpsak.tidsserie.LocalDateTimeline | ||
import no.nav.pleiepengerbarn.uttak.kontrakter.* | ||
import no.nav.pleiepengerbarn.uttak.regler.NULL_PROSENT | ||
import no.nav.pleiepengerbarn.uttak.regler.domene.RegelGrunnlag | ||
import no.nav.pleiepengerbarn.uttak.regler.kontrakter_ext.overlapperDelvis | ||
import no.nav.pleiepengerbarn.uttak.regler.kontrakter_ext.virkedager | ||
import java.time.DayOfWeek | ||
import java.time.LocalDate | ||
|
||
private const val MAX_DAGER_PER_ÅR = 8 * 5 | ||
|
||
internal class UtenlandsoppholdRegel : UttaksplanRegel { | ||
|
||
|
||
override fun kjør(uttaksplan: Uttaksplan, grunnlag: RegelGrunnlag): Uttaksplan { | ||
|
||
val featureToggleUtenlandsoppholdRgel = System.getenv("UTENLANDSOPPHOLD_REGEL").toBoolean() | ||
if (!featureToggleUtenlandsoppholdRgel) { | ||
return uttaksplan | ||
} | ||
|
||
val nyePerioder = mutableMapOf<LukketPeriode, UttaksperiodeInfo>() | ||
val utenlandsdagerFraForrigeUttaksplan = grunnlag.finnUtenlandsdager() | ||
|
||
var brukteDager = 0 | ||
val sortertePerioder = uttaksplan.perioder.keys.toList().sortedBy { it.fom } | ||
sortertePerioder.forEach { periode -> | ||
val info = uttaksplan.perioder[periode] | ||
?: throw IllegalStateException("Dette skal ikke kunne skje. Alle perioder skal finnes i map.") | ||
if (info.utfall == Utfall.OPPFYLT && grunnlag.overlapperMedUtenlandsoppholdUtenGyldigÅrsak(periode)) { | ||
val avklartePerioder = periode.avklarPeriode(utenlandsdagerFraForrigeUttaksplan, brukteDager) | ||
avklartePerioder.forEach { (nyPeriode, utenlandsoppholdInnvilget) -> | ||
if (utenlandsoppholdInnvilget) { | ||
nyePerioder[nyPeriode] = info.copy(utenlandsoppholdUtenÅrsak = true) | ||
brukteDager += nyPeriode.virkedager() | ||
} else { | ||
nyePerioder[nyPeriode] = info.settIkkeInnvilgetPgaUtenlandsopphold() | ||
} | ||
} | ||
} else { | ||
nyePerioder[periode] = info | ||
} | ||
} | ||
return uttaksplan.copy(perioder = nyePerioder) | ||
} | ||
|
||
} | ||
|
||
private fun RegelGrunnlag.overlapperMedUtenlandsoppholdUtenGyldigÅrsak(periode: LukketPeriode): Boolean { | ||
return this.utenlandsoppholdperioder.any {periode.overlapperDelvis(it.key) && it.value.utenlandsoppholdÅrsak == UtenlandsoppholdÅrsak.INGEN} | ||
} | ||
|
||
private fun UttaksperiodeInfo.settIkkeInnvilgetPgaUtenlandsopphold(): UttaksperiodeInfo { | ||
val årsaker = setOf(Årsak.FOR_MANGE_DAGER_UTENLANDSOPPHOLD) | ||
val oppdaterteUtbetalingsgrader = this.utbetalingsgrader.map {it.copy(utbetalingsgrad = NULL_PROSENT)} | ||
return this.copy(utfall = Utfall.IKKE_OPPFYLT, uttaksgrad = NULL_PROSENT, årsaker = årsaker, utbetalingsgrader = oppdaterteUtbetalingsgrader) | ||
} | ||
|
||
private fun LukketPeriode.avklarPeriode(utenlandsdager: Set<LocalDate>, brukteDager: Int): Map<LukketPeriode, Boolean> { | ||
|
||
val segmenter = mutableListOf<LocalDateSegment<Boolean>>() | ||
|
||
val antallFraTidligereUttaksplan = utenlandsdager.mellom(this.fom.minusYears(1), this.fom.minusDays(1)) | ||
|
||
var brukteDagerPåDennePerioden = 0 | ||
this.stream().forEach { dato -> | ||
val forbrukteDager = antallFraTidligereUttaksplan + brukteDager + brukteDagerPåDennePerioden | ||
if (forbrukteDager < MAX_DAGER_PER_ÅR) { | ||
segmenter.add(LocalDateSegment(dato, dato, true)) | ||
brukteDagerPåDennePerioden++ | ||
} else { | ||
segmenter.add(LocalDateSegment(dato, dato, false)) | ||
} | ||
} | ||
val nyePerioder = LocalDateTimeline(segmenter).compress() | ||
|
||
return nyePerioder.toSegments().associate {LukketPeriode(it.fom, it.tom) to it.value} | ||
} | ||
|
||
private fun Set<LocalDate>.mellom(fom: LocalDate, tom: LocalDate) = this.count { it in fom..tom } | ||
|
||
private fun RegelGrunnlag.finnUtenlandsdager(): Set<LocalDate> { | ||
if (this.forrigeUttaksplan == null) { | ||
return setOf() | ||
} | ||
return this.forrigeUttaksplan.perioder | ||
.filter {it.value.utenlandsoppholdUtenÅrsak} | ||
.flatMap {it.key.tilDatoer()} | ||
.toSet() | ||
} | ||
|
||
private fun LukketPeriode.tilDatoer(): Set<LocalDate> { | ||
val datoer = mutableSetOf<LocalDate>() | ||
this.stream().forEach { | ||
if (it.dayOfWeek !in listOf(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY)) { | ||
datoer.add(it) | ||
} | ||
} | ||
return datoer | ||
} | ||
|
||
private fun LukketPeriode.stream() = fom.datesUntil(tom.plusDays(1)) |
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
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
2 changes: 2 additions & 0 deletions
2
server/src/main/resources/db/migration/V1.15__nytt_felt_utenlandsopphold.sql
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,2 @@ | ||
|
||
ALTER TABLE uttaksperiode ADD COLUMN utenlandsopphold_uten_aarsak boolean NOT NULL DEFAULT false; |
Oops, something went wrong.