Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS-2621: Add stansdato to stans vurdering #35

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class VurderingResponseDTO private constructor(
val vurderingType: VurderingType,
val veilederident: String,
val begrunnelse: String,
val stansdato: LocalDate?,
val document: List<DocumentComponent>,
val varsel: VarselDTO?,
) {
Expand All @@ -24,6 +25,7 @@ data class VurderingResponseDTO private constructor(
vurderingType = vurdering.vurderingType,
veilederident = vurdering.veilederident.value,
begrunnelse = vurdering.begrunnelse,
stansdato = if (vurdering is Vurdering.Stans) vurdering.stansdato else null,
document = vurdering.document,
varsel = if (vurdering is Vurdering.Forhandsvarsel) VarselDTO.fromVarsel(vurdering.varsel) else null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class VurderingService(
personident = Personident(newVurdering.personident),
veilederident = veilederident,
begrunnelse = newVurdering.begrunnelse,
stansdato = newVurdering.stansdato,
document = newVurdering.document,
)
is NewVurderingRequestDTO.IkkeAktuell ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sealed class NewVurderingRequestDTO {
override val personident: String,
override val begrunnelse: String,
override val document: List<DocumentComponent>,
val stansdato: LocalDate,
) : NewVurderingRequestDTO()

@JsonTypeName("IKKE_AKTUELL")
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/no/nav/syfo/domain/Vurdering.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sealed class Vurdering(val vurderingType: VurderingType) : IVurdering {
override val begrunnelse: String,
override val document: List<DocumentComponent>,
override val journalpostId: JournalpostId?,
val stansdato: LocalDate,
) : Vurdering(VurderingType.STANS)

data class IkkeAktuell(
Expand Down Expand Up @@ -132,13 +133,15 @@ sealed class Vurdering(val vurderingType: VurderingType) : IVurdering {
personident: Personident,
veilederident: Veilederident,
begrunnelse: String,
stansdato: LocalDate,
document: List<DocumentComponent>,
) = Stans(
uuid = UUID.randomUUID(),
personident = personident,
veilederident = veilederident,
createdAt = OffsetDateTime.now(),
begrunnelse = begrunnelse,
stansdato = stansdato,
document = document,
journalpostId = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import no.nav.syfo.domain.Personident
import no.nav.syfo.domain.Veilederident
import no.nav.syfo.domain.Vurdering
import no.nav.syfo.domain.VurderingType
import java.time.LocalDate
import java.time.OffsetDateTime
import java.util.UUID

Expand All @@ -18,6 +19,7 @@ data class PVurdering(
val veilederident: Veilederident,
val type: VurderingType,
val begrunnelse: String,
val stansdato: LocalDate?,
val document: List<DocumentComponent>,
val journalpostId: JournalpostId?,
val publishedAt: OffsetDateTime?,
Expand Down Expand Up @@ -50,6 +52,7 @@ data class PVurdering(
veilederident = veilederident,
createdAt = createdAt,
begrunnelse = begrunnelse,
stansdato = stansdato!!,
document = document,
journalpostId = journalpostId,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class VurderingRepository(private val database: DatabaseInterface) : IVurderingR
it.setObject(8, mapper.writeValueAsString(vurdering.document))
it.setNull(9, Types.VARCHAR)
it.setNull(10, Types.TIMESTAMP_WITH_TIMEZONE)
when (vurdering) {
is Vurdering.Stans -> it.setDate(11, Date.valueOf(vurdering.stansdato))
else -> it.setNull(11, Types.DATE)
}
it.executeQuery().toList { toPVurdering() }.firstOrNull()
}
if (pVurdering == null) {
Expand Down Expand Up @@ -196,8 +200,9 @@ class VurderingRepository(private val database: DatabaseInterface) : IVurderingR
begrunnelse,
document,
journalpost_id,
published_at
) values (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?::jsonb, ?, ?)
published_at,
stansdato
) values (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?::jsonb, ?, ?, ?)
RETURNING *
"""

Expand Down Expand Up @@ -286,6 +291,7 @@ internal fun ResultSet.toPVurdering(): PVurdering =
veilederident = Veilederident(getString("veilederident")),
type = VurderingType.valueOf(getString("type")),
begrunnelse = getString("begrunnelse"),
stansdato = getDate("stansdato")?.toLocalDate(),
document = configuredJacksonMapper().readValue(
getString("document"),
object : TypeReference<List<DocumentComponent>>() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ object ManglendeMedvirkningEndpointsSpek : Spek({
val stansVurdering = NewVurderingRequestDTO.Stans(
personident = ARBEIDSTAKER_PERSONIDENT.value,
begrunnelse = "Fin begrunnelse",
stansdato = LocalDate.now().plusDays(5),
document = generateDocumentComponent(
fritekst = begrunnelse,
header = "Stans"
),
)
val json = objectMapper.writeValueAsString(stansVurdering)
with(
handleRequest(HttpMethod.Post, "$urlVurderinger/vurderinger") {
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
Expand All @@ -119,6 +119,7 @@ object ManglendeMedvirkningEndpointsSpek : Spek({
responseDTO.personident shouldBeEqualTo stansVurdering.personident
responseDTO.vurderingType shouldBeEqualTo VurderingType.STANS
responseDTO.begrunnelse shouldBeEqualTo stansVurdering.begrunnelse
responseDTO.stansdato shouldBeEqualTo stansVurdering.stansdato
responseDTO.veilederident shouldBeEqualTo VEILEDER_IDENT.value
responseDTO.document shouldBeEqualTo stansVurdering.document
responseDTO.varsel?.svarfrist shouldBeEqualTo null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fun generateVurdering(
personident = personident,
veilederident = UserConstants.VEILEDER_IDENT,
begrunnelse = begrunnelse,
stansdato = LocalDate.now().plusDays(5),
document = document,
journalpostId = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ class VurderingRepositorySpek : Spek({
savedVurdering.journalpostId shouldBeEqualTo vurdering.journalpostId
}

it("saves a vurdering of type STANS") {
val vurdering = Vurdering.Stans(
uuid = UUID.randomUUID(),
personident = ARBEIDSTAKER_PERSONIDENT,
veilederident = VEILEDER_IDENT,
createdAt = nowUTC(),
begrunnelse = "Begrunnelse",
stansdato = nowUTC().toLocalDate(),
document = emptyList(),
journalpostId = null,
)
val savedVurdering = vurderingRepository.saveManglendeMedvirkningVurdering(vurdering, pdf)
when (savedVurdering) {
is Vurdering.Stans -> {
savedVurdering.personident shouldBeEqualTo vurdering.personident
savedVurdering.veilederident shouldBeEqualTo vurdering.veilederident
savedVurdering.begrunnelse shouldBeEqualTo vurdering.begrunnelse
savedVurdering.stansdato shouldBeEqualTo vurdering.stansdato
savedVurdering.document shouldBeEqualTo vurdering.document
savedVurdering.journalpostId shouldBeEqualTo vurdering.journalpostId
}
else ->
throw IllegalStateException("Expected Vurdering.Stans, got $savedVurdering")
}
}

it("saves a vurdering with a varsel") {
val now = nowUTC()
val vurdering = Vurdering.Forhandsvarsel(
Expand Down