Skip to content

Commit

Permalink
IS-1879: Add api for dialogmote statusendringer (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikdahlen authored Nov 5, 2024
1 parent 6b5d02c commit 8931632
Show file tree
Hide file tree
Showing 16 changed files with 381 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/main/kotlin/no/nav/syfo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import no.nav.syfo.dialogmelding.kafka.kafkaDialogmeldingConsumerConfig
import no.nav.syfo.dialogmote.DialogmotedeltakerService
import no.nav.syfo.dialogmote.DialogmoterelasjonService
import no.nav.syfo.dialogmote.DialogmotestatusService
import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository
import no.nav.syfo.identhendelse.IdenthendelseService
import no.nav.syfo.identhendelse.kafka.IdenthendelseConsumerService
import no.nav.syfo.identhendelse.kafka.kafkaIdenthendelseConsumerConfig
Expand Down Expand Up @@ -105,10 +106,10 @@ fun main() {
isoppfolgingstilfelleClientId = environment.isoppfolgingstilfelleClientId,
cache = cache,
)
val dialogmotestatusService = DialogmotestatusService(oppfolgingstilfelleClient = oppfolgingstilfelleClient)

lateinit var behandlerVarselService: BehandlerVarselService
lateinit var dialogmoterelasjonService: DialogmoterelasjonService
lateinit var dialogmotestatusService: DialogmotestatusService

val applicationEngineEnvironment = applicationEngineEnvironment {
log = logger
Expand All @@ -135,6 +136,13 @@ fun main() {
database = applicationDatabase,
dialogmotedeltakerService = dialogmotedeltakerService
)
val moteStatusEndretRepository = MoteStatusEndretRepository(
database = applicationDatabase,
)
dialogmotestatusService = DialogmotestatusService(
oppfolgingstilfelleClient = oppfolgingstilfelleClient,
moteStatusEndretRepository = moteStatusEndretRepository,
)

apiModule(
applicationState = applicationState,
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/no/nav/syfo/application/api/ApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import no.nav.syfo.dialogmote.*
import no.nav.syfo.dialogmote.api.v2.registerDialogmoteActionsApiV2
import no.nav.syfo.dialogmote.api.v2.registerDialogmoteApiV2
import no.nav.syfo.dialogmote.api.v2.registerDialogmoteEnhetApiV2
import no.nav.syfo.dialogmote.database.MoteRepository
import no.nav.syfo.dialogmote.database.repository.MoteRepository
import no.nav.syfo.dialogmote.tilgang.DialogmoteTilgangService

fun Application.apiModule(
Expand Down Expand Up @@ -177,6 +177,7 @@ fun Application.apiModule(
registerDialogmoteApiV2(
dialogmoteService = dialogmoteService,
dialogmoteTilgangService = dialogmoteTilgangService,
dialogmotestatusService = dialogmotestatusService,
)
registerDialogmoteActionsApiV2(
dialogmoteService = dialogmoteService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import no.nav.syfo.client.person.kontaktinfo.KontaktinformasjonClient
import no.nav.syfo.dialogmote.api.domain.*
import no.nav.syfo.dialogmote.database.*
import no.nav.syfo.dialogmote.database.domain.toReferat
import no.nav.syfo.dialogmote.database.repository.MoteRepository
import no.nav.syfo.dialogmote.domain.*
import no.nav.syfo.domain.EnhetNr
import no.nav.syfo.domain.PersonIdent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package no.nav.syfo.dialogmote

import no.nav.syfo.client.oppfolgingstilfelle.OppfolgingstilfelleClient
import no.nav.syfo.dialogmote.api.domain.DialogmoteStatusEndringDTO
import no.nav.syfo.dialogmote.database.createMoteStatusEndring
import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository
import no.nav.syfo.dialogmote.database.updateMoteStatus
import no.nav.syfo.dialogmote.domain.*
import no.nav.syfo.domain.PersonIdent
import java.sql.Connection

class DialogmotestatusService(
private val oppfolgingstilfelleClient: OppfolgingstilfelleClient,
private val moteStatusEndretRepository: MoteStatusEndretRepository,
) {

suspend fun updateMoteStatus(
Expand Down Expand Up @@ -71,6 +74,9 @@ class DialogmotestatusService(
token = token,
)

fun getMoteStatusEndringer(personident: PersonIdent): List<DialogmoteStatusEndringDTO> =
moteStatusEndretRepository.getMoteStatusEndringer(personident)

private suspend fun createMoteStatusEndring(
connection: Connection,
dialogmoteId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package no.nav.syfo.dialogmote.api.domain

import no.nav.syfo.dialogmote.domain.DialogmoteStatus
import java.time.LocalDateTime

data class DialogmoteStatusEndringDTO(
val uuid: String,
val createdAt: LocalDateTime,
val dialogmoteId: Int,
val dialogmoteOpprettetAv: String,
val status: DialogmoteStatus,
val statusEndringOpprettetAv: String,
)
29 changes: 27 additions & 2 deletions src/main/kotlin/no/nav/syfo/dialogmote/api/v2/DialogmoteApiV2.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package no.nav.syfo.dialogmote.api.v2

import io.ktor.server.application.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import no.nav.syfo.application.api.authentication.getNAVIdentFromToken
import no.nav.syfo.dialogmote.DialogmoteService
import no.nav.syfo.dialogmote.DialogmotestatusService
import no.nav.syfo.dialogmote.api.domain.NewDialogmoteDTO
import no.nav.syfo.dialogmote.domain.toDialogmoteDTO
import no.nav.syfo.dialogmote.tilgang.DialogmoteTilgangService
import no.nav.syfo.domain.PersonIdent
import no.nav.syfo.util.*
import no.nav.syfo.util.getBearerHeader
import no.nav.syfo.util.getCallId
import no.nav.syfo.util.getPersonIdentHeader
import no.nav.syfo.util.validateVeilederAccess

const val dialogmoteApiV2Basepath = "/api/v2/dialogmote"

Expand All @@ -22,6 +26,7 @@ const val dialogmoteApiVeilederIdentUrlPath = "/veilederident"
fun Route.registerDialogmoteApiV2(
dialogmoteService: DialogmoteService,
dialogmoteTilgangService: DialogmoteTilgangService,
dialogmotestatusService: DialogmotestatusService,
) {
route(dialogmoteApiV2Basepath) {
get(dialogmoteApiPersonIdentUrlPath) {
Expand Down Expand Up @@ -85,5 +90,25 @@ fun Route.registerDialogmoteApiV2(
call.respond(HttpStatusCode.OK)
}
}

get("/personident/motestatusendringer") {
val personident = getPersonIdentHeader()?.let { personident ->
PersonIdent(personident)
} ?: throw IllegalArgumentException("No Personident supplied")

validateVeilederAccess(
dialogmoteTilgangService = dialogmoteTilgangService,
personIdentToAccess = personident,
action = "GET dialogmote statusendringer for Personident"
) {
val dialogmoteStatusEndringer = dialogmotestatusService.getMoteStatusEndringer(personident)

if (dialogmoteStatusEndringer.isEmpty()) {
call.respond(HttpStatusCode.NoContent, dialogmoteStatusEndringer)
} else {
call.respond(dialogmoteStatusEndringer)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import no.nav.syfo.application.database.toList
import no.nav.syfo.cronjob.statusendring.toInstantOslo
import no.nav.syfo.dialogmote.database.domain.PDialogmote
import no.nav.syfo.dialogmote.database.domain.PMotedeltakerBehandlerVarsel
import no.nav.syfo.dialogmote.database.repository.toPDialogmote
import no.nav.syfo.dialogmote.domain.DialogmoteStatus
import no.nav.syfo.dialogmote.domain.NewDialogmote
import no.nav.syfo.dialogmote.domain.TidStedDTO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.syfo.dialogmote.database
package no.nav.syfo.dialogmote.database.repository

import no.nav.syfo.application.database.DatabaseInterface
import no.nav.syfo.application.database.toList
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package no.nav.syfo.dialogmote.database.repository

import no.nav.syfo.application.database.DatabaseInterface
import no.nav.syfo.application.database.toList
import no.nav.syfo.dialogmote.api.domain.DialogmoteStatusEndringDTO
import no.nav.syfo.dialogmote.database.domain.PMoteStatusEndret
import no.nav.syfo.dialogmote.domain.DialogmoteStatus
import no.nav.syfo.domain.PersonIdent
import java.sql.ResultSet
import java.util.*

class MoteStatusEndretRepository(private val database: DatabaseInterface) {

fun getMoteStatusEndringer(personident: PersonIdent): List<DialogmoteStatusEndringDTO> =
database.connection.use { connection ->
connection.prepareStatement(GET_MOTE_STATUS_ENDRINGER).use { ps ->
ps.setString(1, personident.value)
ps.executeQuery()
.toList {
val pDialogmoteStatusEndret = toPMoteStatusEndret()
DialogmoteStatusEndringDTO(
uuid = pDialogmoteStatusEndret.uuid.toString(),
createdAt = pDialogmoteStatusEndret.createdAt,
dialogmoteId = pDialogmoteStatusEndret.moteId,
dialogmoteOpprettetAv = getString("mote_opprettet_av"),
status = pDialogmoteStatusEndret.status,
statusEndringOpprettetAv = pDialogmoteStatusEndret.opprettetAv,
)
}
}
}

companion object {
private const val GET_MOTE_STATUS_ENDRINGER =
"""
SELECT
mse.*,
m.opprettet_av as mote_opprettet_av
FROM mote_status_endret mse
INNER JOIN mote m on mse.mote_id = m.id
INNER JOIN motedeltaker_arbeidstaker mda on m.id = mda.mote_id
WHERE mda.personident = ?
ORDER BY mse.created_at DESC
"""
}
}

internal fun ResultSet.toPMoteStatusEndret(): PMoteStatusEndret =
PMoteStatusEndret(
id = getInt("id"),
uuid = UUID.fromString(getString("uuid")),
createdAt = getTimestamp("created_at").toLocalDateTime(),
updatedAt = getTimestamp("updated_at").toLocalDateTime(),
moteId = getInt("mote_id"),
motedeltakerBehandler = getBoolean("motedeltaker_behandler"),
status = DialogmoteStatus.valueOf(getString("status")),
opprettetAv = getString("opprettet_av"),
tilfelleStart = getTimestamp("tilfelle_start").toLocalDateTime().toLocalDate(),
publishedAt = getTimestamp("published_at")?.toLocalDateTime(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import no.nav.syfo.dialogmote.api.v2.dialogmoteApiMoteFerdigstillPath
import no.nav.syfo.dialogmote.api.v2.dialogmoteApiPersonIdentUrlPath
import no.nav.syfo.dialogmote.api.v2.dialogmoteApiV2Basepath
import no.nav.syfo.dialogmote.database.getDialogmote
import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository
import no.nav.syfo.dialogmote.domain.DialogmoteStatus
import no.nav.syfo.dialogmote.domain.DialogmoteSvarType
import no.nav.syfo.dialogmote.domain.MotedeltakerVarselType
Expand Down Expand Up @@ -105,6 +106,7 @@ class ArbeidstakerBrevApiSpek : Spek({
)
val dialogmotestatusService = DialogmotestatusService(
oppfolgingstilfelleClient = oppfolgingstilfelleClient,
moteStatusEndretRepository = MoteStatusEndretRepository(database),
)
val dialogmotedeltakerService = DialogmotedeltakerService(
arbeidstakerVarselService = arbeidstakerVarselService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import no.nav.syfo.dialogmote.api.v2.dialogmoteApiMoteFerdigstillPath
import no.nav.syfo.dialogmote.api.v2.dialogmoteApiPersonIdentUrlPath
import no.nav.syfo.dialogmote.api.v2.dialogmoteApiV2Basepath
import no.nav.syfo.dialogmote.database.getDialogmote
import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository
import no.nav.syfo.dialogmote.domain.DialogmoteStatus
import no.nav.syfo.dialogmote.domain.DialogmoteSvarType
import no.nav.syfo.dialogmote.domain.MotedeltakerVarselType
Expand Down Expand Up @@ -109,6 +110,7 @@ object NarmesteLederBrevSpek : Spek({
)
val dialogmotestatusService = DialogmotestatusService(
oppfolgingstilfelleClient = oppfolgingstilfelleClient,
moteStatusEndretRepository = MoteStatusEndretRepository(database),
)
val dialogmotedeltakerService = DialogmotedeltakerService(
arbeidstakerVarselService = arbeidstakerVarselService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import no.nav.syfo.dialogmote.DialogmoterelasjonService
import no.nav.syfo.dialogmote.DialogmotestatusService
import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO
import no.nav.syfo.dialogmote.api.v2.*
import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository
import no.nav.syfo.dialogmote.domain.DialogmoteStatus
import no.nav.syfo.testhelper.*
import no.nav.syfo.testhelper.generator.generateAvlysDialogmoteDTO
Expand Down Expand Up @@ -92,6 +93,7 @@ class DialogmoteOutdatedCronjobSpek : Spek({
)
val dialogmotestatusService = DialogmotestatusService(
oppfolgingstilfelleClient = oppfolgingstilfelleClient,
moteStatusEndretRepository = MoteStatusEndretRepository(database),
)
val arbeidstakerVarselService = ArbeidstakerVarselService(
esyfovarselProducer = esyfovarselProducerMock,
Expand Down
Loading

0 comments on commit 8931632

Please sign in to comment.