From 0719c2edb98b0ce0793a899c135ac3eb640974a7 Mon Sep 17 00:00:00 2001 From: Anders Rognstad Date: Wed, 22 May 2024 15:44:32 +0200 Subject: [PATCH] IS-1896: Create/update dialogmotesvar-oppgave if kommer with tekst --- .../dialogmotesvar/DialogmotesvarService.kt | 30 +++++++++----- .../dialogmotesvar/domain/Dialogmotesvar.kt | 4 ++ .../dialogmotesvar/domain/KDialogmotesvar.kt | 2 + .../kafka/KafkaDialogmotesvar.kt | 2 +- src/main/kotlin/no/nav/syfo/metric/Metrics.kt | 6 --- .../DialogmotesvarServiceSpek.kt | 40 ++++++++++++++++++- .../generators/DialogmotesvarGenerator.kt | 6 ++- 7 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarService.kt b/src/main/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarService.kt index 7f13c7b3..8e60d4ce 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarService.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarService.kt @@ -1,10 +1,14 @@ package no.nav.syfo.dialogmotesvar +import io.micrometer.core.instrument.Counter import no.nav.syfo.dialogmotestatusendring.domain.didFinishDialogmote import no.nav.syfo.dialogmotestatusendring.getDialogmoteStatusendring import no.nav.syfo.dialogmotestatusendring.kafka.log +import no.nav.syfo.dialogmotesvar.Metrics.COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED +import no.nav.syfo.dialogmotesvar.Metrics.COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER import no.nav.syfo.dialogmotesvar.domain.* -import no.nav.syfo.metric.COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED +import no.nav.syfo.metric.METRICS_NS +import no.nav.syfo.metric.METRICS_REGISTRY import no.nav.syfo.personoppgave.* import no.nav.syfo.personoppgave.domain.* import no.nav.syfo.util.toLocalDateTimeOslo @@ -17,7 +21,7 @@ fun processDialogmotesvar( cutoffDate: LocalDate, ) { log.info("Received dialogmotesvar! ${dialogmotesvar.moteuuid}") - if (isIrrelevantDialogmotesvar(connection, dialogmotesvar, cutoffDate)) return + if (dialogmotesvar.isIrrelevant(cutoffDate) || isDialogmoteClosed(connection, dialogmotesvar)) return val personOppgave = connection .getPersonOppgaverByReferanseUuid(dialogmotesvar.moteuuid) @@ -36,6 +40,9 @@ fun processDialogmotesvar( ) connection.updatePersonoppgaveSetBehandlet(updatedOppgave) COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED.increment() + if (dialogmotesvar.svarType == DialogmoteSvartype.KOMMER) { + COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER.increment() + } } } } @@ -54,12 +61,15 @@ fun isDialogmoteClosed(connection: Connection, dialogmotesvar: Dialogmotesvar): return latestStatusEndring != null && latestStatusEndring.didFinishDialogmote() } -fun isIrrelevantDialogmotesvar( - connection: Connection, - dialogmotesvar: Dialogmotesvar, - cutoffDate: LocalDate -): Boolean { - return dialogmotesvar.svarType == DialogmoteSvartype.KOMMER || - !(dialogmotesvar happenedAfter cutoffDate) || - isDialogmoteClosed(connection, dialogmotesvar) +private object Metrics { + const val DIALOGMOTESVAR_OPPGAVE_UPDATED = "${METRICS_NS}_dialogmotesvar_oppgave_updated_count" + val COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED: Counter = + Counter.builder(DIALOGMOTESVAR_OPPGAVE_UPDATED) + .description("Counts the number of PERSON_OPPGAVE updated from a KDialogmotesvar") + .register(METRICS_REGISTRY) + const val DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER = "${METRICS_NS}_dialogmotesvar_oppgave_updated_kommer_count" + val COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER: Counter = + Counter.builder(DIALOGMOTESVAR_OPPGAVE_UPDATED_KOMMER) + .description("Counts the number of PERSON_OPPGAVE updated from a KDialogmotesvar KOMMER") + .register(METRICS_REGISTRY) } diff --git a/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/Dialogmotesvar.kt b/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/Dialogmotesvar.kt index b32ec177..4006030d 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/Dialogmotesvar.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/Dialogmotesvar.kt @@ -15,8 +15,12 @@ data class Dialogmotesvar( val senderType: SenderType, val brevSentAt: OffsetDateTime, val svarReceivedAt: OffsetDateTime, + val svarTekst: String?, ) +fun Dialogmotesvar.isIrrelevant(cutoffDate: LocalDate): Boolean = + !(this happenedAfter cutoffDate) || (svarType == DialogmoteSvartype.KOMMER && svarTekst.isNullOrBlank()) + infix fun Dialogmotesvar.happenedAfter( date: LocalDate, ) = LocalDate.from(svarReceivedAt).isAfter(date) diff --git a/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/KDialogmotesvar.kt b/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/KDialogmotesvar.kt index a63c79b4..f63df21c 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/KDialogmotesvar.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmotesvar/domain/KDialogmotesvar.kt @@ -10,6 +10,7 @@ data class KDialogmotesvar( val senderType: SenderType, val brevSentAt: OffsetDateTime, val svarReceivedAt: OffsetDateTime, + val svarTekst: String?, ) fun KDialogmotesvar.toDialogmotesvar(moteuuid: UUID): Dialogmotesvar = Dialogmotesvar( @@ -20,6 +21,7 @@ fun KDialogmotesvar.toDialogmotesvar(moteuuid: UUID): Dialogmotesvar = Dialogmot senderType = this.senderType, brevSentAt = this.brevSentAt, svarReceivedAt = this.svarReceivedAt, + svarTekst = this.svarTekst, ) enum class SenderType { diff --git a/src/main/kotlin/no/nav/syfo/dialogmotesvar/kafka/KafkaDialogmotesvar.kt b/src/main/kotlin/no/nav/syfo/dialogmotesvar/kafka/KafkaDialogmotesvar.kt index e0c8ad0e..220b02e1 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmotesvar/kafka/KafkaDialogmotesvar.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmotesvar/kafka/KafkaDialogmotesvar.kt @@ -61,7 +61,7 @@ class KafkaDialogmotesvarConsumer( validRecords.forEach { record -> val kDialogmotesvar = record.value() val moteUuid = UUID.fromString(record.key()) - log.info("Received dialogmotesvar with key/moteuuid : $moteUuid of svar type ${kDialogmotesvar.svarType}") + log.info("Received dialogmotesvar with key/moteuuid : $moteUuid of svar type ${kDialogmotesvar.svarType} and tekst ${kDialogmotesvar.svarTekst}") val dialogmotesvar = kDialogmotesvar.toDialogmotesvar(moteUuid) storeDialogmotesvar( diff --git a/src/main/kotlin/no/nav/syfo/metric/Metrics.kt b/src/main/kotlin/no/nav/syfo/metric/Metrics.kt index 7372c1b0..8b30f366 100644 --- a/src/main/kotlin/no/nav/syfo/metric/Metrics.kt +++ b/src/main/kotlin/no/nav/syfo/metric/Metrics.kt @@ -46,12 +46,6 @@ val COUNT_CALL_TILGANGSKONTROLL_PERSON_FORBIDDEN: Counter = Counter.builder(CALL .description("Counts the number of forbidden calls to istilgangskontroll - person") .register(METRICS_REGISTRY) -const val DIALOGMOTESVAR_OPPGAVE_UPDATED = "${METRICS_NS}_dialogmotesvar_oppgave_updated_count" -val COUNT_DIALOGMOTESVAR_OPPGAVE_UPDATED: Counter = - Counter.builder(DIALOGMOTESVAR_OPPGAVE_UPDATED) - .description("Counts the number of PERSON_OPPGAVE updated from a KDialogmotesvar") - .register(METRICS_REGISTRY) - const val PERSONOPPGAVEHENDELSE_DIALOGMELDING_SVAR_MOTTATT = "${METRICS_NS}_personoppgavehendelse_dialogmelding_svar_mottatt_count" val COUNT_PERSONOPPGAVEHENDELSE_DIALOGMELDING_SVAR_MOTTATT: Counter = diff --git a/src/test/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarServiceSpek.kt b/src/test/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarServiceSpek.kt index 9b01c43b..03ef1fcd 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmotesvar/DialogmotesvarServiceSpek.kt @@ -4,6 +4,7 @@ import io.mockk.* import no.nav.syfo.dialogmotestatusendring.domain.DialogmoteStatusendringType import no.nav.syfo.dialogmotestatusendring.getDialogmoteStatusendring import no.nav.syfo.dialogmotesvar.domain.DialogmoteSvartype +import no.nav.syfo.dialogmotesvar.domain.SenderType import no.nav.syfo.personoppgave.* import no.nav.syfo.testutil.generators.generateDialogmotesvar import no.nav.syfo.testutil.generators.generatePDialogmotestatusendring @@ -83,7 +84,44 @@ class DialogmotesvarServiceSpek : Spek({ verify(exactly = 0) { connection.updatePersonoppgaveSetBehandlet(any()) } } - it("does not create an oppgave if arbeidstaker confirms attendance to dialogmote") { + it("creates an oppgave if behandler confirms attendance to dialogmote and svarTekst is not empty") { + val dialogmotesvar = generateDialogmotesvar( + svartype = DialogmoteSvartype.KOMMER, + svarTekst = "Passer bra, men kan vi endre tidspunkt?", + senderType = SenderType.BEHANDLER, + ) + + every { connection.createPersonOppgave(dialogmotesvar) } returns UUID.randomUUID() + + processDialogmotesvar( + connection = connection, + dialogmotesvar = dialogmotesvar, + cutoffDate = CUTOFF_DATE, + ) + + verify(exactly = 1) { connection.getPersonOppgaverByReferanseUuid(dialogmotesvar.moteuuid) } + verify(exactly = 1) { connection.createPersonOppgave(dialogmotesvar) } + verify(exactly = 0) { connection.updatePersonoppgaveSetBehandlet(any()) } + } + + it("does not create an oppgave if behandler confirms attendance to dialogmote and svarTekst is empty") { + val dialogmotesvar = generateDialogmotesvar( + svartype = DialogmoteSvartype.KOMMER, + senderType = SenderType.BEHANDLER, + ) + + processDialogmotesvar( + connection = connection, + dialogmotesvar = dialogmotesvar, + cutoffDate = CUTOFF_DATE, + ) + + verify(exactly = 0) { connection.getPersonOppgaverByReferanseUuid(any()) } + verify(exactly = 0) { connection.createBehandletPersonoppgave(any(), any()) } + verify(exactly = 0) { connection.updatePersonoppgaveSetBehandlet(any()) } + } + + it("does not create an oppgave if arbeidstaker confirms attendance to dialogmote and svarTekst is empty") { val dialogmotesvar = generateDialogmotesvar( svartype = DialogmoteSvartype.KOMMER, ) diff --git a/src/test/kotlin/no/nav/syfo/testutil/generators/DialogmotesvarGenerator.kt b/src/test/kotlin/no/nav/syfo/testutil/generators/DialogmotesvarGenerator.kt index 3144ff0f..5e10f566 100644 --- a/src/test/kotlin/no/nav/syfo/testutil/generators/DialogmotesvarGenerator.kt +++ b/src/test/kotlin/no/nav/syfo/testutil/generators/DialogmotesvarGenerator.kt @@ -9,14 +9,17 @@ fun generateDialogmotesvar( moteuuid: UUID = UUID.randomUUID(), svartype: DialogmoteSvartype = DialogmoteSvartype.KOMMER, svarReceivedAt: OffsetDateTime = OffsetDateTime.now(), + senderType: SenderType = SenderType.ARBEIDSTAKER, + svarTekst: String? = null, ) = Dialogmotesvar( uuid = UUID.randomUUID(), moteuuid = moteuuid, arbeidstakerIdent = UserConstants.ARBEIDSTAKER_FNR, svarType = svartype, - senderType = SenderType.ARBEIDSTAKER, + senderType = senderType, brevSentAt = OffsetDateTime.now(), svarReceivedAt = svarReceivedAt, + svarTekst = svarTekst, ) fun generateKDialogmotesvar() = KDialogmotesvar( @@ -25,4 +28,5 @@ fun generateKDialogmotesvar() = KDialogmotesvar( senderType = SenderType.ARBEIDSTAKER, brevSentAt = OffsetDateTime.now(), svarReceivedAt = OffsetDateTime.now(), + svarTekst = null, )