Skip to content

Commit

Permalink
Omskriving til bruk av BehandlingshistorikkRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
frodeli committed Sep 16, 2024
1 parent 780c60a commit dc20faa
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 66 deletions.
7 changes: 7 additions & 0 deletions api-kontrakt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ group = "no.nav.aap.oppgave"
apply(plugin = "maven-publish")
apply(plugin = "java-library")

val jacksonVersion = "2.17.2"

dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")

}

java {
withSourcesJar()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.nav.aap.oppgave

import no.nav.aap.oppgave.verdityper.AvklaringsbehovType
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import java.util.UUID

data class AvsluttOppgaveDto(
val saksnummer: String? = null,
val behandlingRef: UUID? = null,
val journalpostId: Long? = null,
val avklaringsbehovType: AvklaringsbehovType,
val avklaringsbehovKode: AvklaringsbehovKode,
)
4 changes: 2 additions & 2 deletions api-kontrakt/src/main/kotlin/no/nav/aap/oppgave/OppgaveDto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.nav.aap.oppgave

import no.nav.aap.oppgave.verdityper.AvklaringsbehovType
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import no.nav.aap.oppgave.verdityper.OppgaveId
import no.nav.aap.oppgave.verdityper.Status
import java.time.LocalDateTime
Expand All @@ -12,7 +12,7 @@ data class OppgaveDto(
val behandlingRef: UUID? = null,
val journalpostId: Long? = null,
val behandlingOpprettet: LocalDateTime,
val avklaringsbehovType: AvklaringsbehovType,
val avklaringsbehovKode: AvklaringsbehovKode,
val status: Status = Status.OPPRETTET,
val reservertAv: String? = null,
val reservertTidspunkt: LocalDateTime? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.nav.aap.oppgave.filter

import no.nav.aap.oppgave.verdityper.AvklaringsbehovType
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode

data class FilterDto(
val id: Long,
val navn: String,
val avklaringsbehovKoder: Set<AvklaringsbehovType> = emptySet()
val avklaringsbehovKoder: Set<AvklaringsbehovKode> = emptySet()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package no.nav.aap.oppgave.opprett

import com.fasterxml.jackson.annotation.JsonIgnore
import java.time.LocalDateTime

//TODO skal ligge behandlingsflyt.api-kontrakt, fjernes når det er klart
data class BehandlingshistorikkRequest(
val personident: String,
val saksnummer: String,
val referanse: String,
val behandlingType: Behandlingstype,
val status: Behandlingstatus,
val opprettetTidspunkt: LocalDateTime,
val avklaringsbehov: List<AvklaringsbehovDto>,
) {
fun erLukket() =
(status == Behandlingstatus.AVSLUTTET) ||
avklaringsbehov.all { it.status == Avklaringsbehovstatus.AVSLUTTET }

@JsonIgnore
fun getÅpentAvklaringsbehov() = avklaringsbehov.firstOrNull {
it.status in setOf(
Avklaringsbehovstatus.OPPRETTET,
Avklaringsbehovstatus.SENDT_TILBAKE_FRA_BESLUTTER,
Avklaringsbehovstatus.SENDT_TILBAKE_FRA_KVALITETSSIKRER
)
}
}

enum class Behandlingstype {
Førstegangsbehandling,
Revurdering,
Tilbakekreving,
Klage
}

enum class Behandlingstatus {
OPPRETTET,
UTREDES,
AVSLUTTET,
PÅ_VENT
}

enum class Avklaringsbehovstatus {
OPPRETTET,
AVSLUTTET,
KVALITETSSIKRET,
SENDT_TILBAKE_FRA_KVALITETSSIKRER,
TOTRINNS_VURDERT,
SENDT_TILBAKE_FRA_BESLUTTER,
AVBRUTT
}

enum class Avklaringsbehovtype(val kode: String) {
MANUELT_SATT_PÅ_VENT("9001"),
AVKLAR_STUDENT("5001"),
AVKLAR_SYKDOM("5003"),
FASTSETT_ARBEIDSEVNE("5004"),
FRITAK_MELDEPLIKT("5005"),
AVKLAR_BISTANDSBEHOV("5006"),
VURDER_SYKEPENGEERSTATNING("5007"),
FASTSETT_BEREGNINGSTIDSPUNKT("5008"),
AVKLAR_BARN("5009"),
AVKLAR_SONINGSFORRHOLD("5010"),
AVKLAR_HELSEINSTITUSJON("5011"),
KVALITETSSIKRING("5097"),
FORESLÅ_VEDTAK("5098"),
FATTE_VEDTAK("5099");

companion object {
private val map = entries.associateBy(Avklaringsbehovtype::kode)
fun fraKode(kode: String) =
map[kode] ?: throw IllegalArgumentException("Finner ikke Avklaringsbehovtype for kode: $kode")
}
}

data class AvklaringsbehovDto(
val definisjon: Definisjon,
val status: Avklaringsbehovstatus,
val endringer: List<AvklaringsbehovhendelseEndring>
) {
fun getOpprettelsestidspunkt() = endringer.find { it.status == Avklaringsbehovstatus.OPPRETTET }?.tidsstempel
?: throw IllegalArgumentException("Avklaringsbehov mangler ")
}

data class Definisjon(
val type: String
)

data class AvklaringsbehovhendelseEndring(
val status: Avklaringsbehovstatus,
val tidsstempel: LocalDateTime,
val endretAv: String
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.aap.oppgave.verdityper

@JvmInline
value class AvklaringsbehovType(val kode: String)
value class AvklaringsbehovKode(val kode: String)
2 changes: 1 addition & 1 deletion app/src/main/kotlin/no/nav/aap/oppgave/OppgaveAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun NormalOpenAPIRoute.avsluttOppgave(dataSource: DataSource, prometheus: Promet
dto.saksnummer,
dto.behandlingRef,
dto.journalpostId,
dto.avklaringsbehovType,
dto.avklaringsbehovKode,
ident()
)
oppgaverSomSkalAvsluttes.forEach {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/kotlin/no/nav/aap/oppgave/OppgaveRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package no.nav.aap.oppgave
import no.nav.aap.komponenter.dbconnect.DBConnection
import no.nav.aap.oppgave.filter.FilterDto
import no.nav.aap.oppgave.plukk.NesteOppgaveDto
import no.nav.aap.oppgave.verdityper.AvklaringsbehovType
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import no.nav.aap.oppgave.verdityper.OppgaveId
import no.nav.aap.oppgave.verdityper.Status
import java.util.UUID
Expand Down Expand Up @@ -32,7 +32,7 @@ class OppgaveRepository(private val connection: DBConnection) {
setUUID(2, oppgaveDto.behandlingRef)
setLong(3, oppgaveDto.journalpostId)
setLocalDateTime(4, oppgaveDto.behandlingOpprettet)
setString(5, oppgaveDto.avklaringsbehovType.kode)
setString(5, oppgaveDto.avklaringsbehovKode.kode)
setString(6, oppgaveDto.status.name)
setString(7, oppgaveDto.opprettetAv)
setLocalDateTime(8, oppgaveDto.opprettetTidspunkt)
Expand Down Expand Up @@ -117,7 +117,7 @@ class OppgaveRepository(private val connection: DBConnection) {
behandlingRef = row.getUUIDOrNull("BEHANDLING_REF"),
journalpostId = row.getLongOrNull("JOURNALPOST_ID"),
behandlingOpprettet = row.getLocalDateTime("BEHANDLING_OPPRETTET"),
avklaringsbehovType = AvklaringsbehovType(row.getString("AVKLARINGSBEHOV_TYPE")),
avklaringsbehovKode = AvklaringsbehovKode(row.getString("AVKLARINGSBEHOV_TYPE")),
status = Status.valueOf(row.getString("STATUS")),
reservertAv = row.getStringOrNull("RESERVERT_AV"),
reservertTidspunkt = row.getLocalDateTimeOrNull("RESERVERT_TIDSPUNKT"),
Expand All @@ -130,7 +130,7 @@ class OppgaveRepository(private val connection: DBConnection) {
}
}

fun hentOppgaverForReferanse(saksnummer: String?, behandlingRef: UUID?, journalpostId: Long?, avklaringsbehovType: AvklaringsbehovType, ident: String): List<OppgaveId> {
fun hentOppgaverForReferanse(saksnummer: String?, behandlingRef: UUID?, journalpostId: Long?, avklaringsbehovKode: AvklaringsbehovKode, ident: String): List<OppgaveId> {
val oppgaverForReferanseQuery = """
SELECT
ID
Expand All @@ -149,7 +149,7 @@ class OppgaveRepository(private val connection: DBConnection) {
setString(1, saksnummer)
setUUID(2, behandlingRef)
setLong(3, journalpostId)
setString(4, avklaringsbehovType.kode)
setString(4, avklaringsbehovKode.kode)
setString(5, ident)
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ class OppgaveRepository(private val connection: DBConnection) {
return ""
}

private fun Set<AvklaringsbehovType>.tilStringListe(): String {
private fun Set<AvklaringsbehovKode>.tilStringListe(): String {
return map {"'${it.kode}'"}.joinToString(prefix = "(", postfix = ")", separator = ", ")
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package no.nav.aap.oppgave.filter

import no.nav.aap.komponenter.dbconnect.DBConnection
import no.nav.aap.oppgave.verdityper.AvklaringsbehovType
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode

// Forløpig mock repository
class FilterRepository(private val connection: DBConnection) {

private val filterDtoMap = mapOf(
1L to FilterDto(1L, "Alle oppgaver"),
2L to FilterDto(2L, "Oppgaver av med avklaringsbehov 1000", setOf(AvklaringsbehovType("1000"))),
2L to FilterDto(2L, "Oppgaver av med avklaringsbehov 1000", setOf(AvklaringsbehovKode("1000"))),
)

fun hentFilter(filterId: Long): FilterDto? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package no.nav.aap.oppgave.opprette

import no.nav.aap.oppgave.OppgaveDto
import no.nav.aap.oppgave.opprett.AvklaringsbehovDto
import no.nav.aap.oppgave.opprett.Avklaringsbehovstatus
import no.nav.aap.oppgave.opprett.BehandlingshistorikkRequest
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import java.time.LocalDateTime
import java.util.UUID

object BehandlingshistorikkTilOppgaveConverter {

fun lagOppgave(behandlingshistorikk: BehandlingshistorikkRequest, ident: String): OppgaveDto? {
val åpentAvklaringsbehov = behandlingshistorikk.getÅpentAvklaringsbehov()
if (åpentAvklaringsbehov == null) {
return null
}
return when (åpentAvklaringsbehov.status) {
Avklaringsbehovstatus.OPPRETTET ->
opprettNyOppgave(behandlingshistorikk, åpentAvklaringsbehov, ident)
Avklaringsbehovstatus.SENDT_TILBAKE_FRA_KVALITETSSIKRER, Avklaringsbehovstatus.SENDT_TILBAKE_FRA_BESLUTTER ->
gjenopprettOppgave(behandlingshistorikk, åpentAvklaringsbehov, ident)
else -> return null
}
}

private fun opprettNyOppgave(behandlingshistorikkRequest: BehandlingshistorikkRequest,
avklaringsbehov: AvklaringsbehovDto,
ident: String
): OppgaveDto {
return OppgaveDto(
saksnummer = behandlingshistorikkRequest.saksnummer,
behandlingRef = UUID.fromString(behandlingshistorikkRequest.referanse),
behandlingOpprettet = behandlingshistorikkRequest.opprettetTidspunkt,
avklaringsbehovKode = AvklaringsbehovKode(avklaringsbehov.definisjon.type),
opprettetAv = ident,
opprettetTidspunkt = LocalDateTime.now()
)
}

private fun gjenopprettOppgave(behandlingshistorikkRequest: BehandlingshistorikkRequest,
avklaringsbehov: AvklaringsbehovDto,
ident: String
): OppgaveDto? {
val oppgaveDto = opprettNyOppgave(behandlingshistorikkRequest, avklaringsbehov, ident)
val sistEndretAv = avklaringsbehov.sistEndretAv()
oppgaveDto.copy(reservertAv = sistEndretAv, reservertTidspunkt = LocalDateTime.now())
return oppgaveDto
}

private fun AvklaringsbehovDto.sistEndretAv(): String? {
return endringer
.sortedByDescending { it.tidsstempel }
.filter { it.status == this.status }
.map { it.endretAv }
.firstOrNull()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,29 @@ package no.nav.aap.oppgave.opprette
import com.papsign.ktor.openapigen.route.path.normal.NormalOpenAPIRoute
import com.papsign.ktor.openapigen.route.path.normal.post
import com.papsign.ktor.openapigen.route.response.respond
import com.papsign.ktor.openapigen.route.response.respondWithStatus
import com.papsign.ktor.openapigen.route.route
import io.ktor.http.HttpStatusCode
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import no.nav.aap.komponenter.dbconnect.transaction
import no.nav.aap.oppgave.OppgaveDto
import no.nav.aap.oppgave.verdityper.OppgaveId
import no.nav.aap.oppgave.OppgaveRepository
import no.nav.aap.oppgave.metriker.httpCallCounter
import no.nav.aap.oppgave.opprett.OpprettOppgaveDto
import no.nav.aap.oppgave.opprett.BehandlingshistorikkRequest
import no.nav.aap.oppgave.server.authenticate.ident
import java.time.LocalDateTime
import javax.sql.DataSource

fun NormalOpenAPIRoute.opprettOppgaveApi(dataSource: DataSource, prometheus: PrometheusMeterRegistry) =

route("/opprett-oppgave").post<Unit, OppgaveId, OpprettOppgaveDto> { _, request ->
route("/opprett-oppgave").post<Unit, OppgaveId, BehandlingshistorikkRequest> { _, request ->
prometheus.httpCallCounter("/opprett-oppgave").increment()
val oppgaveId = dataSource.transaction { connection ->
val oppgaveDto = OppgaveDto(
saksnummer = request.saksnummer,
behandlingRef = request.behandlingRef,
behandlingOpprettet = request.behandlingOpprettet,
avklaringsbehovType = request.avklaringsbehovType,
opprettetAv = ident(),
opprettetTidspunkt = LocalDateTime.now()
)
OppgaveRepository(connection).opprettOppgave(oppgaveDto)
val oppgave = BehandlingshistorikkTilOppgaveConverter.lagOppgave(request, ident())
if (oppgave != null) {
val oppgaveId = dataSource.transaction { connection ->
OppgaveRepository(connection).opprettOppgave(oppgave)
}
respond(oppgaveId)
} else {
respondWithStatus(HttpStatusCode.NoContent)
}
respond(oppgaveId)
}



Loading

0 comments on commit dc20faa

Please sign in to comment.