-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-2752: Add endpoint for historikk (#182)
* IS-2752: Add endpoint for historikk * Rename fields
- Loading branch information
1 parent
1a2fd2d
commit a8ef807
Showing
9 changed files
with
472 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/no/nav/syfo/dialogmotekandidat/api/HistorikkDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package no.nav.syfo.dialogmotekandidat.api | ||
|
||
import no.nav.syfo.dialogmotekandidat.domain.DialogmotekandidatEndring | ||
import no.nav.syfo.dialogmotekandidat.domain.DialogmotekandidatEndringArsak | ||
import no.nav.syfo.ikkeaktuell.domain.IkkeAktuell | ||
import no.nav.syfo.unntak.domain.Unntak | ||
import java.time.LocalDateTime | ||
|
||
data class HistorikkDTO( | ||
val tidspunkt: LocalDateTime, | ||
val type: HistorikkType, | ||
val arsak: String, | ||
val vurdertAv: String?, | ||
) { | ||
companion object { | ||
fun createHistorikkDTOs( | ||
dialogmotekandidatEndringer: List<DialogmotekandidatEndring>, | ||
unntak: List<Unntak>, | ||
ikkeAktuell: List<IkkeAktuell>, | ||
): List<HistorikkDTO> { | ||
val historikk = dialogmotekandidatEndringer.toKandidatHistorikk() + unntak.toUnntakHistorikk() + ikkeAktuell.toIkkeAktuellHistorikk() | ||
return historikk.sortedByDescending { it.tidspunkt } | ||
} | ||
} | ||
} | ||
|
||
fun List<DialogmotekandidatEndring>.toKandidatHistorikk(): List<HistorikkDTO> = this.mapNotNull { | ||
val tidspunkt = it.createdAt.toLocalDateTime() | ||
when (it.arsak) { | ||
DialogmotekandidatEndringArsak.STOPPUNKT -> HistorikkDTO( | ||
tidspunkt = tidspunkt, | ||
type = HistorikkType.KANDIDAT, | ||
arsak = it.arsak.name, | ||
vurdertAv = null, | ||
) | ||
|
||
DialogmotekandidatEndringArsak.LUKKET -> HistorikkDTO( | ||
tidspunkt = tidspunkt, | ||
type = HistorikkType.LUKKET, | ||
arsak = it.arsak.name, | ||
vurdertAv = null, | ||
) | ||
|
||
// Disse dekkes av dialogmote-historikk og unntak/ikke-aktuell-historikk | ||
DialogmotekandidatEndringArsak.DIALOGMOTE_FERDIGSTILT, DialogmotekandidatEndringArsak.DIALOGMOTE_LUKKET, DialogmotekandidatEndringArsak.UNNTAK, DialogmotekandidatEndringArsak.IKKE_AKTUELL -> null | ||
} | ||
} | ||
|
||
fun List<Unntak>.toUnntakHistorikk(): List<HistorikkDTO> = this.map { | ||
HistorikkDTO( | ||
tidspunkt = it.createdAt.toLocalDateTime(), | ||
type = HistorikkType.UNNTAK, | ||
arsak = it.arsak.name, | ||
vurdertAv = it.createdBy, | ||
) | ||
} | ||
|
||
fun List<IkkeAktuell>.toIkkeAktuellHistorikk(): List<HistorikkDTO> = this.map { | ||
HistorikkDTO( | ||
tidspunkt = it.createdAt.toLocalDateTime(), | ||
type = HistorikkType.IKKE_AKTUELL, | ||
arsak = it.arsak.name, | ||
vurdertAv = it.createdBy, | ||
) | ||
} | ||
|
||
enum class HistorikkType { | ||
KANDIDAT, | ||
UNNTAK, | ||
IKKE_AKTUELL, | ||
LUKKET, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/no/nav/syfo/ikkeaktuell/database/IkkeAktuellRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package no.nav.syfo.ikkeaktuell.database | ||
|
||
import no.nav.syfo.application.database.DatabaseInterface | ||
import no.nav.syfo.application.database.toList | ||
import no.nav.syfo.domain.PersonIdentNumber | ||
import java.sql.ResultSet | ||
import java.time.OffsetDateTime | ||
import java.util.* | ||
|
||
class IkkeAktuellRepository(private val database: DatabaseInterface) { | ||
|
||
fun getIkkeAktuellListForPerson(personIdent: PersonIdentNumber): List<PIkkeAktuell> = | ||
database.connection.use { connection -> | ||
connection.prepareStatement(GET_IKKE_AKTUELL_FOR_PERSON).use { | ||
it.setString(1, personIdent.value) | ||
it.executeQuery().toList { toPIkkeAktuell() } | ||
} | ||
} | ||
|
||
companion object { | ||
private const val GET_IKKE_AKTUELL_FOR_PERSON = | ||
""" | ||
SELECT * | ||
FROM IKKE_AKTUELL | ||
WHERE personident = ? | ||
""" | ||
} | ||
} | ||
|
||
fun ResultSet.toPIkkeAktuell() = PIkkeAktuell( | ||
id = getInt("id"), | ||
uuid = UUID.fromString(getString("uuid")), | ||
createdAt = getObject("created_at", OffsetDateTime::class.java), | ||
createdBy = getString("created_by"), | ||
personIdent = getString("personident"), | ||
arsak = getString("arsak"), | ||
beskrivelse = getString("beskrivelse"), | ||
) |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/no/nav/syfo/ikkeaktuell/database/PIkkeAktuell.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package no.nav.syfo.ikkeaktuell.database | ||
|
||
import no.nav.syfo.domain.PersonIdentNumber | ||
import no.nav.syfo.ikkeaktuell.domain.IkkeAktuell | ||
import no.nav.syfo.ikkeaktuell.domain.IkkeAktuellArsak | ||
import java.time.OffsetDateTime | ||
import java.util.* | ||
|
||
data class PIkkeAktuell( | ||
val id: Int, | ||
val uuid: UUID, | ||
val createdAt: OffsetDateTime, | ||
val createdBy: String, | ||
val personIdent: String, | ||
val arsak: String, | ||
val beskrivelse: String?, | ||
) | ||
|
||
fun List<PIkkeAktuell>.toIkkeAktuellList() = this.map { | ||
IkkeAktuell( | ||
uuid = it.uuid, | ||
createdAt = it.createdAt, | ||
createdBy = it.createdBy, | ||
personIdent = PersonIdentNumber(it.personIdent), | ||
arsak = IkkeAktuellArsak.valueOf(it.arsak), | ||
beskrivelse = it.beskrivelse, | ||
) | ||
} |
Oops, something went wrong.