diff --git a/nais/alerts.yaml b/nais/alerts.yaml index 08c708e43..e313bce17 100644 --- a/nais/alerts.yaml +++ b/nais/alerts.yaml @@ -36,24 +36,3 @@ spec: labels: namespace: team-esyfo severity: warning - - alert: KAFKA INFOTRYGD CONSUMER LAG - expr: kafka_consumergroup_group_topic_sum_lag{topic="aap.sykepengedager.infotrygd.v1", group="esyfovarsel-group-infotrygd-01"} > 0 - for: 15m - annotations: - summary: "esyfovarsel har ukonsumerte Kafkameldinger på topic aap.sykepengedager.infotrygd.v1" - action: "Finn ut hvorfor esyfovarsel har stoppet å konsumere fra topic" - labels: - namespace: team-esyfo - severity: warning - - alert: KAFKA UTBETALING CONSUMER LAG - expr: kafka_consumergroup_group_topic_sum_lag{topic="flex.ditt-sykefravaer-melding", group="esyfovarsel-group-utbetaling-spleis-01"} > 0 - for: 15m - annotations: - summary: "esyfovarsel har ukonsumerte Kafkameldinger på topic tbd.utbetaling" - action: "Finn ut hvorfor esyfovarsel har stoppet å konsumere fra topic" - labels: - namespace: team-esyfo - severity: warning - - - diff --git a/src/main/kotlin/no/nav/syfo/BootstrapApplication.kt b/src/main/kotlin/no/nav/syfo/BootstrapApplication.kt index 53341fc22..87d20bb36 100644 --- a/src/main/kotlin/no/nav/syfo/BootstrapApplication.kt +++ b/src/main/kotlin/no/nav/syfo/BootstrapApplication.kt @@ -30,17 +30,13 @@ import no.nav.syfo.consumer.distribuerjournalpost.JournalpostdistribusjonConsume import no.nav.syfo.consumer.dkif.DkifConsumer import no.nav.syfo.consumer.narmesteLeder.NarmesteLederConsumer import no.nav.syfo.consumer.narmesteLeder.NarmesteLederService -import no.nav.syfo.consumer.pdl.PdlConsumer import no.nav.syfo.consumer.syfosmregister.SykmeldingerConsumer -import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer import no.nav.syfo.db.Database import no.nav.syfo.db.DatabaseInterface import no.nav.syfo.db.grantAccessToIAMUsers import no.nav.syfo.job.closeExpiredMicrofrontendsJob import no.nav.syfo.kafka.common.launchKafkaListener -import no.nav.syfo.kafka.consumers.infotrygd.InfotrygdKafkaConsumer import no.nav.syfo.kafka.consumers.testdata.reset.TestdataResetConsumer -import no.nav.syfo.kafka.consumers.utbetaling.UtbetalingKafkaConsumer import no.nav.syfo.kafka.consumers.varselbus.VarselBusKafkaConsumer import no.nav.syfo.kafka.producers.brukernotifikasjoner.BrukernotifikasjonKafkaProducer import no.nav.syfo.kafka.producers.dinesykmeldte.DineSykmeldteHendelseKafkaProducer @@ -61,7 +57,6 @@ import no.nav.syfo.service.MerVeiledningVarselService import no.nav.syfo.service.MotebehovVarselService import no.nav.syfo.service.OppfolgingsplanVarselService import no.nav.syfo.service.SenderFacade -import no.nav.syfo.service.SykepengerMaxDateService import no.nav.syfo.service.SykmeldingService import no.nav.syfo.service.TestdataResetService import no.nav.syfo.service.VarselBusService @@ -108,7 +103,6 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE database.grantAccessToIAMUsers() val azureAdTokenConsumer = AzureAdTokenConsumer(env.authEnv) - val pdlConsumer = getPdlConsumer(env.urlEnv, azureAdTokenConsumer) val dkifConsumer = getDkifConsumer(env.urlEnv, azureAdTokenConsumer) val sykmeldingerConsumer = SykmeldingerConsumer(env.urlEnv, azureAdTokenConsumer) val narmesteLederConsumer = NarmesteLederConsumer(env.urlEnv, azureAdTokenConsumer) @@ -163,7 +157,6 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE val manglendeMedvirkningVarselService = ManglendeMedvirkningVarselService(senderFacade) val oppfolgingsplanVarselService = OppfolgingsplanVarselService(senderFacade, accessControlService, env.urlEnv.oppfolgingsplanerUrl) - val sykepengerMaxDateService = SykepengerMaxDateService(database, pdlConsumer) val merVeiledningVarselService = MerVeiledningVarselService( senderFacade = senderFacade, env = env, @@ -195,9 +188,6 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE merVeiledningVarselService ) - val veilederTilgangskontrollConsumer = - VeilederTilgangskontrollConsumer(env.urlEnv, azureAdTokenConsumer) - val testdataResetService = TestdataResetService(database, mikrofrontendService, senderFacade) connector { @@ -209,27 +199,17 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE serverModule( env, - sykepengerMaxDateService, mikrofrontendService, - veilederTilgangskontrollConsumer, ) kafkaModule( env, varselBusService, - sykepengerMaxDateService, testdataResetService, ) } } -private fun getPdlConsumer(urlEnv: UrlEnv, azureADConsumer: AzureAdTokenConsumer): PdlConsumer { - return when { - isLocal() -> PdlConsumer.LocalPdlConsumer(urlEnv, azureADConsumer) - else -> PdlConsumer(urlEnv, azureADConsumer) - } -} - private fun getDkifConsumer(urlEnv: UrlEnv, azureADConsumer: AzureAdTokenConsumer): DkifConsumer { return when { isLocal() -> DkifConsumer(urlEnv, azureADConsumer) @@ -239,9 +219,7 @@ private fun getDkifConsumer(urlEnv: UrlEnv, azureADConsumer: AzureAdTokenConsume fun Application.serverModule( env: Environment, - sykepengerMaxDateService: SykepengerMaxDateService, mikrofrontendService: MikrofrontendService, - veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, ) { install(ContentNegotiation) { jackson { @@ -265,8 +243,6 @@ fun Application.serverModule( runningRemotely { setupRoutesWithAuthentication( mikrofrontendService, - sykepengerMaxDateService, - veilederTilgangskontrollConsumer, env.authEnv, ) } @@ -274,8 +250,6 @@ fun Application.serverModule( runningLocally { setupLocalRoutesWithAuthentication( mikrofrontendService, - sykepengerMaxDateService, - veilederTilgangskontrollConsumer, env.authEnv, ) } @@ -291,24 +265,9 @@ fun Application.serverModule( fun Application.kafkaModule( env: Environment, varselbusService: VarselBusService, - sykepengerMaxDateService: SykepengerMaxDateService, testdataResetService: TestdataResetService, ) { runningRemotely { - launch(backgroundTasksContext) { - launchKafkaListener( - state, - InfotrygdKafkaConsumer(env, sykepengerMaxDateService), - ) - } - - launch(backgroundTasksContext) { - launchKafkaListener( - state, - UtbetalingKafkaConsumer(env, sykepengerMaxDateService), - ) - } - launch(backgroundTasksContext) { launchKafkaListener( state, diff --git a/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApi.kt b/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApi.kt deleted file mode 100644 index 2202bbec4..000000000 --- a/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApi.kt +++ /dev/null @@ -1,58 +0,0 @@ -package no.nav.syfo.api.maxdate - -import io.ktor.http.HttpStatusCode -import io.ktor.server.application.ApplicationCall -import io.ktor.server.application.call -import io.ktor.server.response.respond -import io.ktor.server.routing.Route -import io.ktor.server.routing.get -import net.logstash.logback.argument.StructuredArguments -import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer -import no.nav.syfo.domain.PersonIdent -import no.nav.syfo.service.SykepengerMaxDateService -import no.nav.syfo.utils.* -import org.slf4j.LoggerFactory -import java.io.Serializable -import java.time.LocalDate - -fun Route.registerSykepengerMaxDateAzureApi( - sykepengerMaxDateService: SykepengerMaxDateService, - veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, -) { - val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateAzureApi") - get("/api/azure/v1/sykepenger/maxdate") { - val personIdent = call.personIdent() - val token = call.bearerToken() - val callId = call.getCallId() - - if (veilederTilgangskontrollConsumer.hasAccess(personIdent, token, callId)) { - try { - val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(personIdent.value) - log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}") - call.respond(SykepengerMaxDateAzureResponse(sykepengerMaxDate?.forelopig_beregnet_slutt)) - } catch (e: Exception) { - log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}") - call.respond( - HttpStatusCode.InternalServerError, - "Encountered exception during fetching max date from database: ${e.message}", - ) - } - } else { - val message = "Cannot fetch max date: Veileder has no access to person" - log.warn("$message, {}", callIdArgument(callId)) - call.respond(HttpStatusCode.Forbidden, message) - } - } -} - -data class SykepengerMaxDateAzureResponse( - val maxDate: LocalDate?, -) : Serializable - -private fun ApplicationCall.personIdent(): PersonIdent = this.getPersonIdent() - ?: throw IllegalArgumentException("Failed to get maxDate: No $NAV_PERSONIDENT_HEADER supplied in request header") - -private fun ApplicationCall.bearerToken(): String = this.getBearerToken() - ?: throw IllegalArgumentException("Failed to get maxDate: No Authorization header supplied") - -private fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!! diff --git a/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApiV2.kt b/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApiV2.kt deleted file mode 100644 index 321011ff4..000000000 --- a/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateAzureApiV2.kt +++ /dev/null @@ -1,61 +0,0 @@ -package no.nav.syfo.api.maxdate - -import io.ktor.http.HttpStatusCode -import io.ktor.server.application.ApplicationCall -import io.ktor.server.application.call -import io.ktor.server.response.respond -import io.ktor.server.routing.Route -import io.ktor.server.routing.get -import net.logstash.logback.argument.StructuredArguments -import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer -import no.nav.syfo.db.domain.PMaksDato -import no.nav.syfo.domain.PersonIdent -import no.nav.syfo.service.SykepengerMaxDateService -import no.nav.syfo.utils.NAV_PERSONIDENT_HEADER -import no.nav.syfo.utils.getBearerToken -import no.nav.syfo.utils.getCallId -import no.nav.syfo.utils.getPersonIdent -import org.slf4j.LoggerFactory -import java.io.Serializable - -fun Route.registerSykepengerMaxDateAzureApiV2( - sykepengerMaxDateService: SykepengerMaxDateService, - veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, -) { - val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateAzureApiV2") - get("/api/azure/v2/sykepenger/maxdate") { - val personIdent = call.personIdent() - val token = call.bearerToken() - val callId = call.getCallId() - - if (veilederTilgangskontrollConsumer.hasAccess(personIdent, token, callId)) { - try { - val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(personIdent.value) - log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}") - call.respond(SykepengerMaxDateAzureV2Response(sykepengerMaxDate)) - } catch (e: Exception) { - log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}") - call.respond( - HttpStatusCode.InternalServerError, - "Encountered exception during fetching max date from database: ${e.message}", - ) - } - } else { - val message = "Cannot fetch max date: Veileder has no access to person" - log.warn("$message, {}", callIdArgument(callId)) - call.respond(HttpStatusCode.Forbidden, message) - } - } -} - -data class SykepengerMaxDateAzureV2Response( - val maxDate: PMaksDato?, -) : Serializable - -private fun ApplicationCall.personIdent(): PersonIdent = this.getPersonIdent() - ?: throw IllegalArgumentException("Failed to get maxDate: No $NAV_PERSONIDENT_HEADER supplied in request header") - -private fun ApplicationCall.bearerToken(): String = this.getBearerToken() - ?: throw IllegalArgumentException("Failed to get maxDate: No Authorization header supplied") - -private fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!! diff --git a/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateRest.kt b/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateRest.kt deleted file mode 100644 index 74f11fe0c..000000000 --- a/src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateRest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package no.nav.syfo.api.maxdate - -import io.ktor.http.HttpStatusCode -import io.ktor.server.application.call -import io.ktor.server.auth.authentication -import io.ktor.server.response.respond -import io.ktor.server.routing.Route -import io.ktor.server.routing.get -import no.nav.syfo.auth.BrukerPrincipal -import no.nav.syfo.service.SykepengerMaxDateService -import no.nav.syfo.utils.formatDateForLetter -import org.slf4j.LoggerFactory -import java.io.Serializable - -fun Route.registerSykepengerMaxDateRestApi( - sykepengerMaxDateService: SykepengerMaxDateService, -) { - val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateRest") - get("/api/v1/sykepenger/maxdate") { - val principal: BrukerPrincipal = call.authentication.principal()!! - val sykmeldtFnr = principal.fnr - val isoFormat = call.request.queryParameters["isoformat"]?.toBoolean() ?: false - - try { - val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(sykmeldtFnr) - val maxDate = sykepengerMaxDate?.let { - if (isoFormat) { - it.forelopig_beregnet_slutt.toString() - } else { - formatDateForLetter(it.forelopig_beregnet_slutt) - } - } - val utbetaltTom = sykepengerMaxDate?.let { - if (isoFormat) { - it.utbetalt_tom.toString() - } else { - formatDateForLetter(it.utbetalt_tom) - } - } - log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}") - call.respond( - SykepengerMaxDateResponse( - maxDate = maxDate, - utbetaltTom = utbetaltTom, - gjenstaendeSykedager = sykepengerMaxDate?.gjenstaende_sykedager - ) - ) - } catch (e: Exception) { - log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}") - call.respond( - HttpStatusCode.InternalServerError, - "Encountered exception during fetching max date from database: ${e.message}", - ) - } - } -} - -data class SykepengerMaxDateResponse( - val maxDate: String?, - val utbetaltTom: String?, - val gjenstaendeSykedager: String? -) : Serializable diff --git a/src/main/kotlin/no/nav/syfo/auth/Authentication.kt b/src/main/kotlin/no/nav/syfo/auth/Authentication.kt index 5f6a1a6f7..f3acd332f 100644 --- a/src/main/kotlin/no/nav/syfo/auth/Authentication.kt +++ b/src/main/kotlin/no/nav/syfo/auth/Authentication.kt @@ -2,22 +2,24 @@ package no.nav.syfo.auth import com.auth0.jwk.JwkProvider import com.auth0.jwk.JwkProviderBuilder -import io.ktor.server.application.* -import io.ktor.server.auth.* -import io.ktor.server.auth.jwt.* -import io.ktor.server.routing.* +import io.ktor.server.application.Application +import io.ktor.server.application.install +import io.ktor.server.auth.Authentication +import io.ktor.server.auth.AuthenticationConfig +import io.ktor.server.auth.UserIdPrincipal +import io.ktor.server.auth.authenticate +import io.ktor.server.auth.basic +import io.ktor.server.auth.jwt.JWTCredential +import io.ktor.server.auth.jwt.JWTPrincipal +import io.ktor.server.auth.jwt.jwt +import io.ktor.server.routing.routing +import java.net.URL +import java.util.concurrent.TimeUnit import no.nav.syfo.AuthEnv import no.nav.syfo.api.job.registerJobTriggerApi -import no.nav.syfo.api.maxdate.registerSykepengerMaxDateAzureApi -import no.nav.syfo.api.maxdate.registerSykepengerMaxDateAzureApiV2 -import no.nav.syfo.api.maxdate.registerSykepengerMaxDateRestApi -import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer -import no.nav.syfo.service.SykepengerMaxDateService import no.nav.syfo.service.microfrontend.MikrofrontendService import org.slf4j.Logger import org.slf4j.LoggerFactory -import java.net.URL -import java.util.concurrent.TimeUnit val log: Logger = LoggerFactory.getLogger(Authentication::class.qualifiedName) @@ -103,8 +105,6 @@ private fun JWTCredential.inExpectedAudience(expectedAudience: List) = e fun Application.setupLocalRoutesWithAuthentication( mikrofrontendService: MikrofrontendService, - sykepengerMaxDateService: SykepengerMaxDateService, - veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, authEnv: AuthEnv, ) { install(Authentication) { @@ -120,22 +120,14 @@ fun Application.setupLocalRoutesWithAuthentication( } routing { - registerSykepengerMaxDateRestApi(sykepengerMaxDateService) - authenticate("auth-basic") { registerJobTriggerApi(mikrofrontendService) } - authenticate(JwtIssuerType.INTERNAL_AZUREAD.name) { - registerSykepengerMaxDateAzureApi(sykepengerMaxDateService, veilederTilgangskontrollConsumer) - registerSykepengerMaxDateAzureApiV2(sykepengerMaxDateService, veilederTilgangskontrollConsumer) - } } } fun Application.setupRoutesWithAuthentication( mikrofrontendService: MikrofrontendService, - sykepengerMaxDateService: SykepengerMaxDateService, - veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer, authEnv: AuthEnv, ) { val wellKnownTokenX = getWellKnown(authEnv.tokenXWellKnownUrl) @@ -150,12 +142,5 @@ fun Application.setupRoutesWithAuthentication( authenticate("auth-basic") { registerJobTriggerApi(mikrofrontendService) } - authenticate(JwtIssuerType.INTERNAL_AZUREAD.name) { - registerSykepengerMaxDateAzureApi(sykepengerMaxDateService, veilederTilgangskontrollConsumer) - registerSykepengerMaxDateAzureApiV2(sykepengerMaxDateService, veilederTilgangskontrollConsumer) - } - authenticate("tokenx") { - registerSykepengerMaxDateRestApi(sykepengerMaxDateService) - } } } diff --git a/src/main/kotlin/no/nav/syfo/consumer/pdl/PdlConsumer.kt b/src/main/kotlin/no/nav/syfo/consumer/pdl/PdlConsumer.kt index 8ab48a710..c8faf5a74 100644 --- a/src/main/kotlin/no/nav/syfo/consumer/pdl/PdlConsumer.kt +++ b/src/main/kotlin/no/nav/syfo/consumer/pdl/PdlConsumer.kt @@ -1,32 +1,24 @@ package no.nav.syfo.consumer.pdl -import io.ktor.client.call.* -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.* +import io.ktor.client.call.body +import io.ktor.client.request.header +import io.ktor.client.request.post +import io.ktor.client.request.setBody +import io.ktor.client.statement.HttpResponse +import io.ktor.http.HttpHeaders +import io.ktor.http.HttpStatusCode +import java.io.FileNotFoundException import no.nav.syfo.UrlEnv import no.nav.syfo.auth.AzureAdTokenConsumer import no.nav.syfo.metrics.COUNT_CALL_PDL_FAIL import no.nav.syfo.metrics.COUNT_CALL_PDL_SUCCESS import no.nav.syfo.utils.httpClientWithRetry -import no.nav.syfo.utils.isAlderMindreEnnGittAr import org.slf4j.LoggerFactory -import java.io.FileNotFoundException open class PdlConsumer(private val urlEnv: UrlEnv, private val azureAdTokenConsumer: AzureAdTokenConsumer) { private val httpClient = httpClientWithRetry(expectSuccess = true) private val log = LoggerFactory.getLogger(PdlConsumer::class.qualifiedName) - suspend fun isBrukerYngreEnnGittMaxAlder(ident: String, maxAlder: Int): Boolean { - val fodselsdato = hentPerson(ident)?.getFodselsdato() - if (fodselsdato == null) { - log.warn("Returnert fødselsdato for en person fra PDL er null. Fortsetter som om bruker er yngre enn $maxAlder år da fødselsdato er ukjent.") - return true - } else { - return isAlderMindreEnnGittAr(fodselsdato, maxAlder) - } - } - suspend fun hentPerson( personIdent: String, ): HentPersonData? { @@ -68,7 +60,4 @@ open class PdlConsumer(private val urlEnv: UrlEnv, private val azureAdTokenConsu return this::class.java.getResource(graphQueryResourcePath)?.readText()?.replace("[\n\r]", "") ?: throw FileNotFoundException("Could not found resource: $graphQueryResourcePath") } - - class LocalPdlConsumer(urlEnv: UrlEnv, azureAdTokenConsumer: AzureAdTokenConsumer) : - PdlConsumer(urlEnv, azureAdTokenConsumer) } diff --git a/src/main/kotlin/no/nav/syfo/db/DatabaseUtil.kt b/src/main/kotlin/no/nav/syfo/db/DatabaseUtil.kt index cbc9bf143..180e9ddf3 100644 --- a/src/main/kotlin/no/nav/syfo/db/DatabaseUtil.kt +++ b/src/main/kotlin/no/nav/syfo/db/DatabaseUtil.kt @@ -1,9 +1,8 @@ package no.nav.syfo.db -import no.nav.syfo.db.domain.* import java.sql.ResultSet -import java.util.* - +import no.nav.syfo.db.domain.PMikrofrontendSynlighet +import no.nav.syfo.db.domain.PUtsendtVarsel fun ResultSet.toList(mapper: ResultSet.() -> T) = mutableListOf().apply { while (next()) { @@ -11,26 +10,6 @@ fun ResultSet.toList(mapper: ResultSet.() -> T) = mutableListOf().apply { } } -fun ResultSet.toPPlanlagtVarsel() = PPlanlagtVarsel( - uuid = getString("uuid"), - fnr = getString("fnr"), - aktorId = getString("aktor_id"), - orgnummer = getString("orgnummer"), - type = getString("type"), - utsendingsdato = getDate("utsendingsdato").toLocalDate(), - opprettet = getTimestamp("opprettet").toLocalDateTime(), - sistEndret = getTimestamp("sist_endret").toLocalDateTime() -) - -fun ResultSet.toPUtbetaling() = PUtbetaling( - id = UUID.fromString(getString("id")), - fnr = getString("fnr"), - utbetaltTom = getDate("utbetalt_tom").toLocalDate(), - forelopigBeregnetSlutt = getDate("forelopig_beregnet_slutt").toLocalDate(), - gjenstaendeSykedager = getInt("gjenstaende_sykedager"), - opprettet = getTimestamp("opprettet").toLocalDateTime(), -) - fun ResultSet.toPUtsendtVarsel() = PUtsendtVarsel( uuid = getString("uuid"), fnr = getString("fnr"), @@ -46,28 +25,6 @@ fun ResultSet.toPUtsendtVarsel() = PUtsendtVarsel( arbeidsgivernotifikasjonMerkelapp = getString("arbeidsgivernotifikasjon_merkelapp") ) -fun ResultSet.toVarslingIdsListe(): List { - val rader = ArrayList() - while (this.next()) { - rader.add(getString("sykmelding_id")) - } - return rader -} - -fun ResultSet.toVarslingIdsListeCount(): Int { - this.last() - return this.row -} - -fun ResultSet.toPMaksDato() = PMaksDato( - id = getString("id"), - fnr = getString("fnr"), - forelopig_beregnet_slutt = getTimestamp("forelopig_beregnet_slutt").toLocalDateTime().toLocalDate(), - utbetalt_tom = getTimestamp("utbetalt_tom").toLocalDateTime().toLocalDate(), - gjenstaende_sykedager = getString("gjenstaende_sykedager"), - opprettet = getTimestamp("opprettet").toLocalDateTime(), -) - fun ResultSet.toPMikrofrontendSynlighet() = PMikrofrontendSynlighet( uuid = getString("uuid"), synligFor = getString("synlig_for"), diff --git a/src/main/kotlin/no/nav/syfo/db/PlanlagtVarselDAO.kt b/src/main/kotlin/no/nav/syfo/db/PlanlagtVarselDAO.kt deleted file mode 100644 index fe5fa8a90..000000000 --- a/src/main/kotlin/no/nav/syfo/db/PlanlagtVarselDAO.kt +++ /dev/null @@ -1,185 +0,0 @@ -package no.nav.syfo.db - -import no.nav.syfo.db.domain.PPlanlagtVarsel -import no.nav.syfo.db.domain.PlanlagtVarsel -import no.nav.syfo.db.domain.VarselType -import java.sql.Date -import java.sql.ResultSet -import java.sql.Timestamp -import java.time.LocalDate -import java.time.LocalDateTime -import java.util.* - -fun DatabaseInterface.storePlanlagtVarsel(planlagtVarsel: PlanlagtVarsel) { - val insertStatement1 = """INSERT INTO PLANLAGT_VARSEL ( - uuid, - fnr, - aktor_id, - type, - utsendingsdato, - opprettet, - sist_endret, - orgnummer) VALUES (?, ?, ?, ?, ?, ?, ?, ?) - """.trimIndent() - - val insertStatement2 = """INSERT INTO SYKMELDING_IDS ( - uuid, - sykmelding_id, - varsling_id) VALUES (?, ?, ?) - """.trimIndent() - - val now = Timestamp.valueOf(LocalDateTime.now()) - val varselUUID = UUID.randomUUID() - - connection.use { connection -> - connection.prepareStatement(insertStatement1).use { - it.setObject(1, varselUUID) - it.setString(2, planlagtVarsel.fnr) - it.setString(3, planlagtVarsel.aktorId) - it.setString(4, planlagtVarsel.type.name) - it.setDate(5, Date.valueOf(planlagtVarsel.utsendingsdato)) - it.setTimestamp(6, now) - it.setTimestamp(7, now) - it.setString(8, planlagtVarsel.orgnummer) - it.executeUpdate() - } - - connection.prepareStatement(insertStatement2).use { - for (sykmeldingId: String in planlagtVarsel.sykmeldingerId) { - it.setObject(1, UUID.randomUUID()) - it.setString(2, sykmeldingId) - it.setObject(3, varselUUID) - - it.addBatch() - } - it.executeBatch() - } - - connection.commit() - } -} - -fun DatabaseInterface.fetchPlanlagtVarselByFnr(fnr: String): List { - val queryStatement = """SELECT * - FROM PLANLAGT_VARSEL - WHERE fnr = ? - """.trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.setString(1, fnr) - it.executeQuery().toList { toPPlanlagtVarsel() } - } - } -} - -fun DatabaseInterface.fetchPlanlagtVarselByUtsendingsdato(utsendingsdato: LocalDate): List { - val queryStatement = """SELECT * - FROM PLANLAGT_VARSEL - WHERE utsendingsdato = ? - """.trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.setTimestamp(1, Timestamp.valueOf(utsendingsdato.atStartOfDay())) - it.executeQuery().toList { toPPlanlagtVarsel() } - } - } -} - -fun DatabaseInterface.fetchPlanlagtVarselByUtsendingsdatoAndType(utsendingsdato: LocalDate, varselType: String): List { - val queryStatement = """SELECT * - FROM PLANLAGT_VARSEL - WHERE utsendingsdato = ? - AND type = ? - """.trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.setTimestamp(1, Timestamp.valueOf(utsendingsdato.atStartOfDay())) - it.setString(2, varselType) - it.executeQuery().toList { toPPlanlagtVarsel() } - } - } -} - -fun DatabaseInterface.fetchPlanlagtVarselByTypeAndUtsendingsdato(type: VarselType, fromDate: LocalDate, toDate: LocalDate): List { - val queryStatement = """SELECT * - FROM PLANLAGT_VARSEL - WHERE type = ? - AND utsendingsdato >= ? - AND utsendingsdato <= ? - """.trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.setString(1, type.name) - it.setDate(2, Date.valueOf(fromDate)) - it.setDate(3, Date.valueOf(toDate)) - it.executeQuery().toList { toPPlanlagtVarsel() } - } - } -} - -fun DatabaseInterface.fetchSykmeldingerIdByPlanlagtVarselsUUID(uuid: String): List { - val queryStatement = """SELECT * - FROM SYKMELDING_IDS - WHERE varsling_id = ? - """.trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.setObject(1, UUID.fromString(uuid)) - it.executeQuery().toVarslingIdsListe() - } - } -} - -fun DatabaseInterface.fetchAllSykmeldingIdsAndCount(): Int { - val queryStatement = """SELECT * - FROM SYKMELDING_IDS - """.trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE).use { - it.executeQuery().toVarslingIdsListeCount() - } - } -} - -fun DatabaseInterface.deletePlanlagtVarselByVarselId(uuid: String) { - val queryStatement1 = """DELETE - FROM PLANLAGT_VARSEL - WHERE uuid = ? - """.trimIndent() - - connection.use { connection -> - connection.prepareStatement(queryStatement1).use { - it.setObject(1, UUID.fromString(uuid)) - it.executeUpdate() - } - - connection.commit() - } -} - -fun DatabaseInterface.deletePlanlagtVarselBySykmeldingerId(sykmeldingerId: Set, varselType: VarselType) { - val st1 = """DELETE - FROM PLANLAGT_VARSEL - WHERE uuid IN (SELECT varsling_id FROM SYKMELDING_IDS WHERE sykmelding_id = ? ) - AND type = ? - """.trimMargin() - - connection.use { connection -> - connection.prepareStatement(st1).use { - for (sykmeldingId: String in sykmeldingerId) { - it.setString(1, sykmeldingId) - it.setString(2, varselType.name) - it.addBatch() - } - it.executeBatch() - } - - connection.commit() - } -} diff --git a/src/main/kotlin/no/nav/syfo/db/UtbetalingInfotrygdDAO.kt b/src/main/kotlin/no/nav/syfo/db/UtbetalingInfotrygdDAO.kt deleted file mode 100644 index d641e8d07..000000000 --- a/src/main/kotlin/no/nav/syfo/db/UtbetalingInfotrygdDAO.kt +++ /dev/null @@ -1,73 +0,0 @@ -package no.nav.syfo.db - -import no.nav.syfo.domain.PersonIdent -import no.nav.syfo.kafka.consumers.infotrygd.domain.InfotrygdSource -import java.sql.Date -import java.sql.Timestamp -import java.time.LocalDate -import java.time.LocalDateTime.now -import java.util.* - -fun DatabaseInterface.storeInfotrygdUtbetaling( - fnr: String, - sykepengerMaxDate: LocalDate, - utbetaltTilDate: LocalDate, - gjenstaendeSykepengedager: Int, - source: InfotrygdSource -) { - val insertStatement = """INSERT INTO UTBETALING_INFOTRYGD ( - ID, - FNR, - MAX_DATE, - UTBET_TOM, - GJENSTAENDE_SYKEDAGER, - OPPRETTET, - SOURCE) VALUES (?,?,?,?,?,?,?) - """.trimIndent() - connection.use { connection -> - try { - connection.prepareStatement(insertStatement).use { - it.setObject(1, UUID.randomUUID()) - it.setString(2, fnr) - it.setDate(3, Date.valueOf(sykepengerMaxDate)) - it.setDate(4, Date.valueOf(utbetaltTilDate)) - it.setInt(5, gjenstaendeSykepengedager) - it.setTimestamp(6, Timestamp.valueOf(now())) - it.setString(7, source.name) - it.executeUpdate() - } - connection.commit() - } catch (e: Exception) { - log.info("[INFOTRYGD KAFKA] Ignoring inserting a message from Infotrygd with max date $sykepengerMaxDate, utbet tom $utbetaltTilDate and gjenstaendeSykepengedager $gjenstaendeSykepengedager") - } - } -} - -//TODO: Currently only used for testing, delete if not needed later on -fun DatabaseInterface.fetchInfotrygdUtbetalingByFnr(fnr: String): MutableList { - val fetchStatement = """SELECT * FROM UTBETALING_SPLEIS WHERE FNR = ?""".trimIndent() - - val gjenstaaendeDagerAsList = connection.use { connection -> - connection.prepareStatement(fetchStatement).use { - it.setString(1, fnr) - it.executeQuery().toList { getInt("GJENSTAENDE_SYKEDAGER") } - } - } - - return gjenstaaendeDagerAsList -} - - -fun DatabaseInterface.deleteUtbetalingInfotrygdByFnr(fnr: PersonIdent) { - val updateStatement = """DELETE FROM UTBETALING_INFOTRYGD - WHERE fnr = ? - """.trimMargin() - - return connection.use { connection -> - connection.prepareStatement(updateStatement).use { - it.setString(1, fnr.value) - it.executeUpdate() - } - connection.commit() - } -} diff --git a/src/main/kotlin/no/nav/syfo/db/UtbetalingSpleisDAO.kt b/src/main/kotlin/no/nav/syfo/db/UtbetalingSpleisDAO.kt deleted file mode 100644 index 4518afac6..000000000 --- a/src/main/kotlin/no/nav/syfo/db/UtbetalingSpleisDAO.kt +++ /dev/null @@ -1,71 +0,0 @@ -package no.nav.syfo.db - -import no.nav.syfo.domain.PersonIdent -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis -import java.sql.Date -import java.sql.SQLIntegrityConstraintViolationException -import java.sql.Timestamp -import java.time.LocalDateTime -import java.util.* - -fun DatabaseInterface.storeSpleisUtbetaling( - utbetaling: UtbetalingSpleis, - opprettetDato: LocalDateTime = LocalDateTime.now() -) { - val insertStatement = """INSERT INTO UTBETALING_SPLEIS ( - ID, - FNR, - ORGANISASJONSNUMMER, - EVENT, - TYPE, - FORELOPIG_BEREGNET_SLUTT, - FORBRUKTE_SYKEDAGER, - GJENSTAENDE_SYKEDAGER, - STONADSDAGER, - ANTALL_VEDTAK, - FOM, - TOM, - UTBETALING_ID, - KORRELASJON_ID, - OPPRETTET) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) - """.trimIndent() - connection.use { connection -> - try { - connection.prepareStatement(insertStatement).use { - it.setObject(1, UUID.randomUUID()) - it.setString(2, utbetaling.fødselsnummer) - it.setString(3, utbetaling.organisasjonsnummer) - it.setString(4, utbetaling.event) - it.setString(5, utbetaling.type) - it.setDate(6, Date.valueOf(utbetaling.foreløpigBeregnetSluttPåSykepenger)) - it.setInt(7, utbetaling.forbrukteSykedager!!) //Ikke nullable for event utbetaling_utbetalt - it.setInt(8, utbetaling.gjenståendeSykedager!!) //Ikke nullable for event utbetaling_utbetalt - it.setInt(9, utbetaling.stønadsdager!!) //Ikke nullable for event utbetaling_utbetalt - it.setInt(10, utbetaling.antallVedtak!!) //Ikke nullable for event utbetaling_utbetalt - it.setDate(11, Date.valueOf(utbetaling.fom)) - it.setDate(12, Date.valueOf(utbetaling.tom)) - it.setString(13, utbetaling.utbetalingId) - it.setString(14, utbetaling.korrelasjonsId) - it.setTimestamp(15, Timestamp.valueOf(opprettetDato)) - it.executeUpdate() - } - connection.commit() - } catch (e: SQLIntegrityConstraintViolationException) { - log.debug("Ignoring duplicate message from Spleis with utbetalingID " + utbetaling.utbetalingId) - } - } -} - -fun DatabaseInterface.deleteUtbetalingSpleisByFnr(fnr: PersonIdent) { - val updateStatement = """DELETE FROM UTBETALING_SPLEIS - WHERE fnr = ? - """.trimMargin() - - return connection.use { connection -> - connection.prepareStatement(updateStatement).use { - it.setString(1, fnr.value) - it.executeUpdate() - } - connection.commit() - } -} diff --git a/src/main/kotlin/no/nav/syfo/db/UtbetalingerDAO.kt b/src/main/kotlin/no/nav/syfo/db/UtbetalingerDAO.kt deleted file mode 100644 index babb07734..000000000 --- a/src/main/kotlin/no/nav/syfo/db/UtbetalingerDAO.kt +++ /dev/null @@ -1,59 +0,0 @@ -package no.nav.syfo.db - -import no.nav.syfo.db.domain.PMaksDato -import no.nav.syfo.db.domain.PUtbetaling - - -fun DatabaseInterface.fetchMerVeiledningVarslerToSend(): List { - val gjenstaendeSykedagerLimit = 91 - val nyttVarselLimit = 106 - val maxDateLimit = 14 - val queryStatement = """SELECT ID, FNR, UTBETALT_TOM, FORELOPIG_BEREGNET_SLUTT, GJENSTAENDE_SYKEDAGER, OPPRETTET - FROM UTBETALINGER AS UTBETALINGER1 - WHERE ID = - (SELECT UTBETALINGER2.ID - FROM UTBETALINGER AS UTBETALINGER2 - WHERE UTBETALINGER1.FNR = UTBETALINGER2.FNR - ORDER BY OPPRETTET DESC - LIMIT 1) - AND GJENSTAENDE_SYKEDAGER < $gjenstaendeSykedagerLimit - AND FORELOPIG_BEREGNET_SLUTT >= current_date + INTERVAL '$maxDateLimit' DAY - AND FNR NOT IN - (SELECT FNR - FROM UTSENDT_VARSEL - WHERE TYPE = 'SM_MER_VEILEDNING' - AND UTSENDT_TIDSPUNKT > NOW() - INTERVAL '$nyttVarselLimit' DAY) - """ - .trimIndent() - - return connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.executeQuery().toList { toPUtbetaling() } - } - } -} - -fun DatabaseInterface.fetchMaksDatoByFnr(fnr: String): PMaksDato? { - val queryStatement = """SELECT * - FROM UTBETALINGER AS UTBETALINGER1 - WHERE ID = - (SELECT UTBETALINGER2.ID - FROM UTBETALINGER AS UTBETALINGER2 - WHERE UTBETALINGER1.FNR = UTBETALINGER2.FNR - ORDER BY OPPRETTET DESC - LIMIT 1) - AND FNR = ? - """ - .trimIndent() - - val list = connection.use { connection -> - connection.prepareStatement(queryStatement).use { - it.setString(1, fnr) - it.executeQuery().toList { toPMaksDato() } - } - } - - return if (list.isNotEmpty()) { - list.first() - } else null -} diff --git a/src/main/kotlin/no/nav/syfo/db/domain/PMaksDato.kt b/src/main/kotlin/no/nav/syfo/db/domain/PMaksDato.kt deleted file mode 100644 index 32f0260f9..000000000 --- a/src/main/kotlin/no/nav/syfo/db/domain/PMaksDato.kt +++ /dev/null @@ -1,13 +0,0 @@ -package no.nav.syfo.db.domain - -import java.time.LocalDate -import java.time.LocalDateTime - -data class PMaksDato( - val id: String, - val fnr: String, - val forelopig_beregnet_slutt: LocalDate, - val utbetalt_tom: LocalDate, - val gjenstaende_sykedager: String, - val opprettet: LocalDateTime, -) diff --git a/src/main/kotlin/no/nav/syfo/db/domain/PPlanlagtVarsel.kt b/src/main/kotlin/no/nav/syfo/db/domain/PPlanlagtVarsel.kt deleted file mode 100644 index ca9c9333b..000000000 --- a/src/main/kotlin/no/nav/syfo/db/domain/PPlanlagtVarsel.kt +++ /dev/null @@ -1,15 +0,0 @@ -package no.nav.syfo.db.domain - -import java.time.LocalDate -import java.time.LocalDateTime - -data class PPlanlagtVarsel( - val uuid: String, - val fnr: String, - val orgnummer: String?, - val aktorId: String?, - val type: String, - val utsendingsdato: LocalDate, - val opprettet: LocalDateTime, - val sistEndret: LocalDateTime -) diff --git a/src/main/kotlin/no/nav/syfo/db/domain/PUtbetaling.kt b/src/main/kotlin/no/nav/syfo/db/domain/PUtbetaling.kt deleted file mode 100644 index 3e89b9411..000000000 --- a/src/main/kotlin/no/nav/syfo/db/domain/PUtbetaling.kt +++ /dev/null @@ -1,14 +0,0 @@ -package no.nav.syfo.db.domain - -import java.time.LocalDate -import java.time.LocalDateTime -import java.util.UUID - -data class PUtbetaling( - val id: UUID, - val fnr: String, - val utbetaltTom: LocalDate, - val forelopigBeregnetSlutt: LocalDate, - val gjenstaendeSykedager: Int, - val opprettet: LocalDateTime, -) diff --git a/src/main/kotlin/no/nav/syfo/kafka/common/KafkaCommon.kt b/src/main/kotlin/no/nav/syfo/kafka/common/KafkaCommon.kt index bc5131799..c99e8a4e8 100644 --- a/src/main/kotlin/no/nav/syfo/kafka/common/KafkaCommon.kt +++ b/src/main/kotlin/no/nav/syfo/kafka/common/KafkaCommon.kt @@ -31,8 +31,6 @@ import java.util.* const val topicDineSykmeldteHendelse = "teamsykmelding.dinesykmeldte-hendelser-v2" const val topicVarselBus = "team-esyfo.varselbus" -const val topicSykepengedagerInfotrygd = "aap.sykepengedager.infotrygd.v1" -const val topicUtbetaling = "tbd.utbetaling" const val topicDittSykefravaerMelding = "flex.ditt-sykefravaer-melding" const val topicMinSideMicrofrontend = "min-side.aapen-microfrontend-v1" const val topicTestdataReset = "teamsykefravr.testdata-reset" diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/GjenstaendeSykepengedager.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/GjenstaendeSykepengedager.kt deleted file mode 100644 index 372cb4b05..000000000 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/GjenstaendeSykepengedager.kt +++ /dev/null @@ -1,17 +0,0 @@ -package no.nav.syfo.kafka.consumers.infotrygd - -import java.time.DayOfWeek -import java.time.LocalDate -import no.nav.syfo.utils.isEqualOrBefore - -fun LocalDate.gjenstaendeSykepengedager(other: LocalDate): Int { - // datesUntil teller med startdato og ikke sluttdato, mens vi ikke vil telle med startdato, men sluttdato, derfor er det lagt til en dag på begge datoene - return if (this.isEqualOrBefore(other)) this - .plusDays(1) - .datesUntil(other.plusDays(1)) - .toList() - .count(LocalDate::erIkkeHelg) - .coerceAtLeast(0) else 0 -} - -private fun LocalDate.erIkkeHelg() = dayOfWeek !in arrayOf(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY) diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/InfotrygdKafkaConsumer.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/InfotrygdKafkaConsumer.kt deleted file mode 100644 index ce8a68050..000000000 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/InfotrygdKafkaConsumer.kt +++ /dev/null @@ -1,81 +0,0 @@ -package no.nav.syfo.kafka.consumers.infotrygd - -import com.fasterxml.jackson.module.kotlin.readValue -import no.nav.syfo.ApplicationState -import no.nav.syfo.Environment -import no.nav.syfo.kafka.common.* -import no.nav.syfo.kafka.consumers.infotrygd.domain.InfotrygdSource -import no.nav.syfo.kafka.consumers.infotrygd.domain.KInfotrygdSykepengedager -import no.nav.syfo.service.SykepengerMaxDateService -import no.nav.syfo.utils.parseDate -import org.apache.kafka.clients.CommonClientConfigs -import org.apache.kafka.clients.consumer.KafkaConsumer -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import java.io.IOException -import java.util.* - -class InfotrygdKafkaConsumer( - val env: Environment, - private val sykepengerMaxDateService: SykepengerMaxDateService -) : KafkaListener { - private val log: Logger = LoggerFactory.getLogger("no.nav.syfo.kafka.consumers.infotrygd.InfotrygdKafkaConsumer") - private val kafkaListener: KafkaConsumer - private val objectMapper = createObjectMapper() - - init { - val kafkaConfig = infotrygdConsumerProperties(env) - kafkaListener = KafkaConsumer(kafkaConfig) - kafkaListener.subscribe(listOf(topicSykepengedagerInfotrygd)) - } - - override suspend fun listen(applicationState: ApplicationState) { - log.info("Started listening to topic $topicSykepengedagerInfotrygd") - while (applicationState.running) { - kafkaListener.poll(pollDurationInMillis).forEach { - log.info("Received record from topic $topicSykepengedagerInfotrygd. Opprettet ${it.timestamp()}") - try { - val kInfotrygdSykepengedager: KInfotrygdSykepengedager = objectMapper.readValue(it.value()) - log.info("[INFOTRYGD KAFKA] Mapped record record from topic $topicSykepengedagerInfotrygd}") - val fnr = kInfotrygdSykepengedager.after.F_NR - val sykepengerMaxDate = parseDate(kInfotrygdSykepengedager.after.MAX_DATO) - log.info("[INFOTRYGD KAFKA] MAX_DATO from record record from topic $topicSykepengedagerInfotrygd is $sykepengerMaxDate} ") - val utbetaltTom = kInfotrygdSykepengedager.after.UTBET_TOM - log.info("[INFOTRYGD KAFKA] UTBET_TOM from record from topic $topicSykepengedagerInfotrygd is $utbetaltTom} ") - if (utbetaltTom != null) { - log.info("[INFOTRYGD KAFKA] UTBET_TOM from record from topic $topicSykepengedagerInfotrygd is not null} ") - val utbetaltTomDate = parseDate(utbetaltTom) - val gjenstaendeSykepengedager = utbetaltTomDate.gjenstaendeSykepengedager(sykepengerMaxDate) - log.info("[INFOTRYGD KAFKA] gjenstaendeSykepengedager from record from topic $topicSykepengedagerInfotrygd is $gjenstaendeSykepengedager} ") - sykepengerMaxDateService.processInfotrygdEvent( - fnr, - sykepengerMaxDate, - utbetaltTomDate, - gjenstaendeSykepengedager, - InfotrygdSource.AAP_KAFKA_TOPIC - ) - } - } catch (e: IOException) { - log.error( - "Error in [$topicSykepengedagerInfotrygd]-listener: Could not parse message | ${e.message}", - e - ) - } catch (e: Exception) { - log.error( - "Exception in [$topicSykepengedagerInfotrygd]-listener: ${e.message}", - e - ) - } - kafkaListener.commitSync() - } - } - } - - fun infotrygdConsumerProperties(env: Environment): Properties { - val commonConsumerProperties = consumerProperties(env) - return commonConsumerProperties.apply { - remove(CommonClientConfigs.GROUP_ID_CONFIG) - put(CommonClientConfigs.GROUP_ID_CONFIG, "esyfovarsel-group-infotrygd-01") - } - } -} diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/domain/InfotrygdSource.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/domain/InfotrygdSource.kt deleted file mode 100644 index 48105d5ce..000000000 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/domain/InfotrygdSource.kt +++ /dev/null @@ -1,6 +0,0 @@ -package no.nav.syfo.kafka.consumers.infotrygd.domain - -enum class InfotrygdSource { - AAP_KAFKA_TOPIC, - MANUAL -} diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/domain/KInfotrygdSykepengedager.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/domain/KInfotrygdSykepengedager.kt deleted file mode 100644 index a80d15f41..000000000 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/infotrygd/domain/KInfotrygdSykepengedager.kt +++ /dev/null @@ -1,18 +0,0 @@ -package no.nav.syfo.kafka.consumers.infotrygd.domain - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties -import com.fasterxml.jackson.annotation.JsonProperty - -@JsonIgnoreProperties(ignoreUnknown = true) -data class KInfotrygdSykepengedager( - val after: After, -) { - data class After( - @JsonProperty("MAX_DATO") - val MAX_DATO: String, - @JsonProperty("UTBET_TOM") - val UTBET_TOM: String? = null, - @JsonProperty("F_NR") - val F_NR: String, - ) -} diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/testdata/reset/TestdataResetConsumer.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/testdata/reset/TestdataResetConsumer.kt index c4f27de6e..2656d7a13 100644 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/testdata/reset/TestdataResetConsumer.kt +++ b/src/main/kotlin/no/nav/syfo/kafka/consumers/testdata/reset/TestdataResetConsumer.kt @@ -15,7 +15,7 @@ class TestdataResetConsumer( val env: Environment, private val testdataResetService: TestdataResetService ) : KafkaListener { - private val log: Logger = LoggerFactory.getLogger("no.nav.syfo.kafka.consumers.infotrygd.InfotrygdKafkaConsumer") + private val log: Logger = LoggerFactory.getLogger(TestdataResetConsumer::class.java) private val kafkaListener: KafkaConsumer init { diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/utbetaling/UtbetalingKafkaConsumer.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/utbetaling/UtbetalingKafkaConsumer.kt deleted file mode 100644 index 02610b17c..000000000 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/utbetaling/UtbetalingKafkaConsumer.kt +++ /dev/null @@ -1,64 +0,0 @@ -package no.nav.syfo.kafka.consumers.utbetaling - -import com.fasterxml.jackson.module.kotlin.readValue -import no.nav.syfo.ApplicationState -import no.nav.syfo.Environment -import no.nav.syfo.kafka.common.* -import no.nav.syfo.kafka.consumers.utbetaling.domain.UTBETALING_UTBETALT -import no.nav.syfo.kafka.consumers.utbetaling.domain.UTBETALING_UTEN_UTBETALING -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis -import no.nav.syfo.service.SykepengerMaxDateService -import org.apache.kafka.clients.CommonClientConfigs.GROUP_ID_CONFIG -import org.apache.kafka.clients.consumer.ConsumerRecord -import org.apache.kafka.clients.consumer.KafkaConsumer -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import java.io.IOException -import java.util.* - -class UtbetalingKafkaConsumer( - val env: Environment, - private val sykepengerMaxDateService: SykepengerMaxDateService, -) : KafkaListener { - private val log: Logger = LoggerFactory.getLogger(UtbetalingKafkaConsumer::class.java) - private val kafkaListener: KafkaConsumer - private val objectMapper = createObjectMapper() - - init { - val kafkaConfig = utbetalingSpleisConsumerProperties(env) - kafkaListener = KafkaConsumer(kafkaConfig) - kafkaListener.subscribe(listOf(topicUtbetaling)) - } - - override suspend fun listen(applicationState: ApplicationState) { - log.info("Started listening to topic $topicUtbetaling") - while (applicationState.running) { - kafkaListener.poll(pollDurationInMillis).forEach { - log.info("Received record from topic $topicUtbetaling") - processRecord(it) - kafkaListener.commitSync() - } - } - } - - private suspend fun processRecord(record: ConsumerRecord) { - try { - val utbetaling: UtbetalingSpleis = objectMapper.readValue(record.value()) - if (utbetaling.event == UTBETALING_UTBETALT || utbetaling.event == UTBETALING_UTEN_UTBETALING) { - sykepengerMaxDateService.processUtbetalingSpleisEvent(utbetaling) - } - } catch (e: IOException) { - log.error("Error in [$topicUtbetaling]-listener: Could not parse message. Check topic Schema") - } catch (e: Exception) { - log.error("Exception in [$topicUtbetaling]-listener: $e", e) - } - } - - private fun utbetalingSpleisConsumerProperties(env: Environment): Properties { - val commonConsumerProperties = consumerProperties(env) - return commonConsumerProperties.apply { - remove(GROUP_ID_CONFIG) - put(GROUP_ID_CONFIG, "esyfovarsel-group-utbetaling-spleis-01") - } - } -} diff --git a/src/main/kotlin/no/nav/syfo/kafka/consumers/utbetaling/domain/UtbetalingSpleis.kt b/src/main/kotlin/no/nav/syfo/kafka/consumers/utbetaling/domain/UtbetalingSpleis.kt deleted file mode 100644 index 8c2cb593c..000000000 --- a/src/main/kotlin/no/nav/syfo/kafka/consumers/utbetaling/domain/UtbetalingSpleis.kt +++ /dev/null @@ -1,22 +0,0 @@ -package no.nav.syfo.kafka.consumers.utbetaling.domain - -import java.time.LocalDate - -data class UtbetalingSpleis( - val fødselsnummer: String, - val organisasjonsnummer: String? = null, - val event: String, - val type: String? = null, - val foreløpigBeregnetSluttPåSykepenger: LocalDate? = null, - val forbrukteSykedager: Int? = null, - val gjenståendeSykedager: Int? = null, - val stønadsdager: Int? = null, - val antallVedtak: Int? = null, - val fom: LocalDate, - val tom: LocalDate, - val utbetalingId: String, - val korrelasjonsId: String, -) - -const val UTBETALING_UTBETALT = "utbetaling_utbetalt" -const val UTBETALING_UTEN_UTBETALING = "utbetaling_uten_utbetaling" diff --git a/src/main/kotlin/no/nav/syfo/service/MerVeiledningVarselFinder.kt b/src/main/kotlin/no/nav/syfo/service/MerVeiledningVarselFinder.kt deleted file mode 100644 index 0c71e2496..000000000 --- a/src/main/kotlin/no/nav/syfo/service/MerVeiledningVarselFinder.kt +++ /dev/null @@ -1,61 +0,0 @@ -package no.nav.syfo.service - -import no.nav.syfo.consumer.pdl.PdlConsumer -import no.nav.syfo.db.DatabaseInterface -import no.nav.syfo.db.domain.PPlanlagtVarsel -import no.nav.syfo.db.domain.VarselType -import no.nav.syfo.db.fetchFodselsdatoByFnr -import no.nav.syfo.db.fetchMerVeiledningVarslerToSend -import no.nav.syfo.utils.isAlderMindreEnnGittAr -import org.slf4j.LoggerFactory -import java.time.LocalDate -import java.time.LocalDateTime - -class MerVeiledningVarselFinder( - private val databaseAccess: DatabaseInterface, - private val sykmeldingService: SykmeldingService, - private val pdlConsumer: PdlConsumer, -) { - private val log = LoggerFactory.getLogger("no.nav.syfo.service.MerVeiledningVarselFinder") - - suspend fun findMerVeiledningVarslerToSendToday(): List { - log.info("[MerVeiledningVarselFinder] Henter kandidater for Mer veiledning-varsler") - val alleMerVeiledningVarsler = databaseAccess.fetchMerVeiledningVarslerToSend() - - log.info("[MerVeiledningVarselFinder] Slår opp sykmeldinger") - val merVeiledningVarslerSomHarSykmelding = alleMerVeiledningVarsler - .filter { sykmeldingService.isPersonSykmeldtPaDato(LocalDate.now(), it.fnr) } - - log.info("[MerVeiledningVarselFinder] sjekker fodselsdato") - val merVeiledningVarslerSomSkalSendesIDag = merVeiledningVarslerSomHarSykmelding - .filter { isBrukerYngreEnn67Ar(it.fnr) } - - log.info("[MerVeiledningVarselFinder] Antall MER_VEILEDNING varsler fra Spleis/Infotrygd: ${merVeiledningVarslerSomSkalSendesIDag.size}") - - return merVeiledningVarslerSomSkalSendesIDag.map { - PPlanlagtVarsel( - uuid = it.id.toString(), - fnr = it.fnr, - orgnummer = null, - aktorId = null, - type = VarselType.MER_VEILEDNING.name, - utsendingsdato = LocalDate.now(), - sistEndret = LocalDateTime.now(), - opprettet = LocalDateTime.now(), - ) - } - } - - private suspend fun isBrukerYngreEnn67Ar(fnr: String): Boolean { - val storedBirthdateList = databaseAccess.fetchFodselsdatoByFnr(fnr) - val storedBirthdate = if (storedBirthdateList.isNotEmpty()) storedBirthdateList.first() else null - - return if (storedBirthdate.isNullOrEmpty()) { - log.info("[MerVeiledningVarselFinder] Mangler lagret fodselsdato, sjekker PDL pa nytt") - pdlConsumer.isBrukerYngreEnnGittMaxAlder(fnr, 67) - } else { - log.info("[MerVeiledningVarselFinder] Sjekker om person er under 67 ut fra lagret fodselsdato") - return isAlderMindreEnnGittAr(storedBirthdate, 67) - } - } -} diff --git a/src/main/kotlin/no/nav/syfo/service/SykepengerMaxDateService.kt b/src/main/kotlin/no/nav/syfo/service/SykepengerMaxDateService.kt deleted file mode 100644 index 6592f1945..000000000 --- a/src/main/kotlin/no/nav/syfo/service/SykepengerMaxDateService.kt +++ /dev/null @@ -1,60 +0,0 @@ -package no.nav.syfo.service - -import no.nav.syfo.consumer.pdl.PdlConsumer -import no.nav.syfo.consumer.pdl.getFodselsdato -import no.nav.syfo.db.DatabaseInterface -import no.nav.syfo.db.domain.PMaksDato -import no.nav.syfo.db.fetchFodselsdatoByFnr -import no.nav.syfo.db.fetchMaksDatoByFnr -import no.nav.syfo.db.storeFodselsdato -import no.nav.syfo.db.storeInfotrygdUtbetaling -import no.nav.syfo.db.storeSpleisUtbetaling -import no.nav.syfo.kafka.consumers.infotrygd.domain.InfotrygdSource -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis -import org.slf4j.LoggerFactory -import java.time.LocalDate - -class SykepengerMaxDateService(private val databaseInterface: DatabaseInterface, private val pdlConsumer: PdlConsumer) { - - private val log = LoggerFactory.getLogger(SykepengerMaxDateService::class.qualifiedName) - - suspend fun processUtbetalingSpleisEvent(utbetaling: UtbetalingSpleis) { - val fnr = utbetaling.fødselsnummer - processFodselsdato(fnr) - databaseInterface.storeSpleisUtbetaling(utbetaling) - } - - fun getSykepengerMaxDate(fnr: String): PMaksDato? { - return databaseInterface.fetchMaksDatoByFnr(fnr) - } - - suspend fun processInfotrygdEvent( - fnr: String, - sykepengerMaxDate: LocalDate, - utbetaltTilDate: LocalDate, - gjenstaendeSykepengedager: Int, - source: InfotrygdSource - ) { - processFodselsdato(fnr) - log.info("[INFOTRYGD KAFKA] Processed fodselsdato. Going to storeInfotrygdUtbetaling with max date: " + - "${sykepengerMaxDate.toString()}, utbetaltTil: ${utbetaltTilDate.toString()}," + - " gjenstaendeSykepengedager: ${gjenstaendeSykepengedager}") - - databaseInterface.storeInfotrygdUtbetaling( - fnr, - sykepengerMaxDate, - utbetaltTilDate, - gjenstaendeSykepengedager, - source - ) - } - - private suspend fun processFodselsdato(fnr: String) { - val lagretFodselsdato = databaseInterface.fetchFodselsdatoByFnr(fnr) - if (lagretFodselsdato.isEmpty()) { - log.info("Mangler lagret fødselsdato, henter fra PDL") - val fodselsdato = pdlConsumer.hentPerson(fnr)?.getFodselsdato() - databaseInterface.storeFodselsdato(fnr, fodselsdato) - } - } -} diff --git a/src/main/kotlin/no/nav/syfo/service/TestdataResetService.kt b/src/main/kotlin/no/nav/syfo/service/TestdataResetService.kt index 1872e83df..1390836b7 100644 --- a/src/main/kotlin/no/nav/syfo/service/TestdataResetService.kt +++ b/src/main/kotlin/no/nav/syfo/service/TestdataResetService.kt @@ -2,12 +2,8 @@ package no.nav.syfo.service import no.nav.syfo.db.DatabaseInterface import no.nav.syfo.db.deleteMikrofrontendSynlighetByFnr -import no.nav.syfo.db.deletePlanlagtVarselByVarselId -import no.nav.syfo.db.deleteUtbetalingInfotrygdByFnr -import no.nav.syfo.db.deleteUtbetalingSpleisByFnr import no.nav.syfo.db.deleteUtsendtVarselByFnr import no.nav.syfo.db.deleteUtsendtVarselFeiletByFnr -import no.nav.syfo.db.fetchPlanlagtVarselByFnr import no.nav.syfo.domain.PersonIdent import no.nav.syfo.service.microfrontend.MikrofrontendService import org.slf4j.Logger @@ -25,7 +21,7 @@ class TestdataResetService( "Nullstiller testdata for arbeidstaker ${fnr.value}. Ferdigstiller varsler " + "som er sendt til Min side - arbeidsgiver, Dine sykmeldte, Min side (personbruker), " + "Ditt sykefravær. Fjerner mikrofrontend på Min side. " + - "Sletter planlagte og utsendte varsler, feilede varsler og utbetalinger." + "Sletter planlagte og utsendte varsler, feilede varsler." ) // Ferdigstille varsler @@ -34,21 +30,11 @@ class TestdataResetService( // Slette utsendte varsler database.deleteUtsendtVarselByFnr(fnr) - // Slette planlagte varsler - val planlagteVarsler = database.fetchPlanlagtVarselByFnr(fnr.value) - planlagteVarsler.forEach { database.deletePlanlagtVarselByVarselId(it.uuid) } - // Slette/skjule mikrofrontend mikrofrontendService.closeAllMikrofrontendForUser(fnr) database.deleteMikrofrontendSynlighetByFnr(fnr) // Slette utsendt varsel feilet database.deleteUtsendtVarselFeiletByFnr(fnr) - - // Slette utbetalinger fra Spleis - database.deleteUtbetalingSpleisByFnr(fnr) - - // Slette utbetalinger fra infotrygd - database.deleteUtbetalingInfotrygdByFnr(fnr) } } diff --git a/src/main/resources/db/migration/V35__Drop_utbetaling_spleis_and_ifotrygd_tables.sql b/src/main/resources/db/migration/V35__Drop_utbetaling_spleis_and_ifotrygd_tables.sql new file mode 100644 index 000000000..452f49d05 --- /dev/null +++ b/src/main/resources/db/migration/V35__Drop_utbetaling_spleis_and_ifotrygd_tables.sql @@ -0,0 +1,3 @@ +drop view UTBETALINGER; +DROP TABLE IF EXISTS UTBETALING_INFOTRYGD; +DROP TABLE IF EXISTS UTBETALING_SPLEIS; diff --git a/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt deleted file mode 100644 index 15fa2ada2..000000000 --- a/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt +++ /dev/null @@ -1,211 +0,0 @@ -package no.nav.syfo.db - - -import io.kotest.core.spec.style.DescribeSpec -import no.nav.syfo.db.domain.PPlanlagtVarsel -import no.nav.syfo.db.domain.PlanlagtVarsel -import no.nav.syfo.db.domain.VarselType -import no.nav.syfo.testutil.EmbeddedDatabase -import no.nav.syfo.testutil.mocks.orgnummer -import org.amshove.kluent.should -import org.amshove.kluent.shouldBeEqualTo -import org.amshove.kluent.shouldNotBe -import java.time.LocalDate - - -class PlanlagtVarselDAOSpek : DescribeSpec({ - describe("PlanlagtVarselDAOSpek") { - - val embeddedDatabase = EmbeddedDatabase() - - beforeTest { - embeddedDatabase.dropData() - } - - it("Store and fetch PlanlagtVarsel") { - val planlagtVarselToStore1 = PlanlagtVarsel( - arbeidstakerFnr1, - arbeidstakerAktorId1, - orgnummer, - setOf("1", "2"), - VarselType.MER_VEILEDNING - ) - val planlagtVarselToStore2 = PlanlagtVarsel( - arbeidstakerFnr2, - arbeidstakerAktorId2, - orgnummer, - setOf("3"), - VarselType.MER_VEILEDNING - ) - val planlagtVarselToStore3 = PlanlagtVarsel( - arbeidstakerFnr2, - arbeidstakerAktorId2, - orgnummer, - setOf("4"), - VarselType.MER_VEILEDNING - ) - - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore1) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore2) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore3) - - val planlagtVarselFetchedList1 = embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1) - val planlagtVarselFetchedList2 = embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr2) - - val nrOfRowsFetchedTotal = planlagtVarselFetchedList1.size + planlagtVarselFetchedList2.size - val fnr1Fetched = planlagtVarselFetchedList1.first().fnr - val fnr2Fetched = planlagtVarselFetchedList2.first().fnr - - nrOfRowsFetchedTotal shouldBeEqualTo 3 - arbeidstakerFnr1 shouldBeEqualTo fnr1Fetched - arbeidstakerFnr2 shouldBeEqualTo fnr2Fetched - - embeddedDatabase.fetchAllSykmeldingIdsAndCount() shouldBeEqualTo 4 - } - - it("Delete PlanlagtVarsel by varsel uuid") { - val planlagtVarselToStore1 = PlanlagtVarsel( - arbeidstakerFnr1, - arbeidstakerAktorId1, - orgnummer, - setOf("1", "2"), - VarselType.MER_VEILEDNING - ) - val planlagtVarselToStore2 = PlanlagtVarsel( - arbeidstakerFnr1, - arbeidstakerAktorId1, - orgnummer, - setOf("3"), - VarselType.MER_VEILEDNING - ) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore1) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore2) - - //Før delete - val planlagtVarselFetchedList1 = embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1) - - val planlagtVarselUuid = - planlagtVarselFetchedList1.find { it.type == VarselType.MER_VEILEDNING.name }!!.uuid - - - planlagtVarselFetchedList1.filter { it.uuid == planlagtVarselUuid }.size shouldBeEqualTo 1 - - embeddedDatabase.fetchAllSykmeldingIdsAndCount() shouldBeEqualTo 3 - embeddedDatabase.fetchSykmeldingerIdByPlanlagtVarselsUUID(planlagtVarselUuid).size shouldNotBe 0 - - //Delete - embeddedDatabase.deletePlanlagtVarselByVarselId(planlagtVarselUuid) - - //Etter delete - val planlagtVarselFetchedList1EtterDelete = embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1) - planlagtVarselFetchedList1EtterDelete.filter { it.uuid == planlagtVarselUuid }.size shouldBeEqualTo 0 - - embeddedDatabase.fetchAllSykmeldingIdsAndCount() shouldBeEqualTo 1 - embeddedDatabase.fetchSykmeldingerIdByPlanlagtVarselsUUID(planlagtVarselUuid).size shouldBeEqualTo 0 - } - - it("Delete PlanlagtVarsel by sykmelding ids") { - val planlagtVarselToStore1 = PlanlagtVarsel( - arbeidstakerFnr1, - arbeidstakerAktorId1, - orgnummer, - setOf("1", "2"), - VarselType.MER_VEILEDNING - ) - val planlagtVarselToStore2 = PlanlagtVarsel( - arbeidstakerFnr1, - arbeidstakerAktorId1, - orgnummer, - setOf("3"), - VarselType.MER_VEILEDNING - ) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore1) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore2) - - //Før delete - val planlagtVarselFetchedList1 = embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1) - - val merVeiledningPlanlagtVarselUuid = - planlagtVarselFetchedList1.find { it.type == VarselType.MER_VEILEDNING.name }!!.uuid - - - planlagtVarselFetchedList1.filter { it.uuid == merVeiledningPlanlagtVarselUuid }.size shouldBeEqualTo 1 - - embeddedDatabase.fetchAllSykmeldingIdsAndCount() shouldBeEqualTo 3 - embeddedDatabase.fetchSykmeldingerIdByPlanlagtVarselsUUID(merVeiledningPlanlagtVarselUuid).size shouldNotBe 0 - - //Delete - embeddedDatabase.deletePlanlagtVarselBySykmeldingerId(setOf("1", "2"), VarselType.MER_VEILEDNING) - - //Etter delete - val planlagtVarselFetchedList1EtterDelete = embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1) - planlagtVarselFetchedList1EtterDelete.filter { it.uuid == merVeiledningPlanlagtVarselUuid }.size shouldBeEqualTo 0 - - embeddedDatabase.fetchAllSykmeldingIdsAndCount() shouldBeEqualTo 1 - embeddedDatabase.fetchSykmeldingerIdByPlanlagtVarselsUUID(merVeiledningPlanlagtVarselUuid).size shouldBeEqualTo 0 - } - - it("Finn PlanlagtVarsel som skal sendes") { - val planlagtVarselToStore1 = PlanlagtVarsel( - arbeidstakerFnr1, - arbeidstakerAktorId1, - orgnummer, - setOf("1", "2"), - VarselType.MER_VEILEDNING, - LocalDate.now() - ) - val planlagtVarselToStore2 = PlanlagtVarsel( - arbeidstakerFnr2, - arbeidstakerAktorId2, - orgnummer, - setOf("3"), - VarselType.MER_VEILEDNING, - LocalDate.now().plusDays(1) - ) - val planlagtVarselToStore3 = PlanlagtVarsel( - arbeidstakerFnr2, - arbeidstakerAktorId2, - orgnummer, - setOf("4"), - VarselType.MER_VEILEDNING, - LocalDate.now().minusDays(1) - ) - - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore1) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore2) - embeddedDatabase.storePlanlagtVarsel(planlagtVarselToStore3) - - val varslerSomSkalSendes = embeddedDatabase.fetchPlanlagtVarselByUtsendingsdato(LocalDate.now()) - - varslerSomSkalSendes.skalBareHaVarslerMedUtsendingsdatoPa(LocalDate.now()) - varslerSomSkalSendes.skalInneholdeVarsel(planlagtVarselToStore1) - varslerSomSkalSendes.skalIkkeInneholdeVarsel(planlagtVarselToStore2) - varslerSomSkalSendes.skalIkkeInneholdeVarsel(planlagtVarselToStore3) - } - } -}) - -private fun Collection.skalBareHaVarslerMedUtsendingsdatoPa(dato: LocalDate) = - this.should("Varsel skal ha utsendingsdato nøyaktig på $dato. Varsel $this") { - all { it.utsendingsdato.isEqual(dato) } - } - -private fun Collection.skalInneholdeVarsel(expectedVarsel: PlanlagtVarsel) = - this.should("$this skal inneholde varsel med fnr[${expectedVarsel.fnr}], aktorId[${expectedVarsel.aktorId}], utsendingsdato[${expectedVarsel.utsendingsdato}], type[${expectedVarsel.type}]") { - any { - it.fnr == expectedVarsel.fnr && - it.aktorId == expectedVarsel.aktorId && - it.utsendingsdato == expectedVarsel.utsendingsdato && - it.type == expectedVarsel.type.name - } - } - -private fun Collection.skalIkkeInneholdeVarsel(expectedVarsel: PlanlagtVarsel) = - this.should("$this skal ikke inneholde varsel med fnr[${expectedVarsel.fnr}], aktorId[${expectedVarsel.aktorId}], utsendingsdato[${expectedVarsel.utsendingsdato}], type[${expectedVarsel.type}]") { - !any { - it.fnr == expectedVarsel.fnr && - it.aktorId == expectedVarsel.aktorId && - it.utsendingsdato == expectedVarsel.utsendingsdato && - it.type == expectedVarsel.type.name - } - } diff --git a/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt deleted file mode 100644 index 1da8792e2..000000000 --- a/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt +++ /dev/null @@ -1,200 +0,0 @@ -package no.nav.syfo.db - -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.shouldBe -import no.nav.syfo.db.domain.PUtbetaling -import no.nav.syfo.kafka.consumers.infotrygd.domain.InfotrygdSource.AAP_KAFKA_TOPIC -import no.nav.syfo.kafka.consumers.utbetaling.domain.UTBETALING_UTBETALT -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis -import no.nav.syfo.testutil.EmbeddedDatabase -import org.amshove.kluent.should -import org.amshove.kluent.shouldBeEmpty -import org.amshove.kluent.shouldHaveSingleItem -import org.amshove.kluent.shouldMatchAtLeastOneOf -import java.time.LocalDate -import java.time.LocalDate.now -import java.time.LocalDateTime -import java.util.* - -class UtbetalingerDAOSpek : DescribeSpec({ - describe("Snart slutt på sykepenger varsel") { - val embeddedDatabase = EmbeddedDatabase() - - beforeTest { - embeddedDatabase.dropData() - } - - it("Should include utbetaling with max date 14 days in the future, and gjenstående sykedager < 91") { - val spleisUtbetaling = - spleisUtbetaling(forelopigBeregnetSluttPaSykepenger = now().plusDays(14), gjenstaendeSykedager = 90) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling) - - val merVeiledningVarslerToSend = embeddedDatabase.fetchMerVeiledningVarslerToSend() - merVeiledningVarslerToSend.shouldHaveSingleItem() - merVeiledningVarslerToSend.skalInneholde(spleisUtbetaling) - } - - it("Should not include utbetaling with max date before 14 days in the future") { - val spleisUtbetaling1 = spleisUtbetaling(forelopigBeregnetSluttPaSykepenger = now().plusDays(13)) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1) - - val merVeiledningVarslerToSend = embeddedDatabase.fetchMerVeiledningVarslerToSend() - merVeiledningVarslerToSend.shouldBeEmpty() - } - - it("Should not include utbetaling with gjenstaende sykepenger >= 91") { - val spleisUtbetaling1 = spleisUtbetaling(gjenstaendeSykedager = 91) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1) - - val merVeiledningVarslerToSend = embeddedDatabase.fetchMerVeiledningVarslerToSend() - merVeiledningVarslerToSend.shouldBeEmpty() - } - - it("Should fetch utbetaling with latest opprettet dato") { - val spleisUtbetaling = spleisUtbetaling().copy(gjenståendeSykedager = 90) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling) - embeddedDatabase.storeInfotrygdUtbetaling( - arbeidstakerFnr1, - now().plusMonths(3), - now().minusMonths(1), - 88, - AAP_KAFKA_TOPIC - ) - - val merVeiledningVarslerToSend = embeddedDatabase.fetchMerVeiledningVarslerToSend() - merVeiledningVarslerToSend.shouldHaveSingleItem() - merVeiledningVarslerToSend[0].gjenstaendeSykedager shouldBe 88 - } - - it("Should fetch newest utbetaling when multiple utbetalinger with same fnr") { - val spleisUtbetaling1 = - spleisUtbetaling(forelopigBeregnetSluttPaSykepenger = now().plusDays(15), gjenstaendeSykedager = 59) - val spleisUtbetaling2 = - spleisUtbetaling(forelopigBeregnetSluttPaSykepenger = now().plusDays(16), gjenstaendeSykedager = 60) - - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1, LocalDateTime.now().minusDays(2)) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling2, LocalDateTime.now()) - - val merVeiledningVarslerToSend = embeddedDatabase.fetchMerVeiledningVarslerToSend() - merVeiledningVarslerToSend.shouldHaveSingleItem() - merVeiledningVarslerToSend[0].gjenstaendeSykedager shouldBe 60 - } - - it("Should fetch correct fnr") { - val spleisUtbetaling1 = spleisUtbetaling(fnr = arbeidstakerFnr1, gjenstaendeSykedager = 91) - val spleisUtbetaling2 = spleisUtbetaling(fnr = arbeidstakerFnr2, gjenstaendeSykedager = 90) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1, LocalDateTime.now().minusDays(2)) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling2, LocalDateTime.now()) - - val merVeiledningVarslerToSend = embeddedDatabase.fetchMerVeiledningVarslerToSend() - merVeiledningVarslerToSend.shouldHaveSingleItem() - merVeiledningVarslerToSend[0].fnr shouldBe arbeidstakerFnr2 - } - } - - describe("Maksdato") { - val embeddedDatabase = EmbeddedDatabase() - val nowPlus1Day = now().plusDays(1) - val nowPlus2Days = now().plusDays(2) - val nowMinus1Day = now().minusDays(1) - val nowMinus2Days = now().minusDays(2) - - beforeTest { - embeddedDatabase.dropData() - } - - it("Should fetch maxdate from latest utbetaling") { - val spleisUtbetaling1 = spleisUtbetaling( - fnr = arbeidstakerFnr1, - tom = nowMinus1Day, - forelopigBeregnetSluttPaSykepenger = nowPlus1Day - ) - val spleisUtbetaling2 = spleisUtbetaling( - fnr = arbeidstakerFnr1, - tom = nowMinus2Days, - forelopigBeregnetSluttPaSykepenger = nowPlus2Days - ) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1, LocalDateTime.now().minusDays(2)) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling2, LocalDateTime.now()) - - embeddedDatabase.shouldContainForelopigBeregnetSlutt(arbeidstakerFnr1, nowPlus2Days) - } - - it("Should fetch maxdate from spleis when latest utbetaling from spleis") { - embeddedDatabase.storeInfotrygdUtbetaling( - arbeidstakerFnr1, - nowPlus2Days, - nowMinus2Days, - 60, - AAP_KAFKA_TOPIC - ) - val spleisUtbetaling1 = spleisUtbetaling( - fnr = arbeidstakerFnr1, - tom = nowMinus1Day, - forelopigBeregnetSluttPaSykepenger = nowPlus1Day - ) - - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1, LocalDateTime.now().plusDays(2)) - - embeddedDatabase.shouldContainForelopigBeregnetSlutt(arbeidstakerFnr1, nowPlus1Day) - } - - it("Should fetch maxdate from infotrygd when latest utbetaling from infotrygd") { - val spleisUtbetaling1 = spleisUtbetaling( - fnr = arbeidstakerFnr1, - tom = nowMinus2Days, - forelopigBeregnetSluttPaSykepenger = nowPlus2Days - ) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1, LocalDateTime.now().minusDays(3)) - embeddedDatabase.storeInfotrygdUtbetaling(arbeidstakerFnr1, nowPlus1Day, nowMinus1Day, 60, AAP_KAFKA_TOPIC) - - embeddedDatabase.shouldContainForelopigBeregnetSlutt(arbeidstakerFnr1, nowPlus1Day) - } - - it("Should fetch maxdate for correct fnr") { - val spleisUtbetaling1 = spleisUtbetaling( - fnr = arbeidstakerFnr1, - tom = nowMinus1Day, - forelopigBeregnetSluttPaSykepenger = nowPlus1Day - ) - val spleisUtbetaling2 = spleisUtbetaling( - fnr = arbeidstakerFnr2, - tom = nowMinus2Days, - forelopigBeregnetSluttPaSykepenger = nowPlus2Days - ) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling1, LocalDateTime.now().minusDays(2)) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetaling2, LocalDateTime.now()) - - embeddedDatabase.shouldContainForelopigBeregnetSlutt(arbeidstakerFnr2, nowPlus2Days) - } - } -}) - -private fun spleisUtbetaling( - fnr: String = arbeidstakerFnr1, - tom: LocalDate = now().minusDays(1), - forelopigBeregnetSluttPaSykepenger: LocalDate = now().plusDays(14), - gjenstaendeSykedager: Int = 90 -) = UtbetalingSpleis( - fødselsnummer = fnr, - organisasjonsnummer = "234", - event = UTBETALING_UTBETALT, - type = "UTBETALING", - foreløpigBeregnetSluttPåSykepenger = forelopigBeregnetSluttPaSykepenger, - forbrukteSykedager = 89, - gjenståendeSykedager = gjenstaendeSykedager, - stønadsdager = 10, - antallVedtak = 4, - fom = now().minusDays(50), - tom = tom, - utbetalingId = UUID.randomUUID().toString(), - korrelasjonsId = UUID.randomUUID().toString(), -) - -private fun List.skalInneholde(spleisUtbetaling: UtbetalingSpleis) = - this.shouldMatchAtLeastOneOf { pUtbetaling: PUtbetaling -> pUtbetaling.fnr == spleisUtbetaling.fødselsnummer && pUtbetaling.utbetaltTom == spleisUtbetaling.tom && pUtbetaling.forelopigBeregnetSlutt == spleisUtbetaling.foreløpigBeregnetSluttPåSykepenger && pUtbetaling.gjenstaendeSykedager == spleisUtbetaling.gjenståendeSykedager } - -private fun DatabaseInterface.shouldContainForelopigBeregnetSlutt(fnr: String, forelopigBeregnetSlutt: LocalDate) = - this.should("Should contain row with requested fnr and forelopigBeregnetSlutt") { - this.fetchMaksDatoByFnr(fnr)?.forelopig_beregnet_slutt == forelopigBeregnetSlutt - } diff --git a/src/test/kotlin/no/nav/syfo/kafka/consumers/infotrygd/GjenstaendeSykepengedagerSpek.kt b/src/test/kotlin/no/nav/syfo/kafka/consumers/infotrygd/GjenstaendeSykepengedagerSpek.kt deleted file mode 100644 index 9fd4d5271..000000000 --- a/src/test/kotlin/no/nav/syfo/kafka/consumers/infotrygd/GjenstaendeSykepengedagerSpek.kt +++ /dev/null @@ -1,43 +0,0 @@ -package no.nav.syfo.kafka.consumers.infotrygd - -import io.kotest.core.spec.style.DescribeSpec -import java.time.LocalDate -import java.time.Month.DECEMBER -import java.time.Month.NOVEMBER -import java.util.Calendar.MAY -import kotlin.test.assertEquals - -class GjenstaendeSykepengedagerSpek : DescribeSpec({ - describe("GjenstaendeSykepengedagerSpek") { - - it("Should calculate only ukedager") { - val maxDate = LocalDate.of(2022, DECEMBER, 31) - val ubetTomDate = LocalDate.of(2022, NOVEMBER, 30) - assertEquals(22, ubetTomDate.gjenstaendeSykepengedager(maxDate)) - } - - it("Should not include weekend days") { - val maxDate = LocalDate.of(2022, DECEMBER, 31) //lørdag - val ubetTomDate = LocalDate.of(2022, DECEMBER, 30) - assertEquals(0, ubetTomDate.gjenstaendeSykepengedager(maxDate)) - } - - it("Should include weekday") { - val maxDate = LocalDate.of(2022, DECEMBER, 30) - val ubetTomDate = LocalDate.of(2022, DECEMBER, 29) - assertEquals(1, ubetTomDate.gjenstaendeSykepengedager(maxDate)) - } - - it("Should not include same day") { - val maxDate = LocalDate.of(2022, DECEMBER, 31) - val ubetTomDate = LocalDate.of(2022, DECEMBER, 31) - assertEquals(0, ubetTomDate.gjenstaendeSykepengedager(maxDate)) - } - - it("Should handle when other date is before this") { - val maxDate = LocalDate.of(2023, MAY, 15) - val ubetTomDate = LocalDate.of(2023, MAY, 16) - assertEquals(0, ubetTomDate.gjenstaendeSykepengedager(maxDate)) - } - } -}) diff --git a/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt b/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt deleted file mode 100644 index 697a869ba..000000000 --- a/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt +++ /dev/null @@ -1,160 +0,0 @@ -package no.nav.syfo.service - -import io.kotest.core.spec.style.DescribeSpec -import io.mockk.clearAllMocks -import io.mockk.coEvery -import io.mockk.coVerify -import io.mockk.mockk -import no.nav.syfo.consumer.pdl.PdlConsumer -import no.nav.syfo.consumer.syfosmregister.SykmeldingerConsumer -import no.nav.syfo.db.arbeidstakerFnr2 -import no.nav.syfo.db.domain.PUtsendtVarsel -import no.nav.syfo.db.storeFodselsdato -import no.nav.syfo.db.storeSpleisUtbetaling -import no.nav.syfo.db.storeUtsendtVarsel -import no.nav.syfo.kafka.consumers.utbetaling.domain.UTBETALING_UTBETALT -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis -import no.nav.syfo.kafka.consumers.varselbus.domain.HendelseType -import no.nav.syfo.planner.arbeidstakerFnr1 -import no.nav.syfo.testutil.EmbeddedDatabase -import no.nav.syfo.testutil.mocks.orgnummer -import org.amshove.kluent.shouldBeEqualTo -import java.time.LocalDate -import java.time.LocalDateTime -import java.util.* - -class MerVeiledningVarselFinderSpek : DescribeSpec({ - - val embeddedDatabase = EmbeddedDatabase() - val sykmeldingerConsumerMock: SykmeldingerConsumer = mockk(relaxed = true) - val sykmeldingServiceMockk = SykmeldingService(sykmeldingerConsumerMock) - val pdlConsumerMockk: PdlConsumer = mockk(relaxed = true) - val merVeiledningVarselFinder = - MerVeiledningVarselFinder(embeddedDatabase, sykmeldingServiceMockk, pdlConsumerMockk) - - val spleisUtbetalingWhichResultsToVarsel = UtbetalingSpleis( - fødselsnummer = arbeidstakerFnr1, - organisasjonsnummer = "234", - event = UTBETALING_UTBETALT, - type = "UTBETALING", - foreløpigBeregnetSluttPåSykepenger = LocalDate.now().plusDays(15), - forbrukteSykedager = 100, - gjenståendeSykedager = 79, - stønadsdager = 10, - antallVedtak = 4, - fom = LocalDate.now().minusDays(50), - tom = LocalDate.now().minusDays(3), - utbetalingId = UUID.randomUUID().toString(), - korrelasjonsId = UUID.randomUUID().toString(), - ) - val spleisUtbetalingWhichResultsToVarsel2 = UtbetalingSpleis( - fødselsnummer = arbeidstakerFnr2, - organisasjonsnummer = "234", - event = UTBETALING_UTBETALT, - type = "UTBETALING", - foreløpigBeregnetSluttPåSykepenger = LocalDate.now().plusDays(15), - forbrukteSykedager = 100, - gjenståendeSykedager = 79, - stønadsdager = 10, - antallVedtak = 4, - fom = LocalDate.now().minusDays(50), - tom = LocalDate.now().minusDays(3), - utbetalingId = UUID.randomUUID().toString(), - korrelasjonsId = UUID.randomUUID().toString(), - ) - - describe("MerVeiledningVarselFinderSpek") { - beforeTest { - clearAllMocks() - embeddedDatabase.dropData() - } - - it("Should send MER_VEILEDNING when it was not sent during past 3 months") { - coEvery { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(any(), any()) } returns true - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns true - embeddedDatabase.storeUtsendtVarsel(getUtsendtVarselToStore(LocalDateTime.now().minusMonths(5))) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel) - - val varslerToSendToday = merVeiledningVarselFinder.findMerVeiledningVarslerToSendToday() - - varslerToSendToday.size shouldBeEqualTo 1 - } - - it("Should not send MER_VEILEDNING when it was sent during past 3 months") { - coEvery { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(any(), any()) } returns true - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns true - embeddedDatabase.storeUtsendtVarsel(getUtsendtVarselToStore(LocalDateTime.now().minusMonths(1))) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel) - - val varslerToSendToday = merVeiledningVarselFinder.findMerVeiledningVarslerToSendToday() - - varslerToSendToday.size shouldBeEqualTo 0 - } - - it("Should not send MER_VEILEDNING when it was not sent during past 3 months, but user is not active sykmeldt") { - coEvery { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(any(), any()) } returns true - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns false - embeddedDatabase.storeUtsendtVarsel(getUtsendtVarselToStore(LocalDateTime.now().minusMonths(1))) - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel) - - val varslerToSendToday = merVeiledningVarselFinder.findMerVeiledningVarslerToSendToday() - - varslerToSendToday.size shouldBeEqualTo 0 - } - - it("Should send MER_VEILEDNING when user is under 67") { - coEvery { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(any(), any()) } returns true - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns true - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel) - - val varslerToSendToday = merVeiledningVarselFinder.findMerVeiledningVarslerToSendToday() - - varslerToSendToday.size shouldBeEqualTo 1 - } - - it("Should not send MER_VEILEDNING when user is over 67") { - coEvery { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(any(), any()) } returns false - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns true - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel) - - val varslerToSendToday = merVeiledningVarselFinder.findMerVeiledningVarslerToSendToday() - - varslerToSendToday.size shouldBeEqualTo 0 - } - - it("Should call PDL if stored birthdate is null for a given fnr") { - embeddedDatabase.storeFodselsdato(arbeidstakerFnr1, null) - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns true - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel) - - merVeiledningVarselFinder.findMerVeiledningVarslerToSendToday() - - coVerify(exactly = 1) { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(arbeidstakerFnr1, 67) } - } - - it("Should not call PDL if stored birthdate is not null") { - embeddedDatabase.storeFodselsdato(arbeidstakerFnr2, "1986-01-01") - coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr2) } returns true - embeddedDatabase.storeSpleisUtbetaling(spleisUtbetalingWhichResultsToVarsel2) - - coVerify(exactly = 0) { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(arbeidstakerFnr1, 67) } - } - } -}) - -private fun getUtsendtVarselToStore(utsendtTidspunkt: LocalDateTime): PUtsendtVarsel { - return PUtsendtVarsel( - UUID.randomUUID().toString(), - arbeidstakerFnr1, - null, - "", - orgnummer, - HendelseType.SM_MER_VEILEDNING.name, - null, - utsendtTidspunkt, - null, - null, - null, - null, - ) -} diff --git a/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt deleted file mode 100644 index 033f068d9..000000000 --- a/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt +++ /dev/null @@ -1,89 +0,0 @@ -package no.nav.syfo.service - -import io.kotest.core.spec.style.DescribeSpec -import io.mockk.coEvery -import io.mockk.mockk -import no.nav.syfo.consumer.pdl.Foedselsdato -import no.nav.syfo.consumer.pdl.HentPerson -import no.nav.syfo.consumer.pdl.HentPersonData -import no.nav.syfo.consumer.pdl.Navn -import no.nav.syfo.consumer.pdl.PdlConsumer -import no.nav.syfo.kafka.consumers.utbetaling.domain.UTBETALING_UTBETALT -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis -import no.nav.syfo.testutil.EmbeddedDatabase -import java.time.LocalDate -import java.util.* -import kotlin.test.assertEquals - -class SykepengerMaxDateServiceSpek : DescribeSpec({ - describe("SykepengerMaxDateService") { - val embeddedDatabase = EmbeddedDatabase() - val pdlConsumer = mockk(relaxed = true) - val sykepengerMaxDateService = SykepengerMaxDateService(embeddedDatabase, pdlConsumer) - coEvery { pdlConsumer.hentPerson(any()) } returns HentPersonData( - hentPerson = HentPerson( - foedselsdato = listOf(Foedselsdato(foedselsdato = "1990-01-01")), - navn = listOf( - Navn( - fornavn = "Test", - mellomnavn = null, - etternavn = "Testesen" - ) - ) - ) - ) - beforeTest { - embeddedDatabase.dropData() - } - - it("Should store spleis utbetaling") { - val utbetalingUtbetalt = UtbetalingSpleis( - fødselsnummer = "123", - organisasjonsnummer = "234", - event = UTBETALING_UTBETALT, - type = "UTBETALING", - foreløpigBeregnetSluttPåSykepenger = LocalDate.now().plusDays(100), - forbrukteSykedager = 100, - gjenståendeSykedager = 122, - stønadsdager = 10, - antallVedtak = 4, - fom = LocalDate.now().minusDays(50), - tom = LocalDate.now().minusDays(10), - utbetalingId = UUID.randomUUID().toString(), - korrelasjonsId = UUID.randomUUID().toString(), - ) - - sykepengerMaxDateService.processUtbetalingSpleisEvent(utbetalingUtbetalt) - - val storedGjenstaaendeDager = embeddedDatabase.fetchSpleisUtbetalingByFnr("123") - - assertEquals(122, storedGjenstaaendeDager.first()) - } - - it("Should ignore duplicate spleis utbetaling") { - val utbetalingUtbetalt = UtbetalingSpleis( - fødselsnummer = "123", - organisasjonsnummer = "234", - event = UTBETALING_UTBETALT, - type = "UTBETALING", - foreløpigBeregnetSluttPåSykepenger = LocalDate.now().plusDays(100), - forbrukteSykedager = 100, - gjenståendeSykedager = 122, - stønadsdager = 10, - antallVedtak = 4, - fom = LocalDate.now().minusDays(50), - tom = LocalDate.now().minusDays(10), - utbetalingId = UUID.randomUUID().toString(), - korrelasjonsId = UUID.randomUUID().toString(), - ) - - sykepengerMaxDateService.processUtbetalingSpleisEvent(utbetalingUtbetalt) - sykepengerMaxDateService.processUtbetalingSpleisEvent(utbetalingUtbetalt) - - val storedGjenstaaendeDager = embeddedDatabase.fetchSpleisUtbetalingByFnr("123") - - assertEquals(1, storedGjenstaaendeDager.size) - assertEquals(122, storedGjenstaaendeDager.first()) - } - } -}) diff --git a/src/test/kotlin/no/nav/syfo/service/TestUtil.kt b/src/test/kotlin/no/nav/syfo/service/TestUtil.kt deleted file mode 100644 index 45d781e10..000000000 --- a/src/test/kotlin/no/nav/syfo/service/TestUtil.kt +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.syfo.service - -import no.nav.syfo.db.DatabaseInterface -import no.nav.syfo.db.toList - -fun DatabaseInterface.fetchSpleisUtbetalingByFnr(fnr: String) = - connection.use { connection -> - connection.prepareStatement("""SELECT * FROM UTBETALING_SPLEIS WHERE FNR = ?""".trimIndent()).use { - it.setString(1, fnr) - it.executeQuery().toList { getInt("GJENSTAENDE_SYKEDAGER") } - } - } diff --git a/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt index 394cb3d87..f9d33445a 100644 --- a/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt @@ -4,26 +4,21 @@ import io.kotest.core.spec.style.DescribeSpec import io.mockk.coVerify import io.mockk.mockk import io.mockk.verify +import java.time.LocalDate +import java.time.LocalDateTime +import java.util.* import no.nav.syfo.db.arbeidstakerAktorId1 import no.nav.syfo.db.domain.Kanal import no.nav.syfo.db.domain.PUtsendtVarsel import no.nav.syfo.db.domain.PUtsendtVarselFeilet -import no.nav.syfo.db.domain.PlanlagtVarsel import no.nav.syfo.db.domain.VarselType -import no.nav.syfo.db.fetchInfotrygdUtbetalingByFnr import no.nav.syfo.db.fetchMikrofrontendSynlighetEntriesByFnr -import no.nav.syfo.db.fetchPlanlagtVarselByFnr import no.nav.syfo.db.fetchUtsendtVarselByFnr import no.nav.syfo.db.fetchUtsendtVarselFeiletByFnr -import no.nav.syfo.db.storeInfotrygdUtbetaling import no.nav.syfo.db.storeMikrofrontendSynlighetEntry -import no.nav.syfo.db.storePlanlagtVarsel -import no.nav.syfo.db.storeSpleisUtbetaling import no.nav.syfo.db.storeUtsendtVarsel import no.nav.syfo.db.storeUtsendtVarselFeilet import no.nav.syfo.domain.PersonIdent -import no.nav.syfo.kafka.consumers.infotrygd.domain.InfotrygdSource -import no.nav.syfo.kafka.consumers.utbetaling.domain.UtbetalingSpleis import no.nav.syfo.kafka.consumers.varselbus.domain.HendelseType import no.nav.syfo.kafka.producers.mineside_microfrontend.MikrofrontendSynlighet import no.nav.syfo.kafka.producers.mineside_microfrontend.Tjeneste @@ -31,12 +26,7 @@ import no.nav.syfo.planner.arbeidstakerFnr1 import no.nav.syfo.planner.narmesteLederFnr1 import no.nav.syfo.service.microfrontend.MikrofrontendService import no.nav.syfo.testutil.EmbeddedDatabase -import no.nav.syfo.testutil.mocks.orgnummer import org.amshove.kluent.shouldBeEqualTo -import java.time.LocalDate -import java.time.LocalDateTime -import java.util.* - class TestdataResetServiceSpek : DescribeSpec({ describe("TestdataResetServiceSpek") { @@ -44,8 +34,6 @@ class TestdataResetServiceSpek : DescribeSpec({ val mikrofrontendService: MikrofrontendService = mockk(relaxed = true) val senderFacade: SenderFacade = mockk(relaxed = true) val testdataResetService = TestdataResetService(embeddedDatabase, mikrofrontendService, senderFacade) - val planlagtVarsel = - PlanlagtVarsel(arbeidstakerFnr1, arbeidstakerAktorId1, orgnummer, setOf("1"), VarselType.MER_VEILEDNING) val utsendtVarsel = PUtsendtVarsel( @@ -63,22 +51,6 @@ class TestdataResetServiceSpek : DescribeSpec({ arbeidsgivernotifikasjonMerkelapp = null, ) - val utbetalingUtbetalt = UtbetalingSpleis( - arbeidstakerFnr1, - orgnummer, - "utbetaling", - "hei", - LocalDate.now(), - 0, - 0, - 0, - 0, - LocalDate.now(), - LocalDate.now(), - "1", - "1" - ) - val pUtsendtVarselFeilet = PUtsendtVarselFeilet( UUID.randomUUID().toString(), null, @@ -102,34 +74,19 @@ class TestdataResetServiceSpek : DescribeSpec({ } it("Reset all testdata") { - embeddedDatabase.storePlanlagtVarsel(planlagtVarsel) embeddedDatabase.storeUtsendtVarsel(utsendtVarsel) - embeddedDatabase.storeSpleisUtbetaling(utbetalingUtbetalt) - embeddedDatabase.storeInfotrygdUtbetaling( - arbeidstakerFnr1, - LocalDate.now(), - LocalDate.now(), - 0, - InfotrygdSource.MANUAL - ) embeddedDatabase.storeUtsendtVarselFeilet(pUtsendtVarselFeilet) embeddedDatabase.storeMikrofrontendSynlighetEntry(mikrofrontendSynlighet) //Verify that testdata exists - embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1).size shouldBeEqualTo 1 embeddedDatabase.fetchUtsendtVarselByFnr(arbeidstakerFnr1).size shouldBeEqualTo 1 - embeddedDatabase.fetchSpleisUtbetalingByFnr(arbeidstakerFnr1).size shouldBeEqualTo 1 - embeddedDatabase.fetchInfotrygdUtbetalingByFnr(arbeidstakerFnr1).size shouldBeEqualTo 1 embeddedDatabase.fetchUtsendtVarselFeiletByFnr(arbeidstakerFnr1).size shouldBeEqualTo 1 embeddedDatabase.fetchMikrofrontendSynlighetEntriesByFnr(arbeidstakerFnr1).size shouldBeEqualTo 1 testdataResetService.resetTestdata(PersonIdent(arbeidstakerFnr1)) //Check that testdata is deleted - embeddedDatabase.fetchPlanlagtVarselByFnr(arbeidstakerFnr1).size shouldBeEqualTo 0 embeddedDatabase.fetchUtsendtVarselByFnr(arbeidstakerFnr1).size shouldBeEqualTo 0 - embeddedDatabase.fetchSpleisUtbetalingByFnr(arbeidstakerFnr1).size shouldBeEqualTo 0 - embeddedDatabase.fetchInfotrygdUtbetalingByFnr(arbeidstakerFnr1).size shouldBeEqualTo 0 embeddedDatabase.fetchUtsendtVarselFeiletByFnr(arbeidstakerFnr1).size shouldBeEqualTo 0 embeddedDatabase.fetchMikrofrontendSynlighetEntriesByFnr(arbeidstakerFnr1).size shouldBeEqualTo 0 verify(exactly = 1) { diff --git a/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt b/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt index 61484cfb9..ff7fc79ed 100644 --- a/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt +++ b/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt @@ -33,11 +33,8 @@ class EmbeddedDatabase : DatabaseInterface { fun dropData() { val tables = listOf( - "PLANLAGT_VARSEL", "SYKMELDING_IDS", "UTSENDT_VARSEL", - "UTBETALING_INFOTRYGD", - "UTBETALING_SPLEIS", "MIKROFRONTEND_SYNLIGHET" )